Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2022-04-10 18:53:30 +0300
committerMarton Balint <cus@passwd.hu>2022-04-22 23:54:56 +0300
commit8dd5bb728038f21d17ec789e21d65fe8f3f364a6 (patch)
tree9857df6d3888547b75a4d56d1186e0db8470d33b /libavformat/mov.c
parent58454749a7e6b854d0120a2f58dff40a3ee7bf40 (diff)
avformat/mov: fix timecode with high frame rate content
60 fps content have "Number of Frames" set to 30 in the tmcd atom, but the frame duration / timescale reflects the original video frame rate. Therefore we multiply the frame count with the quotient of the rounded timecode frame rate and the "Number of Frames" per second to get a frame count in the original (higher) frame rate. Note that the frames part in the timecode will be in high frame rate which will make the timecode different to e.g. MediaInfo which seems to show the 30 fps timecode even for 120 fps content. Regression since 428b4aacb1a91a267650de644519882a5f700388. Fixes ticket #9710. Fixes ticket #9492. Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'libavformat/mov.c')
-rw-r--r--libavformat/mov.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 6c847de164..4db4ded101 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -2364,6 +2364,7 @@ static int mov_parse_stsd_data(MOVContext *c, AVIOContext *pb,
tmcd_ctx->tmcd_flags = val;
st->avg_frame_rate.num = AV_RB32(st->codecpar->extradata + 8); /* timescale */
st->avg_frame_rate.den = AV_RB32(st->codecpar->extradata + 12); /* frameDuration */
+ tmcd_ctx->tmcd_nb_frames = st->codecpar->extradata[16]; /* number of frames */
if (size > 30) {
uint32_t len = AV_RB32(st->codecpar->extradata + 18); /* name atom length */
uint32_t format = AV_RB32(st->codecpar->extradata + 22);
@@ -7848,7 +7849,7 @@ finish:
}
static int parse_timecode_in_framenum_format(AVFormatContext *s, AVStream *st,
- uint32_t value, int flags)
+ int64_t value, int flags)
{
AVTimecode tc;
char buf[AV_TIMECODE_STR_SIZE];
@@ -7893,11 +7894,16 @@ static int mov_read_timecode_track(AVFormatContext *s, AVStream *st)
FFStream *const sti = ffstream(st);
int flags = 0;
int64_t cur_pos = avio_tell(sc->pb);
- uint32_t value;
+ int64_t value;
+ AVRational tc_rate = st->avg_frame_rate;
+ int rounded_tc_rate;
if (!sti->nb_index_entries)
return -1;
+ if (!tc_rate.num || !tc_rate.den || !sc->tmcd_nb_frames)
+ return -1;
+
avio_seek(sc->pb, sti->index_entries->pos, SEEK_SET);
value = avio_rb32(s->pb);
@@ -7910,6 +7916,12 @@ static int mov_read_timecode_track(AVFormatContext *s, AVStream *st)
* No sample with tmcd track can be found with a QT timecode at the moment,
* despite what the tmcd track "suggests" (Counter flag set to 0 means QT
* format). */
+
+ /* 60 fps content have tmcd_nb_frames set to 30 but tc_rate set to 60, so
+ * we multiply the frame number with the quotient. */
+ rounded_tc_rate = (tc_rate.num + tc_rate.den / 2) / tc_rate.den;
+ value = av_rescale(value, rounded_tc_rate, sc->tmcd_nb_frames);
+
parse_timecode_in_framenum_format(s, st, value, flags);
avio_seek(sc->pb, cur_pos, SEEK_SET);