This avoids skipping perfectly formed frames that only lack timestamp.

Partially fixes 361.
---
I am not sure of the ramification of this change so I'm posting this as RFC 
(although it survided one fate session).

While I was tackling this bug https://bugzilla.libav.org/show_bug.cgi?id=361 I 
noticed that in certain conditions an fps filter was added and that frames were 
discarded because they lacked pts. However it is normal that an AVC elementary 
stream may lack pts so there should be "fake" or "default" ones provided when 
none is available.

So to correctly mux an AVC file with this patch one has only to supply -r and 
set the muxing framerate. I wrote 'partially' in the "fix bug" section because 
of this additional requirement; maybe it can be dropped in favour of a log 
message explaining to add -r.

Maybe bump is in order?
Cheers,
    Vittorio

 libavfilter/vf_fps.c |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/libavfilter/vf_fps.c b/libavfilter/vf_fps.c
index 5f62ffd..630bb02 100644
--- a/libavfilter/vf_fps.c
+++ b/libavfilter/vf_fps.c
@@ -176,6 +176,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
     int64_t delta;
     int i, ret;
 
+    // avoid discarding frames when possible
+    if (s->pts == AV_NOPTS_VALUE && s->start_time != DBL_MAX) {
+        double first_pts = s->start_time * AV_TIME_BASE;
+        first_pts = FFMIN(FFMAX(first_pts, INT64_MIN), INT64_MAX);
+        s->first_pts = s->pts = av_rescale_q(first_pts, AV_TIME_BASE_Q,
+                                             inlink->time_base);
+    }
+
     s->frames_in++;
     /* discard frames until we get the first timestamp */
     if (s->pts == AV_NOPTS_VALUE) {
-- 
1.7.9.5

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to