[FFmpeg-devel] [PATCH] libavformat/movenc.c: Fix avg_frame_rate inversion on timecode track writing

Ivan Baykalov 4rusxg at gmail.com
Sun Nov 8 21:05:32 EET 2020


When mov_create_timecode_track function is executed,
track->st->avg_frame_rate becomes inverted due to
    track->st->avg_frame_rate = av_inv_q(rate);

, where "rate" is frame per second here.

I didn't find any obvious negative effect of this operation, but this may
lead to some misunderstanding. In particular, it's hard to say why number
of frames per second could be calculated as

    nb_frames      = ROUNDED_DIV(track->st->avg_frame_rate.den,
track->st->avg_frame_rate.num);

---

 libavformat/movenc.c | 6 +++---

 1 file changed, 3 insertions(+), 3 deletions(-)



diff --git a/libavformat/movenc.c b/libavformat/movenc.c index
fea8a86192..e06c902c84 100644

--- a/libavformat/movenc.c

+++ b/libavformat/movenc.c

@@ -2352,8 +2352,8 @@ static int mov_write_tmcd_tag(AVIOContext *pb,
MOVTrack *track)

         return AVERROR(EINVAL);

 #endif

     } else {

-        frame_duration = av_rescale(track->timescale,
track->st->avg_frame_rate.num, track->st->avg_frame_rate.den);

-        nb_frames      = ROUNDED_DIV(track->st->avg_frame_rate.den,
track->st->avg_frame_rate.num);

+        frame_duration = av_rescale(track->timescale,
track->st->avg_frame_rate.den, track->st->avg_frame_rate.num);

+        nb_frames      = ROUNDED_DIV(track->st->avg_frame_rate.num,
track->st->avg_frame_rate.den);

     }



     if (nb_frames > 255) {

@@ -6190,7 +6190,7 @@ static int mov_create_timecode_track(AVFormatContext
*s, int index, int src_inde

         return AVERROR(ENOMEM);

     track->par->codec_type = AVMEDIA_TYPE_DATA;

     track->par->codec_tag  = track->tag;

-    track->st->avg_frame_rate = av_inv_q(rate);

+    track->st->avg_frame_rate = rate;



     /* the tmcd track just contains one packet with the frame number */

     AV_WB32(pkt.data, tc.start);

--

2.28.0.windows.1


More information about the ffmpeg-devel mailing list