[FFmpeg-devel] [PATCH] examples/transcoding: Fix time_base handling

Jack Lau jacklau1222gm at gmail.com
Wed Feb 5 04:26:42 EET 2025


> 
> AVCodecContext.time_base is not used for decoding.


Thank you for your reply. I understand that time_base is not used during decoding, but the transcoding code calls av_packet_rescale_ts twice, once before decoding and once after encoding, as shown below:

540         if (filter_ctx[stream_index].filter_graph) {
541             StreamContext *stream = &stream_ctx[stream_index];
542     
543             av_log(NULL, AV_LOG_DEBUG, "Going to reencode&filter the frame\n");
544         
545             av_packet_rescale_ts(packet,                                                                                                                   
546                                  ifmt_ctx->streams[stream_index]->time_base,
547                                  stream->dec_ctx->time_base);
548             ret = avcodec_send_packet(stream->dec_ctx, packet);

448         /* prepare packet for muxing */                                                                                                                    
449         enc_pkt->stream_index = stream_index;
450         av_packet_rescale_ts(enc_pkt,
451                              stream->enc_ctx->time_base,
452                              ofmt_ctx->streams[stream_index]->time_base);
453 
454         av_log(NULL, AV_LOG_DEBUG, "Muxing frame\n");
455         /* mux encoded frame */
456         ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt);

If dec_ctx->time_base and enc_ctx->time_base are not consistent, it can lead to incorrect packet duration, which in turn causes issues with the output file's duration.


More information about the ffmpeg-devel mailing list