[FFmpeg-devel] [ffmpeg-devel] H264 encoding with libavcodec/libavformat

Rudolf Polzer divverent
Sat Mar 12 16:28:32 CET 2011


On Sat, Mar 12, 2011 at 04:30:05AM +0900, Quy Pham Sy wrote:
> *Can you point me some examples of using libavcode/libavformat with H264? *
> 
> I did change the some lines in api-example in order to use H264 as following
> 
> encoderCodec = avcodec_find_encoder(CODEC_ID_H264);
> 
> //............ allocate codec context ........
> 
> /* INIT CONFIGURATION FOR H264 */
> 
> /* put sample parameters */
> encoderContext->bit_rate = 400000;
> 
> /* resolution must be a multiple of two */
> encoderContext->width = 352;
> encoderContext->height = 288;
> 
> /* frames per second: 25 frames per second */
> encoderContext->time_base.num = 1;
> encoderContext->time_base.den = 25;
> encoderContext->me_range = 16;
> encoderContext->max_qdiff = 4;
> encoderContext->qmin = 10;
> encoderContext->qmax = 51;
> encoderContext->qcompress = 0.6;
> encoderContext->gop_size = 10; /* emit one intra frame every ten frames */
> encoderContext->max_b_frames=1;
> encoderContext->pix_fmt = PIX_FMT_YUV420P;
> 
> //.... continue with original code...
> 
> the quality of the output file is not as good as MPEG1. *Is that because the
> encoder options?

I'd think so, as ffmpeg is known to have REALLY bad defaults for libx264. Can
you try duplicating the x264 options from ffmpeg's "normal" preset in
ffpresets/?

Best regards,

Rudolf Polzer



More information about the ffmpeg-devel mailing list