Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be %

Original thread:
Date: Aug 30, 2006 4:54 PM
Subject: [Ffmpeg-devel] [PATCH] Clarified API for numbered sequences

Originally committed as revision 6166 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Michel Bardiaux
2006-09-04 09:57:47 +00:00
committed by Guillaume Poirier
parent 22e4695905
commit 5c07cf535f
5 changed files with 42 additions and 32 deletions

View File

@@ -3392,7 +3392,7 @@ static void opt_output_file(const char *filename)
/* check filename in case of an image number is expected */ /* check filename in case of an image number is expected */
if (oc->oformat->flags & AVFMT_NEEDNUMBER) { if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
if (filename_number_test(oc->filename) < 0) { if (!av_filename_number_test(oc->filename)) {
print_error(oc->filename, AVERROR_NUMEXPECTED); print_error(oc->filename, AVERROR_NUMEXPECTED);
exit(1); exit(1);
} }

View File

@@ -515,9 +515,9 @@ void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info); int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
int get_frame_filename(char *buf, int buf_size, int av_get_frame_filename(char *buf, int buf_size,
const char *path, int number); const char *path, int number);
int filename_number_test(const char *filename); int av_filename_number_test(const char *filename);
/* grab specific */ /* grab specific */
int video_grab_init(void); int video_grab_init(void);

View File

