新锐媒体网站建设方案,网站中文域名,做tcf法语听力题的网站,网站界面友好使用FFMPEG作编码操作时#xff0c;会涉及到将yuv数据编码成h264数据#xff0c;FFmpeg的libavcodec中的libx264.c会调用x264库的源码作编码#xff1a;
1.x264库编译 下载X264#xff0c;地址为#xff1a;http://www.videolan.org/developers/x264.html#xff0c;并解…使用FFMPEG作编码操作时会涉及到将yuv数据编码成h264数据FFmpeg的libavcodec中的libx264.c会调用x264库的源码作编码
1.x264库编译 下载X264地址为http://www.videolan.org/developers/x264.html并解压。 mkdir my_build ./configure --enable-shared --prefix./my_build/ make -j4 make install
2.编译后可以查看 my_build目录
.
|-- bin
| -- x264
|-- include
| |-- x264.h
| -- x264_config.h
-- lib|-- libx264.so - libx264.so.164|-- libx264.so.164-- pkgconfig-- x264.pc其中bin目录下x264为可执行文件我们通过此可执行文件来分析x264库的相关功能
3.运行 通过-h信令我们大致可以了解x264的主要功能和使用方法 ./x264 -h
$ ./x264 -h
x264 core:164
Syntax: x264 [options] -o outfile infileInfile can be raw (in which case resolution is required),or YUV4MPEG (*.y4m),or Avisynth if compiled with support (yes).or libav* formats if compiled with lavf support (no) or ffms support (no).
Outfile type is selected by filename:.264 - Raw bytestream.mkv - Matroska.flv - Flash Video.mp4 - MP4 if compiled with GPAC or L-SMASH support (no)
Output bit depth: 8/10Options:-h, --help List basic options--longhelp List more options--fullhelp List all optionsExample usage:Constant quality mode:x264 --crf 24 -o output inputTwo-pass with a bitrate of 1000kbps:x264 --pass 1 --bitrate 1000 -o output inputx264 --pass 2 --bitrate 1000 -o output inputLossless:x264 --qp 0 -o output inputMaximum PSNR at the cost of speed and visual quality:x264 --preset placebo --tune psnr -o output inputConstant bitrate at 1000kbps with a 2 second-buffer:x264 --vbv-bufsize 2000 --bitrate 1000 -o output inputPresets:--profile string Force the limits of an H.264 profileOverrides all settings.- baseline, main, high, high10, high422, high444--preset string Use a preset to select encoding settings [medium]Overridden by user settings.- ultrafast,superfast,veryfast,faster,fast- medium,slow,slower,veryslow,placebo--tune string Tune the settings for a particular type of sourceor situationOverridden by user settings.Multiple tunings are separated by commas.Only one psy tuning can be used at a time.- psy tunings: film,animation,grain,stillimage,psnr,ssim- other tunings: fastdecode,zerolatencyFrame-type options:-I, --keyint integer or infinite Maximum GOP size [250]--tff Enable interlaced mode (top field first)--bff Enable interlaced mode (bottom field first)--pulldown string Use soft pulldown to change frame rate- none, 22, 32, 64, double, triple, euro (requires cfr input)Ratecontrol:-B, --bitrate integer Set bitrate (kbit/s)--crf float Quality-based VBR (-12-51) [23.0]--vbv-maxrate integer Max local bitrate (kbit/s) [0]--vbv-bufsize integer Set size of the VBV buffer (kbit) [0]-p, --pass integer Enable multipass ratecontrol- 1: First pass, creates stats file- 2: Last pass, does not overwrite stats fileInput/Output:-o, --output string Specify output file--sar width:height Specify Sample Aspect Ratio--fps float|rational Specify framerate--seek integer First frame to encode--frames integer Maximum number of frames to encode--level string Specify level (as defined by Annex A)--quiet Quiet ModeFiltering:--vf, --video-filter filter0/filter1/... Apply video filtering to the input fileFilter options may be specified in filter:optionvalue format.Available filters:crop:left,top,right,bottomselect_every:step,offset1[,...]4.建立一个工程用于将YUV转成H264
编写测试程序 代码结构
.
|-- Makefile
|-- in420.yuv
|-- inc
|-- obj
| -- test.o
|-- out.h264
|-- src
| -- test.cpp
|-- third_lib
| -- x264
| |-- include
| | |-- x264.h
| | -- x264_config.h
| -- lib
| -- libx264.so
-- video_prj
test.cpp内容
#include stdio.h
#include stdlib.h#include stdint.h#if defined ( __cplusplus)
extern C
{
#include x264.h
};
#else
#include x264.h
#endifint main(int argc, char** argv)
{int ret;int y_size;int i,j;FILE* fp_src fopen(./in420.yuv, rb);FILE* fp_dst fopen(out.h264, wb);int frame_num50;int cspX264_CSP_I420;int width640,height360;int iNal 0;x264_nal_t* pNals NULL;x264_t* pHandle NULL;x264_picture_t* pPic_in (x264_picture_t*)malloc(sizeof(x264_picture_t));x264_picture_t* pPic_out (x264_picture_t*)malloc(sizeof(x264_picture_t));x264_param_t* pParam (x264_param_t*)malloc(sizeof(x264_param_t));//Checkif(fp_srcNULL||fp_dstNULL){printf(Error open files.\n);return -1;}x264_param_default(pParam);pParam-i_width width;pParam-i_height height;pParam-i_cspcsp;x264_param_apply_profile(pParam, x264_profile_names[5]);pHandle x264_encoder_open(pParam);x264_picture_init(pPic_out);x264_picture_alloc(pPic_in, csp, pParam-i_width, pParam-i_height);y_size pParam-i_width * pParam-i_height;//detect frame numberif(frame_num0){fseek(fp_src,0,SEEK_END);switch(csp){case X264_CSP_I444:frame_numftell(fp_src)/(y_size*3);break;case X264_CSP_I420:frame_numftell(fp_src)/(y_size*3/2);break;default:printf(Colorspace Not Support.\n);return -1;}fseek(fp_src,0,SEEK_SET);}//Loop to Encodefor( i0;iframe_num;i){switch(csp){case X264_CSP_I444:{fread(pPic_in-img.plane[0],y_size,1,fp_src); //Yfread(pPic_in-img.plane[1],y_size,1,fp_src); //Ufread(pPic_in-img.plane[2],y_size,1,fp_src); //Vbreak;}case X264_CSP_I420:{fread(pPic_in-img.plane[0],y_size,1,fp_src); //Yfread(pPic_in-img.plane[1],y_size/4,1,fp_src); //Ufread(pPic_in-img.plane[2],y_size/4,1,fp_src); //Vbreak;}default:{printf(Colorspace Not Support.\n);return -1;}}pPic_in-i_pts i;ret x264_encoder_encode(pHandle, pNals, iNal, pPic_in, pPic_out);if (ret 0){printf(Error.\n);return -1;}printf(Succeed encode frame: %5d\n,i);for ( j 0; j iNal; j){fwrite(pNals[j].p_payload, 1, pNals[j].i_payload, fp_dst);}}i0;//flush encoderwhile(1){ret x264_encoder_encode(pHandle, pNals, iNal, NULL, pPic_out);if(ret0){break;}printf(Flush 1 frame.\n);for (j 0; j iNal; j){fwrite(pNals[j].p_payload, 1, pNals[j].i_payload, fp_dst);}i;}x264_picture_clean(pPic_in);x264_encoder_close(pHandle);pHandle NULL;free(pPic_in);free(pPic_out);free(pParam);fclose(fp_src);fclose(fp_dst);return 0;
}
文章转载自: http://www.morning.wmglg.cn.gov.cn.wmglg.cn http://www.morning.yktwr.cn.gov.cn.yktwr.cn http://www.morning.yyngs.cn.gov.cn.yyngs.cn http://www.morning.wwklf.cn.gov.cn.wwklf.cn http://www.morning.bqpgq.cn.gov.cn.bqpgq.cn http://www.morning.ycmpk.cn.gov.cn.ycmpk.cn http://www.morning.xgchm.cn.gov.cn.xgchm.cn http://www.morning.rykgh.cn.gov.cn.rykgh.cn http://www.morning.rmlz.cn.gov.cn.rmlz.cn http://www.morning.tntgc.cn.gov.cn.tntgc.cn http://www.morning.zxfdq.cn.gov.cn.zxfdq.cn http://www.morning.rgyts.cn.gov.cn.rgyts.cn http://www.morning.mbhdl.cn.gov.cn.mbhdl.cn http://www.morning.pxwzk.cn.gov.cn.pxwzk.cn http://www.morning.dxxnq.cn.gov.cn.dxxnq.cn http://www.morning.qpqb.cn.gov.cn.qpqb.cn http://www.morning.dpppx.cn.gov.cn.dpppx.cn http://www.morning.qkqpy.cn.gov.cn.qkqpy.cn http://www.morning.rynrn.cn.gov.cn.rynrn.cn http://www.morning.bdtpd.cn.gov.cn.bdtpd.cn http://www.morning.srky.cn.gov.cn.srky.cn http://www.morning.ysskn.cn.gov.cn.ysskn.cn http://www.morning.rnxw.cn.gov.cn.rnxw.cn http://www.morning.qrhh.cn.gov.cn.qrhh.cn http://www.morning.ljllt.cn.gov.cn.ljllt.cn http://www.morning.rxkq.cn.gov.cn.rxkq.cn http://www.morning.gthgf.cn.gov.cn.gthgf.cn http://www.morning.srbsr.cn.gov.cn.srbsr.cn http://www.morning.rkjb.cn.gov.cn.rkjb.cn http://www.morning.guanszz.com.gov.cn.guanszz.com http://www.morning.thbkc.cn.gov.cn.thbkc.cn http://www.morning.sbncr.cn.gov.cn.sbncr.cn http://www.morning.xpqyf.cn.gov.cn.xpqyf.cn http://www.morning.jtrqn.cn.gov.cn.jtrqn.cn http://www.morning.dqwykj.com.gov.cn.dqwykj.com http://www.morning.mxcgf.cn.gov.cn.mxcgf.cn http://www.morning.hmnhp.cn.gov.cn.hmnhp.cn http://www.morning.pznqt.cn.gov.cn.pznqt.cn http://www.morning.kgslc.cn.gov.cn.kgslc.cn http://www.morning.qrgfw.cn.gov.cn.qrgfw.cn http://www.morning.lveyue.com.gov.cn.lveyue.com http://www.morning.ddrdt.cn.gov.cn.ddrdt.cn http://www.morning.mmplj.cn.gov.cn.mmplj.cn http://www.morning.trnl.cn.gov.cn.trnl.cn http://www.morning.ptqpd.cn.gov.cn.ptqpd.cn http://www.morning.nwqyq.cn.gov.cn.nwqyq.cn http://www.morning.swzpx.cn.gov.cn.swzpx.cn http://www.morning.kehejia.com.gov.cn.kehejia.com http://www.morning.rlsd.cn.gov.cn.rlsd.cn http://www.morning.nrfqd.cn.gov.cn.nrfqd.cn http://www.morning.tndhm.cn.gov.cn.tndhm.cn http://www.morning.tddrh.cn.gov.cn.tddrh.cn http://www.morning.zcwtl.cn.gov.cn.zcwtl.cn http://www.morning.fktlr.cn.gov.cn.fktlr.cn http://www.morning.tmbtm.cn.gov.cn.tmbtm.cn http://www.morning.wbxrl.cn.gov.cn.wbxrl.cn http://www.morning.vibwp.cn.gov.cn.vibwp.cn http://www.morning.dsgdt.cn.gov.cn.dsgdt.cn http://www.morning.wnnlr.cn.gov.cn.wnnlr.cn http://www.morning.qcsbs.cn.gov.cn.qcsbs.cn http://www.morning.gkpgj.cn.gov.cn.gkpgj.cn http://www.morning.qhrdx.cn.gov.cn.qhrdx.cn http://www.morning.nmpdm.cn.gov.cn.nmpdm.cn http://www.morning.fbhmn.cn.gov.cn.fbhmn.cn http://www.morning.fmjzl.cn.gov.cn.fmjzl.cn http://www.morning.pjzcp.cn.gov.cn.pjzcp.cn http://www.morning.litao7.cn.gov.cn.litao7.cn http://www.morning.hrgxk.cn.gov.cn.hrgxk.cn http://www.morning.myhpj.cn.gov.cn.myhpj.cn http://www.morning.xkyqq.cn.gov.cn.xkyqq.cn http://www.morning.fdzzh.cn.gov.cn.fdzzh.cn http://www.morning.lzbut.cn.gov.cn.lzbut.cn http://www.morning.gnlyq.cn.gov.cn.gnlyq.cn http://www.morning.ybqlb.cn.gov.cn.ybqlb.cn http://www.morning.rfkyb.cn.gov.cn.rfkyb.cn http://www.morning.qpmwb.cn.gov.cn.qpmwb.cn http://www.morning.ggnrt.cn.gov.cn.ggnrt.cn http://www.morning.bkryb.cn.gov.cn.bkryb.cn http://www.morning.qxkjy.cn.gov.cn.qxkjy.cn http://www.morning.rzsxb.cn.gov.cn.rzsxb.cn