Browse code

Merge commit '488a0fa68973d48e264d54f1722f7afb18afbea7'

* commit '488a0fa68973d48e264d54f1722f7afb18afbea7':
avconv: support -t as an input option.

Conflicts:
Changelog
ffmpeg.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2013/08/06 19:35:48
Showing 5 changed files
... ...
@@ -11,6 +11,8 @@ version <next>
11 11
 - when transcoding with ffmpeg (i.e. not streamcopying), -ss is now accurate
12 12
   even when used as an input option. Previous behavior can be restored with
13 13
   the -noaccurate_seek option.
14
+- ffmpeg -t option can now be used for inputs, to limit the duration of
15
+  data read from an input file
14 16
 
15 17
 
16 18
 version 2.0:
... ...
@@ -1389,6 +1389,7 @@ static int check_output_constraints(InputStream *ist, OutputStream *ost)
1389 1389
 static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt)
1390 1390
 {
1391 1391
     OutputFile *of = output_files[ost->file_index];
1392
+    InputFile   *f = input_files [ist->file_index];
1392 1393
     int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
1393 1394
     int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->st->time_base);
1394 1395
     int64_t ist_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ist->st->time_base);
... ...
@@ -1417,6 +1418,16 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
1417 1417
         return;
1418 1418
     }
1419 1419
 
1420
+    if (f->recording_time != INT64_MAX) {
1421
+        start_time = f->ctx->start_time;
1422
+        if (f->start_time != AV_NOPTS_VALUE)
1423
+            start_time += f->start_time;
1424
+        if (ist->pts >= f->recording_time + start_time) {
1425
+            close_output_stream(ost);
1426
+            return;
1427
+        }
1428
+    }
1429
+
1420 1430
     /* force the input stream PTS */
1421 1431
     if (ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
1422 1432
         audio_size += pkt->size;
... ...
@@ -284,6 +284,7 @@ typedef struct InputFile {
284 284
     int64_t ts_offset;
285 285
     int64_t last_ts;
286 286
     int64_t start_time;   /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */
287
+    int64_t recording_time;
287 288
     int nb_streams;       /* number of stream that ffmpeg is aware of; may be different
288 289
                              from ctx.nb_streams if new streams appear during av_read_frame() */
289 290
     int nb_streams_warn;  /* number of streams that the user was warned of */
... ...
@@ -698,7 +698,7 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter,
698 698
     snprintf(name, sizeof(name), "trim for input stream %d:%d",
699 699
              ist->file_index, ist->st->index);
700 700
     ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
701
-                      AV_NOPTS_VALUE : 0, INT64_MAX, &last_filter, &pad_idx, name);
701
+                      AV_NOPTS_VALUE : 0, f->recording_time, &last_filter, &pad_idx, name);
702 702
     if (ret < 0)
703 703
         return ret;
704 704
 
... ...
@@ -795,7 +795,7 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter,
795 795
     snprintf(name, sizeof(name), "trim for input stream %d:%d",
796 796
              ist->file_index, ist->st->index);
797 797
     ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
798
-                      AV_NOPTS_VALUE : 0, INT64_MAX, &last_filter, &pad_idx, name);
798
+                      AV_NOPTS_VALUE : 0, f->recording_time, &last_filter, &pad_idx, name);
799 799
     if (ret < 0)
800 800
         return ret;
801 801
 
... ...
@@ -842,6 +842,7 @@ static int open_input_file(OptionsContext *o, const char *filename)
842 842
     f->ctx        = ic;
843 843
     f->ist_index  = nb_input_streams - ic->nb_streams;
844 844
     f->start_time = o->start_time;
845
+    f->recording_time = o->recording_time;
845 846
     f->ts_offset  = o->input_ts_offset - (copy_ts ? 0 : timestamp);
846 847
     f->nb_streams = ic->nb_streams;
847 848
     f->rate_emu   = o->rate_emu;
... ...
@@ -2599,7 +2600,8 @@ const OptionDef options[] = {
2599 2599
     { "map_chapters",   HAS_ARG | OPT_INT | OPT_EXPERT | OPT_OFFSET |
2600 2600
                         OPT_OUTPUT,                                  { .off = OFFSET(chapters_input_file) },
2601 2601
         "set chapters mapping", "input_file_index" },
2602
-    { "t",              HAS_ARG | OPT_TIME | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(recording_time) },
2602
+    { "t",              HAS_ARG | OPT_TIME | OPT_OFFSET |
2603
+                        OPT_INPUT | OPT_OUTPUT,                      { .off = OFFSET(recording_time) },
2603 2604
         "record or transcode \"duration\" seconds of audio/video",
2604 2605
         "duration" },
2605 2606
     { "to",             HAS_ARG | OPT_TIME | OPT_OFFSET | OPT_OUTPUT,  { .off = OFFSET(stop_time) },