video - C++ FFMPEG not writing AVCC box information -
i'm trying encode raw h264 mp4 container using ffmpeg api in c++. works fine, avcc box empty, , returns error: [iso file] box "avcc" size 8 invalid
if use command line tool on output file: ffmpeg -i output.mp4 -vcodec copy fixed.mp4
the output file works , avcc populated required information. i'm @ loss why command line argument works i'm unable produce same result using api.
what in c++ code (also things in between function calls):
outputformat_ = av_guess_format( "mp4", null, null ); //av_codec_h264 formatcontext_ = avformat_alloc_context(); formatcontext_->oformat = outputformat_; ... avdictionary *opts = null; char tmpstr[50]; sprintf(tmpstr, "%i", muxrate * kilobytestobytes); av_dict_set(&opts, "muxrate", tmpstr, 0); avformat_write_header( formatcontext_, &opts); av_write_trailer(formatcontext_);
the output of correct, except it's missing avcc information. adding manually (and fixing box lengths accordingly) lets me playback video fine. idea why api calls not generating avcc info?
for reference, here's chars mp4 before fix: .avc1.........................€.8.h...h..........................................ÿÿ....avcc....stts
and after: avc1.........................€.8.h...h..........................................ÿÿ...!avcc.b€(ÿá..gb€(Ú.à.—•...hÎ<€....stts
solved it. data required sps , pps components of avcc codec. raw h264 stream in annex b format, present @ start of every i-frame, in nal units starting 0x00 0x00 0x00 0x01 0x67 , 0x00 0x00 0x00 0x01 0x68. needed copy information avstream codec's extradata field:
codeccontext = stream->codec; ... // videoseqheader contains pps , sps nal unit data codeccontext->extradata = (uint8_t*)malloc( sizeof(uint8_t) * videoseqheader_.size() ); for( unsigned int index = 0; index < videoseqheader_.size(); index++ ) { codeccontext->extradata[index] = videoseqheader_[index]; } codeccontext->extradata_size = (int)videoseqheader_.size();
this resulted in avcc box being correctly populated.
Comments
Post a Comment