ffmpeg 编解码相关笔记

时间:2021-06-12 21:37:09
pCodecCtx->gop_size = GOP_SIZE;
pCodecCtx->max_b_frames = MAX_B_FRAMES;
pCodecCtx->pix_fmt = AV_PIX_FMT_YUV420P;


av_opt_set(pCodecCtx->priv_data, "preset", "slow", 0);
av_opt_set(pCodecCtx->priv_data, "crf", "35.000", 0);




1.yuv420p 与yv12 的区别 只是uv顺序相反。


2.ffmpeg raw data对其格式:yuv420p 为16,rgb24为1。如果不做对齐可能会出现rgb数据下方有绿边。


3.ffmpeg ffplay 命令
播放rgb或yuv数据
>ffplay -f rawvideo -pixel_format rgb24 -video_size 1920x1080 e:\workspace\encoder\output\test_cff.rgb


从视频中裁剪出jpg
>ffmpeg -i test.264 %04d.jpg


图片格式转换
>ffmpeg -i e:\workspace\encoder\output\pic\jpgs\1.jpg -pix_fmt rgb24 -r 29.970 -y goutput.rgb



//叠加字符
>ffmpeg -y -i 1.mp4 -s 1280*1024 -vcodec libx264 -refs 2 -x264opts keyint=150:mi
n-keyint=15 -vprofile baseline -level 20 -b:v 200k -vf "drawtext=fontfile=msyh.t
tf: text='来源:迅雷':x=100:y=200:fontsize=50:fontcolor=yellow@0.5:shadowy=2" 2.
mp4


ffmpeg -i 1.mp4 -vf "format=yuv444p, drawbox=y=ih/PHI:color=black@0.4:width=iw:height=48:t=max, drawtext=fontfile=msyh.ttf:text='frame %{n}\\: %{pict_type}\\: %@{localtime\:%a %b %d %Y@}':fontcolor=white:fontsize=24:x=(w-tw)/2:y=(h/PHI)+th, format=yuv420p" -c:v libx264 -c:a copy -movflags +faststart output.mp4


>ffmpeg -i 1.mp4 -vf "format=yuv420p, drawbox=y=ih/PHI:color=black@0.4:width=iw:height=48:t=max, drawtext=fontfile=msyh.ttf:text='%@{localtime\:%a %b %d %Y@}':fontcolor=white:fontsize=24:x=(w-tw)/2:y=(h/PHI)+th, format=yuv420p" -c:v libx264 -c:a copy -movflags +faststart output.mp4




ffmpeg -i /f/p/moto-g\ camera/VID_20141225_140557099.mp4 -filter_complex "drawtext=fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf: text='frame %{n}\\: %{pict_type}\\: pts=%{pts \\: hms}': x=100: y=50: fontsize=24: fontcolor=yellow@0.8: box=1: boxcolor=blue@0.9" -c:a copy -c:v libx264 -preset veryfast -crf 16 -x264-params keyint=60 -map 0 foo.mkv


>ffmpeg -i 1.mp4 -vf "drawtext=fontsize=80:fontfile=msyh.ttf:textfile=CREDITS:y=h-20*t" 11.mp4



解码出raw格式 分辨率可调

ffmpeg.exe -i trailer_1080p.mov -s 1280*720 -pixel_format yu
v420p trailer_1080p1.yuv


播放raw格式 
>ffplay.exe -f rawvideo -pixel_format yuv420p -video_size 1280*720 trailer_1280*720p.yuv