[Libav-user] How to corretly setting container and stream information when using an external encoder and using libavformat to pack the movie container

Carl Eugen Hoyos ceffmpeg at gmail.com
Sat Oct 26 11:59:21 EEST 2019

Am Sa., 26. Okt. 2019 um 10:26 Uhr schrieb Ingmar Rieger <dev at irieger.net>:

> I'm currently working on integrating Cineform file read and write into a
> small toy project for processing image sequences. Worked with exr
> sequences up until now but those are so storage heavy I decided to

> include a intermediate video format and with it being the only freely
> available one I decided to give cineform a go.

That's at least a surprising argumentation given the number of encoders
included in FFmpeg.

> Therefore I implemented a small file reader first using libavformat to
> open video containers and unpacking the stream while passing the frames
> to the Cineform-sdk for decompressing to have the reference decoder.
> Works fine so far.
> Now I'm trying the other way round and pack the frames with the cineform
> encoder and then create a movie container. I tried several approaches
> from several samples and ours of going through the Doxygen documentation
> and google searches etc.
> I'm able to write a file that works correct with my simple reader that
> will just extract package for package from the video stream and gets the
> number of frames right and the result looks fine. But there are still a
> few points I haven't managed to get to work correctly related to
> metadata of the container and the stream:
> 1. Set correct container and stream metadata. I copied the codec
> parameters I extracted from a read cineform example (exported from
> Blackmagic DaVinci Resolve) to begin with as I found no better solution
> for this use case yet.

>   - Bit rate is just the value from one sample and depends very much on
> the input resolution, I think the value is from a 4K sample file. Does
> this really matter? The value reported from "ffmpeg -i testout.mov" is
> completely different anyway, I assume it is calculated when calling
> "av_write_trailer"?

And is the written value correct?

> 2. Correct frame rate/time base settings. Tried several examples, tried
> replicating what I extracted from them and made of the documentation
> regarding libav I found about this topic but as the link below (ffmpeg
> -i output) shows, the framerate is always wrong. Had combinations of
> parameters where I had clips with 16k fps etc.

You have to read back the actual timebase used by the muxer (can
be different than the one you requested) and calculate the timestamps

Carl Eugen

More information about the Libav-user mailing list