[FFmpeg-devel] [PATCH] avformat/movenc: Support for variable timescale in mov containers

Kevin Wheatley kevin.j.wheatley at gmail.com
Mon Nov 4 20:42:10 EET 2019


This pair of patches work together to facilitate user specified timescales for
the Movie Header Atom 'mvhd', which allows constant sample table durations for
all frame rates.

Currently there is a fixed timescale of 1000, which is not an even multiple of
all the typical video frame/field rates. This means when performing certain
duration based operations it is possible to be inaccurate.

The default behaviour is left at the current default defined by MOV_TIMESCALE,
but can be over ridden by using the -mov_timescale <int> option.

Typical values of 600 would work for 24, 25 and 30 FPS, for 23.976 and other
fractional rates could use 2997 same as Avid (or 24000 though caution
should be used when encoding long durations).


Example usage that has better behaviour than the current:

# Encode 50 frames at 24FPS and concatenate 5 copies
ffmpeg -f lavfi -i smptebars=duration=2.083333:size=1920x1080:rate=24 \
-codec dnxhd -pix_fmt yuv422p -b:v 115M smptebars_dnx_1000.mov
cat <<EOF > concat_1000.txt
file smptebars_dnx_1000.mov
file smptebars_dnx_1000.mov
file smptebars_dnx_1000.mov
file smptebars_dnx_1000.mov
file smptebars_dnx_1000.mov
EOF
ffmpeg -f concat -i concat_1000.txt -c copy smpte_concat_1000.mov
ffprobe smpte_concat_1000.mov

The output of ffprobe will show a frame rate of 23.99 due to the effect of the
sample durations in the stts entries.

With the new option of -mov_timescale set to 600:

ffmpeg -f lavfi -i smptebars=duration=2.083333:size=1920x1080:rate=24 \
-codec dnxhd -pix_fmt yuv422p -b:v 115M -mov_timescale 600 smptebars_dnx_600.mov
cat <<EOF > concat_600.txt
file smptebars_dnx_600.mov
file smptebars_dnx_600.mov
file smptebars_dnx_600.mov
file smptebars_dnx_600.mov
file smptebars_dnx_600.mov
EOF
ffmpeg -f concat -i concat_600.txt -c copy -mov_timescale 600
smpte_concat_600.mov
ffprobe smpte_concat_600.mov

The durations all line up, the stts table is smaller and no rounding
issues occur.


Kevin Wheatley (2):
  avformat/movenc: Add command line option to set base mov file
    timescale
  avformat/movenc: Use base container timescale, instead of hard coded
    default

 libavformat/movenc.c | 23 ++++++++++++-----------
 libavformat/movenc.h |  1 +
 2 files changed, 13 insertions(+), 11 deletions(-)

--
1.8.5.6
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-avformat-movenc-Use-base-container-timescale-instead.patch
Type: application/octet-stream
Size: 5349 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20191104/3ec68739/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-avformat-movenc-Add-command-line-option-to-set-base-.patch
Type: application/octet-stream
Size: 2181 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20191104/3ec68739/attachment-0001.obj>


More information about the ffmpeg-devel mailing list