avconv: stop using setpts for input framerate forced with -r
authorAnton Khirnov <anton@khirnov.net>
Fri, 15 Jul 2016 04:50:47 +0000 (06:50 +0200)
committerAnton Khirnov <anton@khirnov.net>
Fri, 22 Jul 2016 17:08:12 +0000 (19:08 +0200)
The setpts filter does not signal to the rest of the filtergraph that
the stream is CFR. Just generate the timestamps manually instead.

avconv.c
avconv.h
avconv_filter.c
configure

index 3a7a898..57c02ac 100644 (file)
--- a/avconv.c
+++ b/avconv.c
@@ -1392,6 +1392,8 @@ static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output)
 
     decoded_frame->pts = guess_correct_pts(&ist->pts_ctx, decoded_frame->pts,
                                            decoded_frame->pkt_dts);
+    if (ist->framerate.num)
+        decoded_frame->pts = ist->cfr_next_pts++;
 
     if (ist->st->sample_aspect_ratio.num)
         decoded_frame->sample_aspect_ratio = ist->st->sample_aspect_ratio;
index cffe114..fcdf3d0 100644 (file)
--- a/avconv.h
+++ b/avconv.h
@@ -269,6 +269,11 @@ typedef struct InputStream {
     int64_t       last_dts;
     int64_t min_pts; /* pts with the smallest value in a current stream */
     int64_t max_pts; /* pts with the higher value in a current stream */
+
+    // when forcing constant input framerate through -r,
+    // this contains the pts that will be given to the next decoded frame
+    int64_t cfr_next_pts;
+
     int64_t nb_samples; /* number of samples in the last decoded audio frame before looping */
     PtsCorrectionContext pts_ctx;
     double ts_scale;
index 96277f8..b78d3bd 100644 (file)
@@ -519,6 +519,8 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter,
     par->height              = ifilter->height;
     par->format              = ifilter->format;
     par->time_base           = tb;
+    if (ist->framerate.num)
+        par->frame_rate      = ist->framerate;
     par->hw_frames_ctx       = ifilter->hw_frames_ctx;
 
     ret = av_buffersrc_parameters_set(ifilter->filter, par);
@@ -552,23 +554,6 @@ static int configure_input_video_filter(FilterGraph *fg, InputFilter *ifilter,
         }
     }
 
-    if (ist->framerate.num) {
-        AVFilterContext *setpts;
-
-        snprintf(name, sizeof(name), "force CFR for input from stream %d:%d",
-                 ist->file_index, ist->st->index);
-        if ((ret = avfilter_graph_create_filter(&setpts,
-                                                avfilter_get_by_name("setpts"),
-                                                name, "N", NULL,
-                                                fg->graph)) < 0)
-            return ret;
-
-        if ((ret = avfilter_link(last_filter, 0, setpts, 0)) < 0)
-            return ret;
-
-        last_filter = setpts;
-    }
-
     snprintf(name, sizeof(name), "trim for input stream %d:%d",
              ist->file_index, ist->st->index);
     ret = insert_trim(((f->start_time == AV_NOPTS_VALUE) || !f->accurate_seek) ?
index 37c5611..5885519 100755 (executable)
--- a/configure
+++ b/configure
@@ -2436,7 +2436,7 @@ swscale_deps="avutil"
 avconv_deps="avcodec avfilter avformat avresample swscale"
 avconv_select="aformat_filter anull_filter asyncts_filter atrim_filter format_filter
                fps_filter null_filter resample_filter scale_filter
-               setpts_filter trim_filter"
+               trim_filter"
 avplay_deps="avcodec avfilter avformat avresample sdl"
 avplay_libs='$sdl_libs'
 avplay_select="rdft format_filter transpose_filter hflip_filter vflip_filter"