@@ -44,7 +44,7 @@ static int find_image_range(int *pfirst_index, int *plast_index,
/* find the first image */ /* find the first image */
for(first_index = 0; first_index < 5; first_index++) { for(first_index = 0; first_index < 5; first_index++) {
if (get_frame_filename(buf, sizeof(buf), path, first_index) < 0) if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0)
goto fail; goto fail;
if (url_exist(buf)) if (url_exist(buf))
break; break;
@@ -61,7 +61,7 @@ static int find_image_range(int *pfirst_index, int *plast_index,
range1 = 1; range1 = 1;
else else
range1 = 2 * range; range1 = 2 * range;
if (get_frame_filename(buf, sizeof(buf), path, if (av_get_frame_filename(buf, sizeof(buf), path,
last_index + range1) < 0) last_index + range1) < 0)
goto fail; goto fail;
if (!url_exist(buf)) if (!url_exist(buf))
@@ -86,7 +86,7 @@ static int find_image_range(int *pfirst_index, int *plast_index,
static int image_probe(AVProbeData *p) static int image_probe(AVProbeData *p)
{ {
if (filename_number_test(p->filename) >= 0 && guess_image_format(p->filename)) if (av_filename_number_test(p->filename) && guess_image_format(p->filename))
return AVPROBE_SCORE_MAX-1; return AVPROBE_SCORE_MAX-1;
else else
return 0; return 0;
@@ -144,7 +144,7 @@ static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap)
/* compute duration */ /* compute duration */
st->start_time = 0; st->start_time = 0;
st->duration = last_index - first_index + 1; st->duration = last_index - first_index + 1;
if (get_frame_filename(buf, sizeof(buf), s->path, s->img_number) < 0) if (av_get_frame_filename(buf, sizeof(buf), s->path, s->img_number) < 0)
goto fail; goto fail;
if (url_fopen(f, buf, URL_RDONLY) < 0) if (url_fopen(f, buf, URL_RDONLY) < 0)
goto fail; goto fail;
@@ -200,7 +200,7 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
if (s1->loop_input && s->img_number > s->img_last) { if (s1->loop_input && s->img_number > s->img_last) {
s->img_number = s->img_first; s->img_number = s->img_first;
} }
if (get_frame_filename(filename, sizeof(filename), if (av_get_frame_filename(filename, sizeof(filename),
s->path, s->img_number) < 0) s->path, s->img_number) < 0)
return AVERROR_IO; return AVERROR_IO;
f = &f1; f = &f1;
@@ -307,7 +307,7 @@ static int img_write_packet(AVFormatContext *s, AVPacket *pkt)
picture = (AVPicture *)pkt->data; picture = (AVPicture *)pkt->data;
if (!img->is_pipe) { if (!img->is_pipe) {
if (get_frame_filename(filename, sizeof(filename), if (av_get_frame_filename(filename, sizeof(filename),
img->path, img->img_number) < 0) img->path, img->img_number) < 0)
return AVERROR_IO; return AVERROR_IO;
pb = &pb1; pb = &pb1;

View File

@@ -104,7 +104,7 @@ static int find_image_range(int *pfirst_index, int *plast_index,
/* find the first image */ /* find the first image */
for(first_index = 0; first_index < 5; first_index++) { for(first_index = 0; first_index < 5; first_index++) {
if (get_frame_filename(buf, sizeof(buf), path, first_index) < 0){ if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0){
*pfirst_index = *pfirst_index =
*plast_index = 1; *plast_index = 1;
return 0; return 0;
@@ -124,7 +124,7 @@ static int find_image_range(int *pfirst_index, int *plast_index,
range1 = 1; range1 = 1;
else else
range1 = 2 * range; range1 = 2 * range;
if (get_frame_filename(buf, sizeof(buf), path, if (av_get_frame_filename(buf, sizeof(buf), path,
last_index + range1) < 0) last_index + range1) < 0)
goto fail; goto fail;
if (!url_exist(buf)) if (!url_exist(buf))
@@ -149,7 +149,7 @@ static int find_image_range(int *pfirst_index, int *plast_index,
static int image_probe(AVProbeData *p) static int image_probe(AVProbeData *p)
{ {
if (filename_number_test(p->filename) >= 0 && av_str2id(img_tags, p->filename)) if (av_filename_number_test(p->filename) && av_str2id(img_tags, p->filename))
return AVPROBE_SCORE_MAX; return AVPROBE_SCORE_MAX;
else else
return 0; return 0;
@@ -236,7 +236,7 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
if (s1->loop_input && s->img_number > s->img_last) { if (s1->loop_input && s->img_number > s->img_last) {
s->img_number = s->img_first; s->img_number = s->img_first;
} }
if (get_frame_filename(filename, sizeof(filename), if (av_get_frame_filename(filename, sizeof(filename),
s->path, s->img_number)<0 && s->img_number > 1) s->path, s->img_number)<0 && s->img_number > 1)
return AVERROR_IO; return AVERROR_IO;
for(i=0; i<3; i++){ for(i=0; i<3; i++){
@@ -317,7 +317,7 @@ static int img_write_packet(AVFormatContext *s, AVPacket *pkt)
int i; int i;
if (!img->is_pipe) { if (!img->is_pipe) {
if (get_frame_filename(filename, sizeof(filename), if (av_get_frame_filename(filename, sizeof(filename),
img->path, img->img_number) < 0 && img->img_number>1) img->path, img->img_number) < 0 && img->img_number>1)
return AVERROR_IO; return AVERROR_IO;
for(i=0; i<3; i++){ for(i=0; i<3; i++){

View File

@@ -93,13 +93,13 @@ AVOutputFormat *guess_format(const char *short_name, const char *filename,
/* specific test for image sequences */ /* specific test for image sequences */
#ifdef CONFIG_IMAGE2_MUXER #ifdef CONFIG_IMAGE2_MUXER
if (!short_name && filename && if (!short_name && filename &&
filename_number_test(filename) >= 0 && av_filename_number_test(filename) &&
av_guess_image2_codec(filename) != CODEC_ID_NONE) { av_guess_image2_codec(filename) != CODEC_ID_NONE) {
return guess_format("image2", NULL, NULL); return guess_format("image2", NULL, NULL);
} }
#endif #endif
if (!short_name && filename && if (!short_name && filename &&
filename_number_test(filename) >= 0 && av_filename_number_test(filename) &&
guess_image_format(filename)) { guess_image_format(filename)) {
return guess_format("image", NULL, NULL); return guess_format("image", NULL, NULL);
} }
@@ -403,12 +403,16 @@ int put_fifo(ByteIOContext *pb, FifoBuffer *f, int buf_size, uint8_t **rptr_ptr)
return 0; return 0;
} }
int filename_number_test(const char *filename) /**
* Allocate the payload of a packet and intialized its fields to default values.
*
* @param filename possible numbered sequence string
* @return 1 if a valid numbered sequence string, 0 otherwise.
*/
int av_filename_number_test(const char *filename)
{ {
char buf[1024]; char buf[1024];
if(!filename) return filename && (av_get_frame_filename(buf, sizeof(buf), filename, 1)>=0);
return -1;
return get_frame_filename(buf, sizeof(buf), filename, 1);
} }
/** /**
@@ -635,7 +639,7 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
/* check filename in case of an image number is expected */ /* check filename in case of an image number is expected */
if (fmt->flags & AVFMT_NEEDNUMBER) { if (fmt->flags & AVFMT_NEEDNUMBER) {
if (filename_number_test(filename) < 0) { if (!av_filename_number_test(filename)) {
err = AVERROR_NUMEXPECTED; err = AVERROR_NUMEXPECTED;
goto fail; goto fail;
} }
@@ -2951,11 +2955,17 @@ int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
/** /**
* Returns in 'buf' the path with '%d' replaced by number. * Returns in 'buf' the path with '%d' replaced by number.
*
* Also handles the '%0nd' format where 'n' is the total number * Also handles the '%0nd' format where 'n' is the total number
* of digits and '%%'. Return 0 if OK, and -1 if format error. * of digits and '%%'.
*
* @param buf destination buffer
* @param buf_size destination buffer size
* @param path numbered sequence string
* @number frame number
* @return 0 if OK, -1 if format error.
*/ */
int get_frame_filename(char *buf, int buf_size, int av_get_frame_filename(char *buf, int buf_size,
const char *path, int number) const char *path, int number)
{ {
const char *p; const char *p;