mbox series

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

Message ID 1587405459-29001-1-git-send-email-kevin.j.wheatley@gmail.com
Headers show
Series avformat/movenc: Support for variable timescale in mov containers
Related show

Message

Kevin Wheatley April 20, 2020, 5:57 p.m. UTC
v3 - rebased to current master

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).

An automatic mode has been added if a negative value is passed to the option.
This will compute an appropriate time scale starting from the lowest numbered
video stream's time scale.


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(-)