[FFmpeg-devel] [PATCH 1/8] ffserver.c: Fix timestamp handling, still creates new clusters for mp4 files, but result is playable

Stephan Holljes klaxa1337 at googlemail.com
Mon May 28 21:18:52 EEST 2018


Signed-off-by: Stephan Holljes <klaxa1337 at googlemail.com>
---
 ffserver.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/ffserver.c b/ffserver.c
index 39e1c32..fc2a1a4 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -133,7 +133,7 @@ void *read_thread(void *arg)
         pkt.pos = -1;
         
         // current pts
-        pts = pkt.pts; //av_rescale_q(pkt.pts, in_stream->time_base, tb);
+        pts = pkt.pts;
         
         // current stream "uptime"
         now = av_gettime_relative() - start;
@@ -200,6 +200,9 @@ void write_segment(struct Client *c)
     struct Segment *seg;
     int ret;
     int pkt_count = 0;
+    AVRational tb;
+    tb.num = 1;
+    tb.den = AV_TIME_BASE;
     pthread_mutex_lock(&c->buffer_lock);
     if (av_fifo_size(c->buffer) > 0) {
         AVFormatContext *fmt_ctx;
@@ -249,8 +252,13 @@ void write_segment(struct Client *c)
             if (ret < 0)
                 break;
             
-            pkt.dts = seg->ts[pkt_count];
-            pkt.pts = seg->ts[pkt_count+1];
+            pkt.dts = av_rescale_q_rnd(seg->ts[pkt_count], tb,
+                                                        c->ofmt_ctx->streams[pkt.stream_index]->time_base,
+                                                               AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
+            pkt.pts = av_rescale_q_rnd(seg->ts[pkt_count+1], tb,
+                                                        c->ofmt_ctx->streams[pkt.stream_index]->time_base,
+                                                               AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
+            pkt.pos = -1;
             pkt_count += 2;
             ret = av_write_frame(c->ofmt_ctx, &pkt);
             av_packet_unref(&pkt);
-- 
2.16.2



More information about the ffmpeg-devel mailing list