summaryrefslogtreecommitdiff
path: root/libavformat/avformat.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2023-05-05 15:45:42 +0200
committerAnton Khirnov <anton@khirnov.net>2023-05-15 10:31:55 +0200
commite930b834a928546f9cbc937f6633709053448232 (patch)
treeb6490fcbb8d5dbc7e8d2f1142754e4268071e8ae /libavformat/avformat.c
parent70433abf7fbc978b5fa0d06951d61ac18ac335f8 (diff)
lavf: use AV_CODEC_PROP_FIELDS where appropriate
H.264 and mpeg12 parsers need to be adjusted at the same time to stop using the value of AVCodecContext.ticks_per_frame, because it is not set correctly unless the codec has been opened. Previously this would result in both the parser and lavf seeing the same incorrect value, which would cancel out. Updating lavf and not the parsers would result in correct value in lavf, but the wrong one in parsers, which would break some tests.
Diffstat (limited to 'libavformat/avformat.c')
-rw-r--r--libavformat/avformat.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/libavformat/avformat.c b/libavformat/avformat.c
index 708d90b38c..fea905693d 100644
--- a/libavformat/avformat.c
+++ b/libavformat/avformat.c
@@ -679,6 +679,7 @@ AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *strea
AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *frame)
{
AVRational fr = st->r_frame_rate;
+ const AVCodecDescriptor *desc = cffstream(st)->codec_desc;
AVCodecContext *const avctx = ffstream(st)->avctx;
AVRational codec_fr = avctx->framerate;
AVRational avg_fr = st->avg_frame_rate;
@@ -688,7 +689,7 @@ AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *f
fr = avg_fr;
}
- if (avctx->ticks_per_frame > 1) {
+ if (desc && (desc->props & AV_CODEC_PROP_FIELDS)) {
if ( codec_fr.num > 0 && codec_fr.den > 0 &&
(fr.num == 0 || av_q2d(codec_fr) < av_q2d(fr)*0.7 && fabs(1.0 - av_q2d(av_div_q(avg_fr, fr))) > 0.1))
fr = codec_fr;
@@ -701,10 +702,12 @@ int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt,
AVStream *ost, const AVStream *ist,
enum AVTimebaseSource copy_tb)
{
+ const AVCodecDescriptor *desc = cffstream(ist)->codec_desc;
const AVCodecContext *const dec_ctx = cffstream(ist)->avctx;
AVCodecContext *const enc_ctx = ffstream(ost)->avctx;
- AVRational dec_ctx_tb = dec_ctx->framerate.num ? av_inv_q(av_mul_q(dec_ctx->framerate,
- (AVRational){dec_ctx->ticks_per_frame, 1}))
+
+ AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 };
+ AVRational dec_ctx_tb = dec_ctx->framerate.num ? av_inv_q(av_mul_q(dec_ctx->framerate, mul))
: (ist->codecpar->codec_type == AVMEDIA_TYPE_AUDIO ? (AVRational){0, 1}
: ist->time_base);