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

Michael Niedermayer michael at niedermayer.cc
Tue Nov 5 18:52:17 EET 2019


On Mon, Nov 04, 2019 at 06:42:10PM +0000, Kevin Wheatley wrote:
> 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.

Assuming this doesnt violate any specifications and assuming that
it works with all players.
Then it would make sense to select this value automatically based
on the stream timestamps or timebases.
maybe there could be still a -mov_timescale but with an option for
"auto" to autoselect a small one which allows accurate representation
of most streams

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Old school: Use the lowest level language in which you can solve the problem
            conveniently.
New school: Use the highest level language in which the latest supercomputer
            can solve the problem without the user falling asleep waiting.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20191105/94810af9/attachment.sig>


More information about the ffmpeg-devel mailing list