<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello,<div><br></div><div>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?</div><div><br></div><div>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.</div><span class="gmail-HOEnZb"><font color="#888888"><div><br></div><div>--michael</div></font></span></div>
<br>______________________________<wbr>_________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">http://ffmpeg.org/mailman/<wbr>listinfo/libav-user</a><br>
<br></blockquote></div><br>
<div><div><div><div><div>You can search in dict.h and use: int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags). <br><br></div>Example:<br><br></div>AVDictionary* myOptions;<br></div>av_dict_set( &myOptions, "movflags", "+faststart", 0 );<br><br></div>av_dict_set will allocate the dictionary for you.<br><br></div>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:<br><br>static const AVOption options[] = {<br>    { "movflags", "MOV muxer flags", offsetof(MOVMuxContext, flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },<br>...<br>   
 { "faststart", "Run a second pass to put the index (moov atom) at the 
beginning of the file", 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_MOV_FLAG_FASTSTART}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, 
"movflags" },<br><br></div><div class="gmail_extra">
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.<br></div><div class="gmail_extra">

</div><div class="gmail_extra"><br>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.<br><br></div><div class="gmail_extra">Cheers.<br></div></div>