<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hello,<div class=""><br class=""></div><div class="">I’m attempting to use libavformat to generate an MP4 file from a sequence of compressed frames provided to me by an encoder.</div><div class="">I am successfully generating an MP4 file, however I missing something. When sanity checking it with ffmpeg -i file.mp4, I get:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(244, 244, 244); background-color: rgb(0, 0, 0);">ffmpeg version git-2014-11-10-5dcb990 Copyright (c) 2000-2014 the FFmpeg developers</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(244, 244, 244); background-color: rgb(0, 0, 0);"> built on Nov 10 2014 23:50:45 with Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(244, 244, 244); background-color: rgb(0, 0, 0);"> configuration: --prefix=/usr/local/Cellar/ffmpeg/HEAD --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(244, 244, 244); background-color: rgb(0, 0, 0);"> libavutil 54. 11.100 / 54. 11.100</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(244, 244, 244); background-color: rgb(0, 0, 0);"> libavcodec 56. 12.100 / 56. 12.100</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(244, 244, 244); background-color: rgb(0, 0, 0);"> libavformat 56. 12.103 / 56. 12.103</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(244, 244, 244); background-color: rgb(0, 0, 0);"> libavdevice 56. 2.100 / 56. 2.100</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(244, 244, 244); background-color: rgb(0, 0, 0);"> libavfilter 5. 2.103 / 5. 2.103</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(244, 244, 244); background-color: rgb(0, 0, 0);"> libavresample 2. 1. 0 / 2. 1. 0</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(244, 244, 244); background-color: rgb(0, 0, 0);"> libswscale 3. 1.101 / 3. 1.101</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(244, 244, 244); background-color: rgb(0, 0, 0);"> libswresample 1. 1.100 / 1. 1.100</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(244, 244, 244); background-color: rgb(0, 0, 0);"> libpostproc 53. 3.100 / 53. 3.100</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(0, 175, 255); background-color: rgb(0, 0, 0);">[h264 @ 0x7fd02300f000] <span class="" style="color: rgb(255, 37, 0);">no frame!</span></div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);"> Last message repeated 149 times</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(255, 95, 255); background-color: rgb(0, 0, 0);">[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd02300da00] <span class="" style="color: rgb(245, 245, 245);">decoding for stream 0 failed</span></div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(255, 251, 1); background-color: rgb(0, 0, 0);"><span class="" style="color: rgb(255, 95, 255);">[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fd02300da00] </span>Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 1280x720, 4941 kb/s): unspecified pixel format</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(255, 251, 1); background-color: rgb(0, 0, 0);">Consider increasing the value for the 'analyzeduration' and 'probesize' options</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(255, 135, 0); background-color: rgb(0, 0, 0);">/Users/charlie/hd.mp4: could not find codec parameters</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);">Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/charlie/hd.mp4':</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);"> Metadata:</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);"> major_brand : isom</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);"> minor_version : 512</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);"> compatible_brands: isomiso2avc1iso6mp41</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);"> encoder : Lavf56.15.102</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);"> Duration: 00:00:05.23, start: 0.066667, bitrate: 4944 kb/s</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);"> Stream #0:0(und): Video: h264 (avc1 / 0x31637661), none, 1280x720, 4941 kb/s, 30 fps, 30 tbr, 19200 tbn, 38400 tbc (default)</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);"> Metadata:</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(245, 245, 245); background-color: rgb(0, 0, 0);"> handler_name : VideoHandler</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(255, 135, 0); background-color: rgb(0, 0, 0);">At least one output file must be specified</div></div><div class=""><br class=""></div><div class="">The (possibly) relevant bit of code looks like this:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);">/* Add an output stream. */</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">static</span> <span class="" style="color: rgb(187, 44, 162);">void</span> addStream(<span class="" style="color: rgb(79, 129, 135);">OutputStream</span> *ost, <span class="" style="color: rgb(79, 129, 135);">AVFormatContext</span> *oc, <span class="" style="color: rgb(187, 44, 162);">enum</span> <span class="" style="color: rgb(79, 129, 135);">AVCodecID</span> codec_id)</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;">{</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(79, 129, 135);"><span class="" style="color: rgb(0, 0, 0);"> </span>AVCodecContext<span class="" style="color: rgb(0, 0, 0);"> *c;</span></div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> ost-><span class="" style="color: rgb(79, 129, 135);">st</span> = <span class="" style="color: rgb(49, 89, 93);">avformat_new_stream</span>(oc, <span class="" style="color: rgb(39, 42, 216);">0</span>);</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">if</span> (!ost-><span class="" style="color: rgb(79, 129, 135);">st</span>) {</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(209, 47, 27);"><span class="" style="color: rgb(0, 0, 0);"> </span><span class="" style="color: rgb(61, 29, 129);">fprintf</span><span class="" style="color: rgb(0, 0, 0);">(</span><span class="" style="color: rgb(120, 73, 42);">stderr</span><span class="" style="color: rgb(0, 0, 0);">, </span>"Could not allocate stream\n"<span class="" style="color: rgb(0, 0, 0);">);</span></div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">return</span>;</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> }</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;"> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> ost-><span class="" style="color: rgb(79, 129, 135);">st</span>-><span class="" style="color: rgb(79, 129, 135);">id</span> = oc-><span class="" style="color: rgb(79, 129, 135);">nb_streams</span>-<span class="" style="color: rgb(39, 42, 216);">1</span>;</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> c = ost-><span class="" style="color: rgb(79, 129, 135);">st</span>-><span class="" style="color: rgb(79, 129, 135);">codec</span>;</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> c-><span class="" style="color: rgb(79, 129, 135);">codec_id</span> = codec_id;</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">switch</span> (codec_id) {</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(49, 89, 93);"><span class="" style="color: rgb(0, 0, 0);"> </span><span class="" style="color: rgb(187, 44, 162);">case</span><span class="" style="color: rgb(0, 0, 0);"> </span>AV_CODEC_ID_H264<span class="" style="color: rgb(0, 0, 0);">:</span></div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> c-><span class="" style="color: rgb(79, 129, 135);">codec_type</span> = <span class="" style="color: rgb(49, 89, 93);">AVMEDIA_TYPE_VIDEO</span>;</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(120, 73, 42);"><span class="" style="color: rgb(0, 0, 0);"> c-></span><span class="" style="color: rgb(79, 129, 135);">profile</span><span class="" style="color: rgb(0, 0, 0);"> = </span>FF_PROFILE_H264_HIGH<span class="" style="color: rgb(0, 0, 0);">;</span></div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> c-><span class="" style="color: rgb(79, 129, 135);">pix_fmt</span> = <span class="" style="color: rgb(49, 89, 93);">AV_PIX_FMT_YUV420P</span>;</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> c-><span class="" style="color: rgb(79, 129, 135);">framerate</span> = (<span class="" style="color: rgb(79, 129, 135);">AVRational</span>){ <span class="" style="color: rgb(39, 42, 216);">640</span>, <span class="" style="color: rgb(39, 42, 216);">19200</span> };</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> c-><span class="" style="color: rgb(79, 129, 135);">bit_rate</span> = <span class="" style="color: rgb(39, 42, 216);">5000000</span>;</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> c-><span class="" style="color: rgb(79, 129, 135);">width</span> = <span class="" style="color: rgb(39, 42, 216);">1280</span>;</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> c-><span class="" style="color: rgb(79, 129, 135);">height</span> = <span class="" style="color: rgb(39, 42, 216);">720</span>;</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> c-><span class="" style="color: rgb(79, 129, 135);">time_base</span> = (<span class="" style="color: rgb(79, 129, 135);">AVRational</span>){ <span class="" style="color: rgb(39, 42, 216);">1</span>, <span class="" style="color: rgb(39, 42, 216);">60</span> };</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> ost-><span class="" style="color: rgb(79, 129, 135);">st</span>-><span class="" style="color: rgb(79, 129, 135);">time_base</span> = (<span class="" style="color: rgb(79, 129, 135);">AVRational</span>){ <span class="" style="color: rgb(39, 42, 216);">1</span>, <span class="" style="color: rgb(39, 42, 216);">19200</span> };</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> c-><span class="" style="color: rgb(79, 129, 135);">time_base</span> = ost-><span class="" style="color: rgb(79, 129, 135);">st</span>-><span class="" style="color: rgb(79, 129, 135);">time_base</span>;</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;"> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);"><span class="" style="color: rgb(0, 0, 0);"> </span>//c->gop_size = 12; /* emit one intra frame every twelve frames at most */</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);"><span class="" style="color: rgb(0, 0, 0);"> </span>//c->pix_fmt = STREAM_PIX_FMT;</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">break</span>;</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">default</span>:</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">break</span>;</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;"> }</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;"> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);"><span class="" style="color: rgb(0, 0, 0);"> </span>/* Some formats want stream headers to be separate. */</div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(120, 73, 42);"><span class="" style="color: rgb(0, 0, 0);"> </span><span class="" style="color: rgb(187, 44, 162);">if</span><span class="" style="color: rgb(0, 0, 0);"> (oc-></span><span class="" style="color: rgb(79, 129, 135);">oformat</span><span class="" style="color: rgb(0, 0, 0);">-></span><span class="" style="color: rgb(79, 129, 135);">flags</span><span class="" style="color: rgb(0, 0, 0);"> & </span>AVFMT_GLOBALHEADER<span class="" style="color: rgb(0, 0, 0);">)</span></div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(120, 73, 42);"><span class="" style="color: rgb(0, 0, 0);"> ost-></span><span class="" style="color: rgb(79, 129, 135);">st</span><span class="" style="color: rgb(0, 0, 0);">-></span><span class="" style="color: rgb(79, 129, 135);">codec</span><span class="" style="color: rgb(0, 0, 0);">-></span><span class="" style="color: rgb(79, 129, 135);">flags</span><span class="" style="color: rgb(0, 0, 0);"> |= </span>CODEC_FLAG_GLOBAL_HEADER<span class="" style="color: rgb(0, 0, 0);">;</span></div><div class="" style="margin: 0px; font-size: 11px; font-family: Menlo;">}</div></div><div class=""><br class=""></div><div class="">As you can see I am setting the pix_fmt field, but this isn’t being reflected in the final MP4. I am unsure as the whether this information is trying to be determined from the H264 stream, or the MP4, and so am unsure of where the problem lies. Could it be an issue with the SPS and PPS of the H264 stream? Could it be that the pixel format I am specifying is wrong? Presumably it needs to match whatever the encoder is outputting, but the error doesn’t suggest that. It looks more like it tried to scan the entire stream and found nothing…</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Any thoughts appreciated!</div><div class=""><br class=""></div><div class="">Kind regards,</div><div class="">Charlie</div></body></html>