看到 @zhangzhao_lenovo 在这里推荐了 Netflix 开源的视频质量评估工具,试用下做个记录,项目地址。
在 Mac 上安装,基本照着 README 做就行了:
# 系统版本 MacOS 10.13.2
brew install gcc freetype pkg-config homebrew/science/hdf5 python
# 替换 MacOS 自带的 Python
echo "export PATH=/usr/local/opt/python/libexec/bin:$PATH" >> ~/.bash_profile
source ~/.bash_profile
brew install numpy scipy
# 和 README 不一样的是用了 pip2 命令
pip2 install matplotlib notebook pandas sympy nose scikit-learn h5py
# 安装 vmaf
git clone https://github.com/Netflix/vmaf.git
cd vmaf
git submodule update --init --recursive
make
echo export PYTHONPATH="$(pwd)/python/src:$(pwd)/sureal/python/src:$PYTHONPATH" >> ~/.bash_profile
source ~/.bash_profile
vmaf 源码里带了一些用于测试的视频,验证一下有没有安装成功:
./run_vmaf yuv420p 576 324 \
python/test/resource/yuv/src01_hrc00_576x324.yuv \
python/test/resource/yuv/src01_hrc01_576x324.yuv \
--out-fmt json
# 执行成功有以下输出
...
],
"aggregate": {
"VMAF_feature_adm2_score": 0.9345878041226809,
"VMAF_feature_motion2_score": 3.8953518541666665,
"VMAF_feature_vif_scale0_score": 0.36342081156994926,
"VMAF_feature_vif_scale1_score": 0.7666473878461729,
"VMAF_feature_vif_scale2_score": 0.8628533892781629,
"VMAF_feature_vif_scale3_score": 0.9159718691393048,
"VMAF_score": 76.69927060701059,
"method": "mean"
}
}
从输出可以看出对转码前和转码后的两个视频逐帧比较,从 6 个维度评分,最后是总分 VMAF_score 。
播放这两个视频用肉眼看看:
brew install ffmpeg --with-sdl2 --with-x265
ffplay -f rawvideo -video_size 576x324 -pixel_format yuv420p src01_hrc00_576x324.yuv
ffplay -f rawvideo -video_size 576x324 -pixel_format yuv420p src01_hrc01_576x324.yuv
找了一个蓝光视频源,用不同参数转码,之后用 vmaf 评下分。
# 视频文件名是 origin.mkv,查看下视频流信息
ffmpeg -i origin.mkv -hide_banner
Stream #0:0(jpn): Video: hevc (Main 10), yuv420p10le(tv), 1920x1080, SAR 1:1 DAR 16:9, 23.98 fps, 23.98 tbr, 1k tbn, 23.98 tbc (default)
# 剪切出 8 秒的片段
ffmpeg -i origin.mkv -vcodec copy -acodec copy -ss 00:20:42 -t 00:00:08 split.mkv
# 输出 .yuv 格式
ffmpeg -i split.mkv split.yuv
# CRF 28 转码
ffmpeg -i split.mkv -c:v libx265 -crf 28 crf28.mkv
# 输出 .yuv 格式
ffmpeg -i crf28.mkv crf28.yuv
# 评分
./run_vmaf yuv420p10le 1920 1080 \
split.yuv \
crf28.yuv \
--out-fmt json
试完往下看 README,发现 vmaf 提供了一个 ffmpeg2vmaf
命令,不用自己输出 .yuv
格式。
在 ${your-vmaf-path}/vmaf/python/src/vmaf/externals.py
里加一行 ffmpeg
路径:
FFMPEG_PATH = "/usr/local/bin/ffmpeg"
# 继续转几个不同质量的视频
ffmpeg -i split.mkv -c:v libx265 -crf 51 crf51.mkv
ffmpeg -i split.mkv -c:v libx265 -crf 27 crf27.mkv
转码前后的视频放在网盘了,可以先播放主观感受下。
# 评分
./ffmpeg2vmaf 1920 1080 split.mkv crf27.mkv --out-fmt json > crf27.json
./ffmpeg2vmaf 1920 1080 split.mkv crf28.mkv --out-fmt json > crf28.json
./ffmpeg2vmaf 1920 1080 split.mkv crf51.mkv --out-fmt json > crf51.json
crf27 得分:
"aggregate": {
"VMAF_feature_adm2_score": 0.9506281927651887,
"VMAF_feature_motion2_score": 15.292086189944133,
"VMAF_feature_vif_scale0_score": 0.7033932664352849,
"VMAF_feature_vif_scale1_score": 0.891849091157867,
"VMAF_feature_vif_scale2_score": 0.9376366751606525,
"VMAF_feature_vif_scale3_score": 0.9605367831047515,
"VMAF_score": 91.54301859617843,
"method": "mean"
}
crf28 得分:
"aggregate": {
"VMAF_feature_adm2_score": 0.9454497740556413,
"VMAF_feature_motion2_score": 15.292086189944133,
"VMAF_feature_vif_scale0_score": 0.6865860812976473,
"VMAF_feature_vif_scale1_score": 0.8774754333779801,
"VMAF_feature_vif_scale2_score": 0.9274710703407736,
"VMAF_feature_vif_scale3_score": 0.9534477600744574,
"VMAF_score": 90.0891120853419,
"method": "mean"
}
crf51 得分:
"aggregate": {
"VMAF_feature_adm2_score": 0.7351725278920788,
"VMAF_feature_motion2_score": 15.292086189944133,
"VMAF_feature_vif_scale0_score": 0.38975482224744185,
"VMAF_feature_vif_scale1_score": 0.49917455035693126,
"VMAF_feature_vif_scale2_score": 0.5541193612075329,
"VMAF_feature_vif_scale3_score": 0.6013419372604807,
"VMAF_score": 27.672561113858062,
"method": "mean"
}