From f21f294e05a6f0a06910236707bdfc82b4432487 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 19 Aug 2011 17:52:44 +0200 Subject: [PATCH 1/6] avconv: rescue poor abused limit_filesize global. Keep a per-OutputFile instance of it, thus making -fs work with multiple output files. Signed-off-by: Alex Converse --- avconv.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/avconv.c b/avconv.c index 8656a15453..3dddc8d1f6 100644 --- a/avconv.c +++ b/avconv.c @@ -197,7 +197,7 @@ static int64_t extra_size = 0; static int nb_frames_dup = 0; static int nb_frames_drop = 0; static int input_sync; -static uint64_t limit_filesize = 0; +static uint64_t limit_filesize = UINT64_MAX; static int force_fps = 0; static char *forced_key_frames = NULL; @@ -303,6 +303,7 @@ typedef struct OutputFile { int ost_index; /* index of the first stream in output_streams */ int64_t recording_time; /* desired length of the resulting file in microseconds */ int64_t start_time; /* start time in microseconds */ + uint64_t limit_filesize; } OutputFile; static InputStream *input_streams = NULL; @@ -2246,12 +2247,15 @@ static int transcode(OutputFile *output_files, smallest output pts */ file_index = -1; for (i = 0; i < nb_output_streams; i++) { + OutputFile *of; int64_t ipts; double opts; ost = &output_streams[i]; + of = &output_files[ost->file_index]; os = output_files[ost->file_index].ctx; ist = &input_streams[ost->source_index]; - if(ost->is_past_recording_time || no_packet[ist->file_index]) + if (ost->is_past_recording_time || no_packet[ist->file_index] || + (os->pb && avio_tell(os->pb) >= of->limit_filesize)) continue; opts = ost->st->pts.val * av_q2d(ost->st->time_base); ipts = ist->pts; @@ -2281,10 +2285,6 @@ static int transcode(OutputFile *output_files, break; } - /* finish if limit size exhausted */ - if (limit_filesize != 0 && limit_filesize <= avio_tell(output_files[0].ctx->pb)) - break; - /* read a frame from it and output it in the fifo */ is = input_files[file_index].ctx; ret= av_read_frame(is, &pkt); @@ -3568,6 +3568,7 @@ static void opt_output_file(const char *filename) output_files[nb_output_files - 1].ost_index = nb_output_streams - oc->nb_streams; output_files[nb_output_files - 1].recording_time = recording_time; output_files[nb_output_files - 1].start_time = start_time; + output_files[nb_output_files - 1].limit_filesize = limit_filesize; av_dict_copy(&output_files[nb_output_files - 1].opts, format_opts, 0); /* check filename in case of an image number is expected */ @@ -3695,6 +3696,7 @@ static void opt_output_file(const char *filename) chapters_input_file = INT_MAX; recording_time = INT64_MAX; start_time = 0; + limit_filesize = UINT64_MAX; av_freep(&meta_data_maps); nb_meta_data_maps = 0; From c09315084973fb9ee1c2cfdd385d0f35723ed29a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 19 Aug 2011 17:52:45 +0200 Subject: [PATCH 2/6] avconv: fix broken indentation. Signed-off-by: Alex Converse --- avconv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avconv.c b/avconv.c index 3dddc8d1f6..c8ffd64156 100644 --- a/avconv.c +++ b/avconv.c @@ -2257,7 +2257,7 @@ static int transcode(OutputFile *output_files, if (ost->is_past_recording_time || no_packet[ist->file_index] || (os->pb && avio_tell(os->pb) >= of->limit_filesize)) continue; - opts = ost->st->pts.val * av_q2d(ost->st->time_base); + opts = ost->st->pts.val * av_q2d(ost->st->time_base); ipts = ist->pts; if (!input_files[ist->file_index].eof_reached){ if(ipts < ipts_min) { From b62b5cb6fd5f97b7c1cd9b84f183d458e97622a9 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 19 Aug 2011 17:52:46 +0200 Subject: [PATCH 3/6] avconv: call flush_encoders() from transcode() directly. And remove now pointless parameter. Signed-off-by: Alex Converse --- avconv.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/avconv.c b/avconv.c index c8ffd64156..11d77419eb 100644 --- a/avconv.c +++ b/avconv.c @@ -1397,7 +1397,7 @@ static void generate_silence(uint8_t* buf, enum AVSampleFormat sample_fmt, size_ memset(buf, fill_char, size); } -static void flush_encoders(int ist_index, OutputStream *ost_table, int nb_ostreams) +static void flush_encoders(OutputStream *ost_table, int nb_ostreams) { int i, ret; @@ -1406,7 +1406,7 @@ static void flush_encoders(int ist_index, OutputStream *ost_table, int nb_ostrea AVCodecContext *enc = ost->st->codec; AVFormatContext *os = output_files[ost->file_index].ctx; - if (ost->source_index != ist_index || !ost->encoding_needed) + if (!ost->encoding_needed) continue; if (ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO && enc->frame_size <=1) @@ -1797,10 +1797,6 @@ static int output_packet(InputStream *ist, int ist_index, } } discard_packet: - if (pkt == NULL) { - /* EOF handling */ - flush_encoders(ist_index, ost_table, nb_ostreams); - } return 0; } @@ -2371,6 +2367,7 @@ static int transcode(OutputFile *output_files, output_packet(ist, i, output_streams, nb_output_streams, NULL); } } + flush_encoders(output_streams, nb_output_streams); term_exit(); From cf4976ed7b3c4efd18f6ab352de5bd61e8766b6c Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 19 Aug 2011 17:52:47 +0200 Subject: [PATCH 4/6] doc/avconv: extend -ss documentation. Signed-off-by: Alex Converse --- doc/avconv.texi | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/avconv.texi b/doc/avconv.texi index 97ba88144d..37f0cbd415 100644 --- a/doc/avconv.texi +++ b/doc/avconv.texi @@ -134,8 +134,12 @@ to the duration specified in seconds. Set the file size limit. @item -ss @var{position} -Seek to given time position in seconds. -@code{hh:mm:ss[.xxx]} syntax is also supported. +When used as an input option (before @code{-i}), seeks in this input file to +@var{position}. When used as an output option (before an output filename), +decodes but discards input until the timestamps reach @var{position}. This is +slower, but more accurate. + +@var{position} may be either in seconds or in @code{hh:mm:ss[.xxx]} form. @item -itsoffset @var{offset} Set the input time offset in seconds. From f60a6b5853dbf656b307d06144bb20d09a9d41cb Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 19 Aug 2011 17:52:48 +0200 Subject: [PATCH 5/6] avconv: reset input_ts_offset between files. Signed-off-by: Alex Converse --- avconv.c | 1 + doc/avconv.texi | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/avconv.c b/avconv.c index 11d77419eb..4d1c1a4494 100644 --- a/avconv.c +++ b/avconv.c @@ -3065,6 +3065,7 @@ static int opt_input_file(const char *opt, const char *filename) audio_channels = 0; audio_sample_fmt = AV_SAMPLE_FMT_NONE; av_dict_free(&ts_scale); + input_ts_offset = 0; for (i = 0; i < orig_nb_streams; i++) av_dict_free(&opts[i]); diff --git a/doc/avconv.texi b/doc/avconv.texi index 37f0cbd415..0710650fea 100644 --- a/doc/avconv.texi +++ b/doc/avconv.texi @@ -144,7 +144,6 @@ slower, but more accurate. @item -itsoffset @var{offset} Set the input time offset in seconds. @code{[-]hh:mm:ss[.xxx]} syntax is also supported. -This option affects all the input files that follow it. The offset is added to the timestamps of the input files. Specifying a positive offset means that the corresponding streams are delayed by 'offset' seconds. From f5bae2c6ed855f528d68ddab1cad080bcc271440 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 19 Aug 2011 17:52:49 +0200 Subject: [PATCH 6/6] doc/avconv: replace forgotten av by avconv. Signed-off-by: Alex Converse --- doc/avconv.texi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/avconv.texi b/doc/avconv.texi index 0710650fea..a0368a5afe 100644 --- a/doc/avconv.texi +++ b/doc/avconv.texi @@ -68,7 +68,7 @@ specified for the inputs. @chapter Stream selection @c man begin STREAM SELECTION -By default av tries to pick the "best" stream of each type present in input +By default avconv tries to pick the "best" stream of each type present in input files and add them to each output file. For video, this means the highest resolution, for audio the highest channel count. For subtitle it's simply the first subtitle stream. @@ -686,7 +686,7 @@ It disables matching streams from already created mappings. For example, to map ALL streams from the first input file to output @example -av -i INPUT -map 0 output +avconv -i INPUT -map 0 output @end example For example, if you have two audio streams in the first input file,