Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/2] avformat/mov: fix timecode with high frame rate content
@ 2022-04-10 18:11 Marton Balint
  2022-04-10 18:12 ` [FFmpeg-devel] [PATCH 2/2] avutil/timecode: use timecode fps for number of frame digits Marton Balint
  2022-04-11  7:54 ` [FFmpeg-devel] [PATCH 1/2] avformat/mov: fix timecode with high frame rate content Anton Khirnov
  0 siblings, 2 replies; 5+ messages in thread
From: Marton Balint @ 2022-04-10 18:11 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Marton Balint

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>
---
 libavformat/isom.h |  1 +
 libavformat/mov.c  | 14 +++++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index 5caf42b15d..99408a42d1 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -214,6 +214,7 @@ typedef struct MOVStreamContext {
     int has_palette;
     int64_t data_size;
     uint32_t tmcd_flags;  ///< tmcd track flags
+    uint8_t tmcd_nb_frames;  ///< tmcd number of frames per tick / second
     int64_t track_end;    ///< used for dts generation in fragmented movie files
     int start_pad;        ///< amount of samples to skip due to enc-dec delay
     unsigned int rap_group_count;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 6c847de164..8527591ff3 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);
@@ -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);
-- 
2.31.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] [PATCH 2/2] avutil/timecode: use timecode fps for number of frame digits
  2022-04-10 18:11 [FFmpeg-devel] [PATCH 1/2] avformat/mov: fix timecode with high frame rate content Marton Balint
@ 2022-04-10 18:12 ` Marton Balint
  2022-04-11  7:54 ` [FFmpeg-devel] [PATCH 1/2] avformat/mov: fix timecode with high frame rate content Anton Khirnov
  1 sibling, 0 replies; 5+ messages in thread
From: Marton Balint @ 2022-04-10 18:12 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Marton Balint

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavutil/timecode.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavutil/timecode.c b/libavutil/timecode.c
index a37d725fc7..b93f05b4b8 100644
--- a/libavutil/timecode.c
+++ b/libavutil/timecode.c
@@ -104,7 +104,7 @@ char *av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum)
 {
     int fps = tc->fps;
     int drop = tc->flags & AV_TIMECODE_FLAG_DROPFRAME;
-    int hh, mm, ss, ff, neg = 0;
+    int hh, mm, ss, ff, ff_len, neg = 0;
 
     framenum += tc->start;
     if (drop)
@@ -119,9 +119,10 @@ char *av_timecode_make_string(const AVTimecode *tc, char *buf, int framenum)
     hh = framenum / (fps*3600LL);
     if (tc->flags & AV_TIMECODE_FLAG_24HOURSMAX)
         hh = hh % 24;
-    snprintf(buf, AV_TIMECODE_STR_SIZE, "%s%02d:%02d:%02d%c%02d",
+    ff_len = fps > 10000 ? 5 : fps > 1000 ? 4 : fps > 100 ? 3 : fps > 10 ? 2 : 1;
+    snprintf(buf, AV_TIMECODE_STR_SIZE, "%s%02d:%02d:%02d%c%0*d",
              neg ? "-" : "",
-             hh, mm, ss, drop ? ';' : ':', ff);
+             hh, mm, ss, drop ? ';' : ':', ff_len, ff);
     return buf;
 }
 
-- 
2.31.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/2] avformat/mov: fix timecode with high frame rate content
  2022-04-10 18:11 [FFmpeg-devel] [PATCH 1/2] avformat/mov: fix timecode with high frame rate content Marton Balint
  2022-04-10 18:12 ` [FFmpeg-devel] [PATCH 2/2] avutil/timecode: use timecode fps for number of frame digits Marton Balint
@ 2022-04-11  7:54 ` Anton Khirnov
  2022-04-11 20:57   ` Marton Balint
  1 sibling, 1 reply; 5+ messages in thread
From: Anton Khirnov @ 2022-04-11  7:54 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: Marton Balint

Quoting Marton Balint (2022-04-10 20:11:59)
> 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.

Sounds like there should be a test for this.

-- 
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/2] avformat/mov: fix timecode with high frame rate content
  2022-04-11  7:54 ` [FFmpeg-devel] [PATCH 1/2] avformat/mov: fix timecode with high frame rate content Anton Khirnov
@ 2022-04-11 20:57   ` Marton Balint
  2022-04-20 17:59     ` Marton Balint
  0 siblings, 1 reply; 5+ messages in thread
From: Marton Balint @ 2022-04-11 20:57 UTC (permalink / raw)
  To: FFmpeg development discussions and patches



On Mon, 11 Apr 2022, Anton Khirnov wrote:

> Quoting Marton Balint (2022-04-10 20:11:59)
>> 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.
>
> Sounds like there should be a test for this.

The smallest file I managed to find which is affected by this is
mov/canon_6d/mvi_9114.mov, but that is still 12 MB, therefore probably not
fit for addition to fate-samples.

With our muxer, the issue is not reproducible, so remuxing is not an
option.

Regards,
Marton
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/2] avformat/mov: fix timecode with high frame rate content
  2022-04-11 20:57   ` Marton Balint
@ 2022-04-20 17:59     ` Marton Balint
  0 siblings, 0 replies; 5+ messages in thread
From: Marton Balint @ 2022-04-20 17:59 UTC (permalink / raw)
  To: FFmpeg development discussions and patches



On Mon, 11 Apr 2022, Marton Balint wrote:

>
>
> On Mon, 11 Apr 2022, Anton Khirnov wrote:
>
>>  Quoting Marton Balint (2022-04-10 20:11:59)
>>>  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.
>>
>>  Sounds like there should be a test for this.
>
> The smallest file I managed to find which is affected by this is
> mov/canon_6d/mvi_9114.mov, but that is still 12 MB, therefore probably not
> fit for addition to fate-samples.
>
> With our muxer, the issue is not reproducible, so remuxing is not an
> option.

Will apply soon.

Regards,
Marton
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-04-20 17:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-10 18:11 [FFmpeg-devel] [PATCH 1/2] avformat/mov: fix timecode with high frame rate content Marton Balint
2022-04-10 18:12 ` [FFmpeg-devel] [PATCH 2/2] avutil/timecode: use timecode fps for number of frame digits Marton Balint
2022-04-11  7:54 ` [FFmpeg-devel] [PATCH 1/2] avformat/mov: fix timecode with high frame rate content Anton Khirnov
2022-04-11 20:57   ` Marton Balint
2022-04-20 17:59     ` Marton Balint

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git