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

Kevin Wheatley kevin.j.wheatley at gmail.com
Fri Nov 8 20:22:45 EET 2019


This set 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 ther
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

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

 libavformat/movenc.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++------
 libavformat/movenc.h |  2 ++
 2 files changed, 85 insertions(+), 11 deletions(-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v2-0001-avformat-movenc-Add-command-line-option-to-set-ba.patch
Type: application/octet-stream
Size: 2185 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20191108/fe07eebd/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v2-0002-avformat-movenc-Use-base-container-timescale-inst.patch
Type: application/octet-stream
Size: 5353 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20191108/fe07eebd/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v2-0003-avformat-movenc-Add-an-automatic-timescale-comput.patch
Type: application/octet-stream
Size: 5125 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20191108/fe07eebd/attachment-0002.obj>


More information about the ffmpeg-devel mailing list