<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=FR link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span lang=EN-US>Hi !<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>I'm working on a project that generates a kind of CBR video file and I want to reproduce the same following command line in code :<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>ffmpeg -i videoFile.ts -qmin 10 -qmax 51 -vcodec libx264 -vb 300k -acodec libfaac -ab 64k videoFile.mp4<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>It generates correctly a video file with about 300k bit / s for the video and 64k bit / s for the audio = 364 kb/s.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>But when I'm trying to do the same thing by sing fmpeg library in C. It never creates a videoFile with the bitrate set.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>Here is a sample of my code, I think that some initialisations are missing ...<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>                               AVOutputFormat * pAVOutputFormat = ::guess_format(NULL, wFilesOut[i].strFileOut, NULL);<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                               wFilesOut[i].pAVFormatCtxW = ::av_alloc_format_context();<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                               AVFormatContext* pAVFormatCtxW = wFilesOut[i].pAVFormatCtxW;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                               pAVFormatCtxW->oformat = pAVOutputFormat;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                               strcpy(pAVFormatCtxW->filename, wFilesOut[i].strFileOut);<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>                               pAVFormatCtxW->ctx_flags = AVFMTCTX_NOHEADER;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                               pAVFormatCtxW->oformat->flags |= AVFMT_GLOBALHEADER;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>                               // add stream video<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                               AVStream* pAVStream = ::av_new_stream(pAVFormatCtxW, pAVFormatCtxW->nb_streams);<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>                               avcodec_get_context_defaults2(pAVStream->codec, AVMEDIA_TYPE_VIDEO);<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>                               </span>pAVStream->codec->codec_id = CODEC_ID_H264;<o:p></o:p></p><p class=MsoNormal>                               pAVStream->codec->codec_type = CODEC_TYPE_VIDEO;<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                               AVCodecContext * pAVCodecContext = pAVStream->codec;<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                               pAVCodecContext->width = srcWidth;<o:p></o:p></p><p class=MsoNormal>                               <span lang=EN-US>pAVCodecContext->height = srcHeight;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>                               pAVCodecContext->time_base.num = 1;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                               pAVCodecContext->time_base.den = 25;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>                               pAVCodecContext->bit_rate = video_bitrate;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>                               pAVCodecContext->pix_fmt = PIX_FMT_YUV420P;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                               </span>pAVCodecContext->strict_std_compliance = -2;<o:p></o:p></p><p class=MsoNormal>                               pAVCodecContext->flags |= CODEC_FLAG_GLOBAL_HEADER;<o:p></o:p></p><p class=MsoNormal>                               <o:p></o:p></p><p class=MsoNormal>                               pAVCodecContext->qmin = qmin;<o:p></o:p></p><p class=MsoNormal>                               pAVCodecContext->qmax = qmax;<o:p></o:p></p><p class=MsoNormal>                               <o:p></o:p></p><p class=MsoNormal>                               pAVCodecContext->gop_size = gop_size;<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                               pAVCodecContext->bit_rate_tolerance = 0;<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                               AVCodec* pAVCodecVideo = ::avcodec_find_encoder(pAVStream->codec->codec_id);<o:p></o:p></p><p class=MsoNormal>                               int nRes = avcodec_open(pAVStream->codec, pAVCodecVideo);<o:p></o:p></p><p class=MsoNormal>                               <span lang=EN-US>if (nRes < 0)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                               {<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                                               cerr<<"ERROR : avcodec_open failed for video"<<endl;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                                               return nRes;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                               }<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>                               // Add stream audio<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                               pAVStream = ::av_new_stream(pAVFormatCtxW, audio_channel);<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                               avcodec_get_context_defaults2(pAVStream->codec, AVMEDIA_TYPE_AUDIO);<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>                               </span>pAVStream->codec->codec_id = CODEC_ID_AAC;<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                               pAVStream->codec->codec_type = CODEC_TYPE_AUDIO;<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                               pAVCodecContext = pAVStream->codec;<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                               pAVCodecContext->channels = audio_channel;<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                               pAVCodecContext->sample_rate = audio_sample_rate;<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                               pAVCodecContext->bit_rate = audio_bitrate;<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                               pAVCodecContext->channels = audio_channel;<o:p></o:p></p><p class=MsoNormal>                               pAVCodecContext->sample_rate = srcAF;<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                               pAVCodecContext->flags |= CODEC_FLAG_GLOBAL_HEADER;<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                               AVCodec* pAVCodecAudio = ::avcodec_find_encoder(pAVStream->codec->codec_id);<o:p></o:p></p><p class=MsoNormal>                               <span lang=EN-US>//AVCodec* pAVCodecAudio = ::avcodec_find_encoder_by_name("libfaac");<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                               <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>                               </span>pAVCodecContext->sample_fmt = pAVCodecAudio->sample_fmts[0];<o:p></o:p></p><p class=MsoNormal>                               <span lang=EN-US>                                                                              </span><o:p></o:p></p><p class=MsoNormal><span lang=EN-US>                               nRes = avcodec_open(pAVStream->codec, pAVCodecAudio);<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>I thought :<o:p></o:p></span></p><p class=MsoNormal>                               pAVCodecContext->bit_rate = video_bitrate;<o:p></o:p></p><p class=MsoNormal>                               <o:p></o:p></p><p class=MsoNormal>                               pAVCodecContext->qmin = qmin;<o:p></o:p></p><p class=MsoNormal>                               pAVCodecContext->qmax = qmax;<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>and <o:p></o:p></p><p class=MsoNormal>                               pAVCodecContext->bit_rate = audio_bitrate;<o:p></o:p></p><p class=MsoNormal>                               <o:p></o:p></p><p class=MsoNormal>                               pAVCodecContext->qmin = qmin;<o:p></o:p></p><p class=MsoNormal>                               <span lang=EN-US>pAVCodecContext->qmax = qmax;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>could solved the issue, but no, it simply generates a kind of CBR does not depend on video or audio bitrate set.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal>Does somebody know why?<o:p></o:p></p></div></body></html>