ffmpeg 240p 360p 480p 720p 1080p 2K 4K 转码多个码率版本的计算方式 【1】

国内视频网站 都是伪高清
最近为客户定制转码系统 参考Youtube的码率

暂时未做SDR和HDR的判断 这个Youtube的码率不一样
但是我通过判断视频fps来改变码率 代码见下

逻辑是这样
然后通过获得源视频的尺寸和比特率
来计算该视频是不是可以被转码为更高清晰度和标准尺寸
默认转360p的单个版本
如果存在更高的版本 追加
进入转码队列

以NASA的1080P的太空测试视频做个测试

Media Descriptors Commands
Comand 1: /usr/local/bin/mediainfo –Inform=file://media/media_general.txt media/earth_night_rotate_1080.mov
Comand 2: /usr/local/bin/mediainfo –Inform=file://media/media_video.txt media/earth_night_rotate_1080.mov

Media Info
$vinfo[‘General_FileExtension’] = ‘mov’;
$vinfo[‘General_Duration’] = ‘30000’; #长度
$vinfo[‘General_Format’] = ‘MPEG-4’;
$vinfo[‘General_Format_Profile’] = ‘QuickTime’;
$vinfo[‘General_CodecID’] = ‘qt’;
$vinfo[‘Video_Format’] = ‘AVC’;
$vinfo[‘Video_Format/Info’] = ‘Advanced Video Codec’;
$vinfo[‘Video_CodecID’] = ‘avc1’;
$vinfo[‘Video_CodecID/Info’] = ‘Advanced Video Coding’;
$vinfo[‘Video_Width’] = ‘1920’;
$vinfo[‘Video_Height’] = ‘1080’; #尺寸
$vinfo[‘Video_PixelAspectRatio’] = ‘1.000’;
$vinfo[‘Video_DisplayAspectRatio’] = ‘1.778’;
$vinfo[‘Video_BitRate_Mode’] = ”;
$vinfo[‘Video_BitRate’] = ‘15372097’; #码率
$vinfo[‘Video_BitRate_Minimum’] = ”;
$vinfo[‘Video_BitRate_Maximum’] = ”;
$vinfo[‘Video_FrameRate_Mode’] = ‘CFR’;
$vinfo[‘Video_FrameRate’] = ‘30.000’; #帧

Encoder Details
$video_type = normal
$aspect = 16:9
$vinfo[‘Original_Width’] = 1920
$vinfo[‘Video_Width’] = 1920

源视频码率15372097
帧<30 fps
ffmpeg -y -i media/earth_night_rotate_1080.mov \
-s 1920×1080 -c:v libx264 -b:v 8000k -maxrate 2237k -bufsize 2237k -c:a libfdk_aac -b:a 128k -movflags faststart -f mp4 out/10_1080p.mp4 \
-s 1280×720 -c:v libx264 -b:v 5000k -maxrate 1535k -bufsize 1536k -c:a libfdk_aac -b:a 128k -movflags faststart -f mp4 out/10_720p.mp4 \
-s 854×480 -c:v libx264 -b:v 2500k -maxrate 960k -bufsize 960k -c:a libfdk_aac -b:a 64k -movflags faststart -f mp4 out/10_480p.mp4 \
-s 640×360 -c:v libx264 -b:v 1000k -maxrate 448k -bufsize 448k -c:a libfdk_aac -b:a 64k -movflags faststart -f mp4 out/10_360p.mp4

ffmpeg 命令是测试的 所以带宽需求设的很低

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注