[FFmpeg-devel] [PATCH] examples/muxing: honour distinction between encoder PTS timebase and stream timebase

Stefano Sabatini stefasab at gmail.com
Tue Jan 7 13:05:58 CET 2014


Fix PTS set on the frame when encoding, which must be specified in the
encoder timebase or this will confuse the encoder.

When muxing the packet, the PTS/DTS generated by the encoder is then
rescaled to the stream timebase.
---
 doc/examples/muxing.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/doc/examples/muxing.c b/doc/examples/muxing.c
index 4cf72e5..712dbcc 100644
--- a/doc/examples/muxing.c
+++ b/doc/examples/muxing.c
@@ -426,6 +426,11 @@ static void write_video_frame(AVFormatContext *oc, AVStream *st)
         }
         /* If size is zero, it means the image was buffered. */
 
+        if (pkt.pts != AV_NOPTS_VALUE)
+            pkt.pts = av_rescale_q(pkt.pts, c->time_base, st->time_base);
+        if (pkt.dts != AV_NOPTS_VALUE)
+            pkt.dts = av_rescale_q(pkt.dts, c->time_base, st->time_base);
+
         if (!ret && got_packet && pkt.size) {
             pkt.stream_index = st->index;
 
@@ -545,7 +550,7 @@ int main(int argc, char **argv)
             write_audio_frame(oc, audio_st);
         } else {
             write_video_frame(oc, video_st);
-            frame->pts += av_rescale_q(1, video_st->codec->time_base, video_st->time_base);
+            frame->pts++;
         }
     }
 
-- 
1.8.1.2



More information about the ffmpeg-devel mailing list