@@ -103,6 +103,7 @@ static int open_input_file(const char *filename)
return ret;
}
+ codec_ctx->pkt_timebase = stream->time_base;
codec_type = codec_ctx->codec_type;
/* Reencode video & audio and remux subtitles etc. */
@@ -272,7 +273,7 @@ static int init_filter(FilteringContext *fctx, AVCodecContext *dec_ctx,
snprintf(args, sizeof(args),
"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
- dec_ctx->time_base.num, dec_ctx->time_base.den,
+ dec_ctx->pkt_timebase.num, dec_ctx->pkt_timebase.den,
dec_ctx->sample_aspect_ratio.num,
dec_ctx->sample_aspect_ratio.den);
@@ -443,6 +444,14 @@ static int encode_write_frame(unsigned int stream_index, int flush)
/* encode filtered frame */
av_packet_unref(enc_pkt);
+ if (filt_frame) {
+ /* rescale frame PTS, to match the expected encoder time base */
+ filt_frame->pts = av_rescale_q(filt_frame->pts, filt_frame->time_base,
+ stream->enc_ctx->time_base);
+ filt_frame->pkt_dts = av_rescale_q(filt_frame->pkt_dts, filt_frame->time_base,
+ stream->enc_ctx->time_base);
+ filt_frame->time_base = stream->enc_ctx->time_base;
+ }
ret = avcodec_send_frame(stream->enc_ctx, filt_frame);
if (ret < 0)
@@ -549,7 +558,7 @@ int main(int argc, char **argv)
av_packet_rescale_ts(packet,
ifmt_ctx->streams[stream_index]->time_base,
- stream->dec_ctx->time_base);
+ stream->dec_ctx->pkt_timebase);
ret = avcodec_send_packet(stream->dec_ctx, packet);
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Decoding failed\n");
@@ -564,6 +573,7 @@ int main(int argc, char **argv)
goto end;
stream->dec_frame->pts = stream->dec_frame->best_effort_timestamp;
+ stream->dec_frame->time_base = ifmt_ctx->streams[stream_index]->time_base;
ret = filter_encode_write_frame(stream->dec_frame, stream_index);
if (ret < 0)
goto end;