Hi !

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 :

ffmpeg -i videoFile.ts -qmin 10 -qmax 51 -vcodec libx264 -vb 300k -acodec 
libfaac -ab 64k videoFile.mp4

It generates correctly a video file with about 300k bit / s for the video and 
64k bit / s for the audio = 364 kb/s.

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.

Here is a sample of my code, I think that some initialisations are missing ...

                               AVOutputFormat * pAVOutputFormat = 
::guess_format(NULL, wFilesOut[i].strFileOut, NULL);
                               wFilesOut[i].pAVFormatCtxW = 
::av_alloc_format_context();
                               AVFormatContext* pAVFormatCtxW = 
wFilesOut[i].pAVFormatCtxW;
                               pAVFormatCtxW->oformat = pAVOutputFormat;
                               strcpy(pAVFormatCtxW->filename, 
wFilesOut[i].strFileOut);

                               pAVFormatCtxW->ctx_flags = AVFMTCTX_NOHEADER;
                               pAVFormatCtxW->oformat->flags |= 
AVFMT_GLOBALHEADER;

                               // add stream video
                               AVStream* pAVStream = 
::av_new_stream(pAVFormatCtxW, pAVFormatCtxW->nb_streams);

                               avcodec_get_context_defaults2(pAVStream->codec, 
AVMEDIA_TYPE_VIDEO);

                               pAVStream->codec->codec_id = CODEC_ID_H264;
                               pAVStream->codec->codec_type = CODEC_TYPE_VIDEO;

                               AVCodecContext * pAVCodecContext = 
pAVStream->codec;

                               pAVCodecContext->width = srcWidth;
                               pAVCodecContext->height = srcHeight;

                               pAVCodecContext->time_base.num = 1;
                               pAVCodecContext->time_base.den = 25;

                               pAVCodecContext->bit_rate = video_bitrate;

                               pAVCodecContext->pix_fmt = PIX_FMT_YUV420P;
                               pAVCodecContext->strict_std_compliance = -2;
                               pAVCodecContext->flags |= 
CODEC_FLAG_GLOBAL_HEADER;

                               pAVCodecContext->qmin = qmin;
                               pAVCodecContext->qmax = qmax;

                               pAVCodecContext->gop_size = gop_size;

                               pAVCodecContext->bit_rate_tolerance = 0;

                               AVCodec* pAVCodecVideo = 
::avcodec_find_encoder(pAVStream->codec->codec_id);
                               int nRes = avcodec_open(pAVStream->codec, 
pAVCodecVideo);
                               if (nRes < 0)
                               {
                                               cerr<<"ERROR : avcodec_open 
failed for video"<<endl;
                                               return nRes;
                               }

                               // Add stream audio
                               pAVStream = ::av_new_stream(pAVFormatCtxW, 
audio_channel);
                               avcodec_get_context_defaults2(pAVStream->codec, 
AVMEDIA_TYPE_AUDIO);

                               pAVStream->codec->codec_id = CODEC_ID_AAC;

                               pAVStream->codec->codec_type = CODEC_TYPE_AUDIO;

                               pAVCodecContext = pAVStream->codec;

                               pAVCodecContext->channels = audio_channel;

                               pAVCodecContext->sample_rate = audio_sample_rate;

                               pAVCodecContext->bit_rate = audio_bitrate;

                               pAVCodecContext->channels = audio_channel;
                               pAVCodecContext->sample_rate = srcAF;

                               pAVCodecContext->flags |= 
CODEC_FLAG_GLOBAL_HEADER;

                               AVCodec* pAVCodecAudio = 
::avcodec_find_encoder(pAVStream->codec->codec_id);
                               //AVCodec* pAVCodecAudio = 
::avcodec_find_encoder_by_name("libfaac");

                               pAVCodecContext->sample_fmt = 
pAVCodecAudio->sample_fmts[0];

                               nRes = avcodec_open(pAVStream->codec, 
pAVCodecAudio);


I thought :
                               pAVCodecContext->bit_rate = video_bitrate;

                               pAVCodecContext->qmin = qmin;
                               pAVCodecContext->qmax = qmax;

and
                               pAVCodecContext->bit_rate = audio_bitrate;

                               pAVCodecContext->qmin = qmin;
                               pAVCodecContext->qmax = qmax;

could solved the issue, but no, it simply generates a kind of CBR does not 
depend on video or audio bitrate set.

Does somebody know why?
_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user

Reply via email to