[Libav-user] movflags/faststart flag for avcodec_open2

Michael Armes michael.armes at gmail.com
Fri May 4 01:31:10 EEST 2018


Thanks for the reply. It's great to know that I'm on track with the option
name/value and my use of av_dict_set. Also good to know that the -/+ logic
applies here.

Can you confirm that:
AVDictionary* myOptions;
av_dict_set( &myOptions, "movflags", "+faststart", 0 );
avcodec_open2(context, codec, &myOptions);

should set the option on the muxer?

Interestingly, if I use av_opt_serialize on the AvCodecContext after
av_opt_serialize(context, 0, 0, &buffer, ':', ';');

after opening the codec, I don't see the flag set.


I'm looking for the 7th bit (128) to be set on flags, yes?

On Wed, May 2, 2018 at 5:45 PM, Jodon Karlik <jodonk at gmail.com> wrote:

> Hello,
>> I am trying to ensure that I have the moov metadata for H.264 encoded
>> video at the beginning of the file. I have seen examples online that
>> indicate I need to give ffmpeg the "-movflags +faststart"  option, but I am
>> coding against libav*. How do these options translate to the options given
>> to the AVDictionary parameter of avcodec_open2? Or rather, am I barking up
>> the wrong tree entirely?
>> I assumed that it was trivially a dictionary entry with key "movflags"
>> and value "faststart" after I inspected movenc.c in libavformat, but this
>> is not currently working for me and I need to determine what I have wrong
>> (the "how" or the "what"). I appreciate any help.
>> --michael
>> _______________________________________________
>> Libav-user mailing list
>> Libav-user at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/libav-user
> You can search in dict.h and use: int av_dict_set(AVDictionary **pm, const
> char *key, const char *value, int flags).
> Example:
> AVDictionary* myOptions;
> av_dict_set( &myOptions, "movflags", "+faststart", 0 );
> av_dict_set will allocate the dictionary for you.
> To understand how this all works:  there is a bunch of code in ffmpeg that
> deals with AVOptions (and these dictionaries) and converts human readable
> data into the right flags.  In the ffmpeg source code, in
> libavformat/movenc.c you can find:
> static const AVOption options[] = {
>     { "movflags", "MOV muxer flags", offsetof(MOVMuxContext, flags),
> ...
>     { "faststart", "Run a second pass to put the index (moov atom) at the
> beginning of the file", 0, AV_OPT_TYPE_CONST, {.i64 =
> "movflags" },
> The first one defines the human-readable "movflags" to access the "flags"
> member variable, and the one further down that ends with "movflags" is a
> way of saying the "faststart" string refers to a flag that applies to the
> variable movflags.  In opt.c you'll find special code for AV_OPT_TYPE_FLAGS
> that deals with prefixing with "+" or "-" which will add or remove flags
> from the variable specified.  Once you know all of this, the code (and
> settings) become quite readable which is nice.
> Everything that is an AVClass can be accessed using these types of options
> through the AVOptions interfaces (libavutil/opt.h), or passing in an
> AVDictionary with the options when creating it, as you've found.  I've
> found it helpful when starting out to use the AVOptions interface rather
> than AVDictionary.  The reason being, there's more immediately feedback
> through the return code of av_opt_set, and you can grab the configuration
> of an object through av_opt_serialize.  This will help you catch errors
> like setting movflags on the stream rather than the muxer.
> Cheers.
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20180503/0beb07f0/attachment.html>

More information about the Libav-user mailing list