<div dir="ltr"><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"><br><div class="gmail_extra"><div><div class="gmail-m_-3218521178267293242m_1258140664135753716h5"><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 class="gmail-m_-3218521178267293242m_1258140664135753716m_-1348671473499924568gmail-HOEnZb"><div class="gmail-m_-3218521178267293242m_1258140664135753716m_-1348671473499924568gmail-h5"><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 class="gmail-m_-3218521178267293242m_1258140664135753716m_-1348671473499924568gmail-m_2884311302736695445HOEnZb"><div class="gmail-m_-3218521178267293242m_1258140664135753716m_-1348671473499924568gmail-m_2884311302736695445h5"><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"><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><div class="gmail-m_-3218521178267293242m_1258140664135753716m_-1348671473499924568gmail-m_2884311302736695445m_8107019454532287728h5"><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-m_-3218521178267293242m_1258140664135753716m_-1348671473499924568gmail-m_2884311302736695445m_8107019454532287728m_-4837494515208386185gmail-HOEnZb"><font color="#888888"><div><br></div><div>--michael</div></font></span></div>
<br></div></div>______________________________<wbr>_________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">http://ffmpeg.org/mailman/list<wbr>info/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>
<br>______________________________<wbr>_________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">http://ffmpeg.org/mailman/list<wbr>info/libav-user</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div>
<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 class="gmail-m_-3218521178267293242m_1258140664135753716m_-1348671473499924568gmail-HOEnZb"><div class="gmail-m_-3218521178267293242m_1258140664135753716m_-1348671473499924568gmail-h5"><div class="gmail_extra"><div class="gmail_quote">On Thu, May 3, 2018 at 3:31 PM, Michael Armes <span dir="ltr"><<a href="mailto:michael.armes@gmail.com" target="_blank">michael.armes@gmail.com</a>></span> wrote:<br><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"><div>Jordan,</div><div><br></div>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.<div><br></div><div>Can you confirm that:</div><span><div>

<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">AVDictionary* myOptions;<br></div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">av_dict_set( &myOptions, "movflags", "+faststart", 0 );</span>

<br></div></span><div>avcodec_open2(context, codec, &myOptions);<br></div><div><br></div><div>should set the option on the muxer?</div><div><br></div><div>Interestingly, if I use av_opt_serialize on the AvCodecContext after opening </div><div>av_opt_serialize(context, 0, 0, &buffer, ':', ';');<br></div><div><br></div><div>after opening the codec, I don't see the flag set.</div><div><br></div><div>b:1216000;ab:1216000;bt:400000<wbr>0;flags:0x80400000;me_method:-<wbr>1;time_base:1/20;g:12;ar:0;ac:<wbr>0;cutoff:0;frame_size:0;frame_<wbr>number:0;delay:0;qcomp:-1.0000<wbr>0<br></div><div><br></div><div>I'm looking for the 7th bit (128) to be set on flags, yes?</div><div><br></div></div><div class="gmail-m_-3218521178267293242m_1258140664135753716m_-1348671473499924568gmail-m_2884311302736695445HOEnZb"><div class="gmail-m_-3218521178267293242m_1258140664135753716m_-1348671473499924568gmail-m_2884311302736695445h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 2, 2018 at 5:45 PM, Jodon Karlik <span dir="ltr"><<a href="mailto:jodonk@gmail.com" target="_blank">jodonk@gmail.com</a>></span> wrote:<br><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"><br></div></blockquote></div></div></div></div></blockquote></div></div></div></div></blockquote></div></div>

</div></div><span><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"><div>My
 apologizes. Here is the full list of options from the serialize. I do 
