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

Ingmar Rieger dev at irieger.net
Sat Oct 26 21:56:55 EEST 2019



On 26.10.19 14:37, Carl Eugen Hoyos wrote:
> Am Sa., 26. Okt. 2019 um 14:14 Uhr schrieb Ingmar Rieger <dev at irieger.net>:
> 
>> On 26.10.19 10:59, Carl Eugen Hoyos wrote:
>>> That's at least a surprising argumentation given the number of encoders
>>> included in FFmpeg.
>>
>> Did I miss something? For me the relevant codecs I know for intermediate
>> work are ProRes, DNxHR and Cineform with the later being seldomly used
>> but the only open standard and as I recently found out supported in
>> Resolve for some time now so as my main target is Resolve it seems worth
>> giving it a try. ProRes and DNxHR are both proprietary with only reverse
>> engineered codecs available.
> 
> Correct:
> FFmpeg contains encoders for both ProRes and DNxHR.
> (Note that Cineform being an open standard is a joke, it is exactly as
> proprietary as the others.)
> 
> [...]
Ok you are right. But still Apple is evil etc. (Blackmagic accidentially 
activated ProRes in a beta version showing everyone what is already 
known: There is quicktime support ready...)

Still this discussion helps nothing regarding writing the correct 
container metadata.

>> So basically I have an input like frame_rate (in integer for simplicity,
>> don't care about the crazy 23.98 and other strange rates), a frame
>> number from 0 to NUM_FRAMES-1 and ideally a start time input -> How to
>> set the correct time base/rates and calculate the frame dts/pts?
> 
> As said, you cannot set the time base (you can but you don't have to) but
> you have to read the time base used by the muxer, then calculate timestamps
> using this time base, should be possible with av_rescale_q().

Ok, so what do I set and what will be set automatically in general?
As I said I found no documentation describing how to setup a stream 
manually, that is why I asked in the first place. Just used the remux 
example (which uses avcodec_parameters_copy) as the base and manually 
read information from an existing Cineform encoded by Blackmagic to set 
the parameters manually.

With
 > out_avstream->avg_frame_rate = (AVRational){24, 1};
 > out_avstream->r_frame_rate   = out_avstream->avg_frame_rate;
I now have to correct frame rate shown when av_dump_format is called but 
after writing some frames the frame rate seems to be reset.

My current code that tries to set correct pts/dts values:
 > AVRational timebase_clip  = out_avstream->time_base;
 > AVRational timebase_count = (AVRational){1, 24}; // also tried {24, 1}
 > pkg.pts  = av_rescale_q(frame, timebase_count, timebase_clip);
 > pkg.dts  = pkg.dts;

This results in errors displayed by libav:
 > [mov @ 0x55b6572cfbc0] Application provided invalid, non 
monotonically increasing dts to muxer in stream 0: 6 >= 6

So what is the right way to go from frame number to correct timebase 
conversion. Can someone just give a hint how to correctly call this 
conversions?
 From the outputs and everything I would say I seem to be near a solution.

-- 
Kind regards,
Ingmar


More information about the Libav-user mailing list