1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

lavc/av1*: fix exporting framerate

* take num_ticks_per_picture_minus_1 into account, since that is a part
  of the framerate computation
* stop exporting num_ticks_per_picture_minus_1 into
  AVCodecContext.ticks_per_frame, as that field is used for other
  purposes (in conjunction with repeat_pict, which is not used at all by
  av1)
This commit is contained in:
Anton Khirnov 2023-05-04 08:47:33 +02:00
parent 7be945a011
commit e10a5b91bc
5 changed files with 29 additions and 15 deletions

View File

@ -1143,7 +1143,7 @@ OBJS-$(CONFIG_AC3_PARSER) += aac_ac3_parser.o ac3tab.o \
ac3_channel_layout_tab.o
OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o
OBJS-$(CONFIG_AMR_PARSER) += amr_parser.o
OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o
OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o av1_parse.o
OBJS-$(CONFIG_AVS2_PARSER) += avs2.o avs2_parser.o
OBJS-$(CONFIG_AVS3_PARSER) += avs3_parser.o
OBJS-$(CONFIG_BMP_PARSER) += bmp_parser.o

View File

@ -108,3 +108,17 @@ void ff_av1_packet_uninit(AV1Packet *pkt)
av_freep(&pkt->obus);
pkt->obus_allocated = pkt->obus_allocated_size = 0;
}
AVRational ff_av1_framerate(int64_t ticks_per_frame, int64_t units_per_tick,
int64_t time_scale)
{
AVRational fr;
if (ticks_per_frame && units_per_tick && time_scale &&
ticks_per_frame < INT64_MAX / units_per_tick &&
av_reduce(&fr.den, &fr.num, units_per_tick * ticks_per_frame,
time_scale, INT_MAX))
return fr;
return (AVRational){ 0, 1 };
}

View File

@ -181,4 +181,7 @@ static inline int get_obu_bit_length(const uint8_t *buf, int size, int type)
return size;
}
AVRational ff_av1_framerate(int64_t ticks_per_frame, int64_t units_per_tick,
int64_t time_scale);
#endif /* AVCODEC_AV1_PARSE_H */

View File

@ -21,6 +21,8 @@
*/
#include "libavutil/avassert.h"
#include "av1_parse.h"
#include "cbs.h"
#include "cbs_av1.h"
#include "parser.h"
@ -162,11 +164,10 @@ static int av1_parser_parse(AVCodecParserContext *ctx,
avctx->color_trc = (enum AVColorTransferCharacteristic) color->transfer_characteristics;
avctx->color_range = color->color_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
if (seq->timing_info_present_flag) {
const AV1RawTimingInfo *timing = &seq->timing_info;
av_reduce(&avctx->framerate.den, &avctx->framerate.num,
timing->num_units_in_display_tick, timing->time_scale, INT_MAX);
}
if (seq->timing_info_present_flag)
avctx->framerate = ff_av1_framerate(1LL + seq->timing_info.num_ticks_per_picture_minus_1,
seq->timing_info.num_units_in_display_tick,
seq->timing_info.time_scale);
end:
ff_cbs_fragment_reset(td);

View File

@ -26,6 +26,7 @@
#include "libavutil/pixdesc.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "av1_parse.h"
#include "av1dec.h"
#include "atsc_a53.h"
#include "bytestream.h"
@ -709,15 +710,10 @@ static int set_context_with_sequence(AVCodecContext *avctx,
}
avctx->sample_aspect_ratio = (AVRational) { 1, 1 };
if (seq->timing_info.num_units_in_display_tick &&
seq->timing_info.time_scale) {
av_reduce(&avctx->framerate.den, &avctx->framerate.num,
seq->timing_info.num_units_in_display_tick,
seq->timing_info.time_scale,
INT_MAX);
if (seq->timing_info.equal_picture_interval)
avctx->ticks_per_frame = seq->timing_info.num_ticks_per_picture_minus_1 + 1;
}
if (seq->timing_info_present_flag)
avctx->framerate = ff_av1_framerate(1LL + seq->timing_info.num_ticks_per_picture_minus_1,
seq->timing_info.num_units_in_display_tick,
seq->timing_info.time_scale);
return 0;
}