appreciate any help. Heads up that I will be away starting tomorrow 
until Monday. If I don't respond timely, it doesn't mean I don't care. 
:-)<br></div><div><br></div><div><br></div><div>b:1216000;ab:1216000;bt:400000<wbr>0;flags:0x80400000;me_method:-<wbr>1;time_base:1/20;g:12;ar:0;ac:<wbr>0;cutoff:0;frame_size:0;frame_<wbr>number:0;delay:0;qcomp:-1.0000<wbr>00;qblur:-1.000000;qmin:-1;qma<wbr>x:-1;qdiff:-1;bf:0;b_qfactor:-<wbr>1.000000;rc_strategy:0;b_strat<wbr>egy:-1;ps:0;mv_bits:0;header_<wbr>bits:0;i_tex_bits:0;p_tex_<wbr>bits:0;i_count:0;p_count:0;<wbr>skip_count:0;misc_bits:0;frame<wbr>_bits:0;codec_tag:0;bug:0x0000<wbr>0001;strict:0;b_qoffset:1.<wbr>250000;err_detect:0x00000000;<wbr>has_b_frames:2;block_align:0;m<wbr>peg_quant:0;qsquish:0.000000;r<wbr>c_qmod_amp:0.000000;rc_qmod_fr<wbr>eq:0;rc_override_count:0;rc_eq<wbr>:;maxrate:0;minrate:0;bufsize:<wbr>0;rc_buf_aggressivity:1.<wbr>000000;i_qfactor:-1.000000;i_<wbr>qoffset:0.000000;rc_init_cplx:<wbr>0.000000;dct:0;lumi_mask:0.<wbr>000000;tcplx_mask:0.000000;scp<wbr>lx_mask:0.000000;p_mask:0.0000<wbr>00;dark_mask:0.000000;idct:0;<wbr>slice_count:0;ec:0x00000003;<wbr>bits_per_coded_sample:0;pred:<wbr>0;aspect:0/1;sar:0/1;debug:<wbr>0x00000000;vismv:0x00000000;<wbr>cmp:-1;subcmp:0;mbcmp:0;<wbr>ildctcmp:8;dia_size:0;last_<wbr>pred:0;preme:0;precmp:0;pre_<wbr>dia_size:0;subq:-1;dtg_active_<wbr>format:0;me_range:-1;ibias:<wbr>999999;pbias:999999;global_<wbr>quality:0;coder:-1;context:0;<wbr>slice_flags:0;xvmc_<wbr>acceleration:0;mbd:0;stream_<wbr>codec_tag:0;sc_threshold:-1;<wbr>lmin:0;lmax:0;nr:-1;rc_init_<wbr>occupancy:-1;flags2:<wbr>0x00000000;error:0;threads:0;<wbr>me_threshold:0;mb_threshold:0;<wbr>dc:0;nssew:8;skip_top:0;skip_<wbr>bottom:0;profile:-99;level:-<wbr>99;lowres:0;skip_threshold:0;<wbr>skip_factor:0;skip_exp:0;<wbr>skipcmp:13;border_mask:0.<wbr>000000;mblmin:236;mblmax:3658;<wbr>mepc:256;skip_loop_filter:0;<wbr>skip_idct:0;skip_frame:0;<wbr>bidir_refine:1;brd_scale:0;<wbr>keyint_min:-1;refs:-1;<wbr>chromaoffset:0;trellis:-1;sc_<wbr>factor:6;mv0_threshold:256;b_<wbr>sensitivity:40;compression_<wbr>level:-1;min_prediction_order:<wbr>0;max_prediction_order:0;<wbr>timecode_frame_start:-1;bits_<wbr>per_raw_sample:0;channel_<wbr>layout:0;request_channel_<wbr>layout:0;rc_max_vbv_use:0.<wbr>000000;rc_min_vbv_use:3.<wbr>000000;ticks_per_frame:2;<wbr>color_primaries:2;color_trc:2;<wbr>colorspace:2;color_range:0;<wbr>chroma_sample_location:0;log_<wbr>level_offset:0;slices:0;<wbr>thread_type:0x00000000;audio_<wbr>service_type:0;request_sample_<wbr>fmt:u8;pkt_timebase:0/1;sub_<wbr>charenc:;sub_charenc_mode:<wbr>0x00000000;sub_text_format:0;<wbr>refcounted_frames:false;side_<wbr>data_only_packets:true;skip_<wbr>alpha:false;field_order:0;<wbr>dump_separator:;codec_<wbr>whitelist:;pixel_format:yuv420<wbr>p;video_size:1204x338<br></div></div><div class="gmail-m_-3218521178267293242m_1258140664135753716m_-1348671473499924568gmail-HOEnZb"><div class="gmail-m_-3218521178267293242m_1258140664135753716m_-1348671473499924568gmail-h5"><div class="gmail_extra"><br></div></div></div></blockquote></div></div>

<br></span></div><div class="gmail_extra">Heads-up the rule here is to not "top post" (i.e. put replies below the original message) and the mods are quite strict on it.  I was hoping someone with more experience would chime in, but I'll give this a shot:<br><br>I think you're applying the dictionary to the wrong object.  If you look at the previous code you're targeting ("faststart" in movenc.c) you'll notice it has a bunch of variables that are nowhere to be found (e.g. min_frag_duration).  This indicates to me that you're inspecting an object that doesn't have the ability for faststart which you're requesting.  It could be that you're writing an AVI as opposed to an MP4 or a MOV, or what's being applied is to the AVCodecContext as opposed to the AVFormatContext (I didn't read into the avcodec_open2, but that would make sense).  For my stuff, I wrote my own C++ wrapper which applies these things in descending order:  Muxer (AVFormatContext), the Stream (AVCodecContext->stream pointers of AVStream), and the Codec itself (AVCodecContext which I think is what you're doing here).  Again, I use av_opt which would catch these things.<br><br></div><div class="gmail_extra">Cheers.<br></div></div>
</blockquote></div><br></div><div class="gmail_extra">Thank you for the help. I think I finally have a handle on what is going on. Firstly, I need to pass the dictionary to avformat_write_header. There are some children on the AVFormatContext that need the option set and this will handle that through avformat_init_output. However, this is only part of the way there. Now I am getting invalid mp4s without the moov atom entirely.</div><div class="gmail_extra"><br></div><div class="gmail_extra"> Secondly, I have a custom IO callbacks that I hooked up through avio_alloc_context. This is necessary because I am in the cloud and do not have a filesystem. The faststart second pass attempts to reopen the file for reading to avoid some read/seek loops. This open is failing. My guess is that I also need to supply custom io_open and io_close callbacks to my AVFormatContext.</div><div class="gmail_extra"><br></div><div class="gmail_extra">I will take it from here.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Cheers,</div><div class="gmail_extra">Michael</div></div>