[FFmpeg-cvslog] examples/transcode_aac: generate proper PTS and set the muxer timebase

Andreas Unterweger git at videolan.org
Tue Jan 27 13:54:54 CET 2015


ffmpeg | branch: master | Andreas Unterweger <dustsigns at gmail.com> | Tue Jan 27 09:03:08 2015 +0100| [3a70c0c95feacb3844d05eebd579fc8189a77eee] | committer: Anton Khirnov

examples/transcode_aac: generate proper PTS and set the muxer timebase

Signed-off-by: Anton Khirnov <anton at khirnov.net>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3a70c0c95feacb3844d05eebd579fc8189a77eee
---

 doc/examples/transcode_aac.c |   13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/doc/examples/transcode_aac.c b/doc/examples/transcode_aac.c
index e0efe2d..60698f7 100644
--- a/doc/examples/transcode_aac.c
+++ b/doc/examples/transcode_aac.c
@@ -182,6 +182,10 @@ static int open_output_file(const char *filename,
     /** Allow the use of the experimental AAC encoder */
     (*output_codec_context)->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
 
+    /** Set the sample rate for the container. */
+    stream->time_base.den = input_codec_context->sample_rate;
+    stream->time_base.num = 1;
+
     /**
      * Some container formats (like MP4) require global headers to be present
      * Mark the encoder so that it behaves accordingly.
@@ -553,6 +557,9 @@ static int init_output_frame(AVFrame **frame,
     return 0;
 }
 
+/** Global timestamp for the audio frames */
+static int64_t pts = 0;
+
 /** Encode one frame worth of audio to the output file. */
 static int encode_audio_frame(AVFrame *frame,
                               AVFormatContext *output_format_context,
@@ -564,6 +571,12 @@ static int encode_audio_frame(AVFrame *frame,
     int error;
     init_packet(&output_packet);
 
+    /** Set a timestamp based on the sample rate for the container. */
+    if (frame) {
+        frame->pts = pts;
+        pts += frame->nb_samples;
+    }
+
     /**
      * Encode the audio frame and store it in the temporary packet.
      * The output audio stream encoder is used to do this.



More information about the ffmpeg-cvslog mailing list