H.264、H.265视频编解码器学习笔记

x265编解码器下的环境对应

VC6→ Visual Studio 6
vc7→ Visual Studio 2003
vc8→ Visual Studio 2005
vc9→ Visual Studio 2008
vc10→Visual Studio 2010
vc11→Visual Studio 2012
vc12→Visual Studio 2013
vc14→Visual Studio 2015
vc15→Visual Studio 2017

一些零碎知识

%i是Windows命令行中用于循环的变量。在for命令中,%i代表从指定的文件列表中依次取出的每个文件的名称。例如,如果文件列表中有3个文件,分别为file1.txt、file2.txt和file3.txt,那么循环执行时,%i分别代表file1.txt、file2.txt和file3.txt。
%~ni 是 Windows 命令行中用于提取文件名部分的变量。其中 %i 是一个通配符,代表一个变量。在这个命令中,%i 代表了每个输入文件,而 %~ni 代表了 %i 变量中的文件名部分,其中 ~n 表示取文件名,i 是通配符变量的命名。

例如,如果 %i 是文件路径 C:\some\path\file.txt,那么 %~ni 就是 file。

HM编解码器

HM编码

hm 50fps

for %i in ("G:\xiph_dataset\720p_split\50fps\*.yuv") do TAppEncoder.exe -c G:\software\HM-HM-16.20\cfg\encoder_lowdelay_P_main.cfg –-InputFile="%i" --ReconFile="G:\xiph_dataset\720p_hevc\%~ni.yuv"  --BitstreamFile="G:\xiph_dataset\720p_hevc_bin\%~ni.bin"

hm 60fps

for %i in ("G:\xiph_dataset\720p_split\60fps\*.yuv") do TAppEncoder.exe -c G:\software\HM-HM-16.20\cfg\encoder_lowdelay_P_main.cfg --FrameRate=60-InputFile="%i" --ReconFile="G:\xiph_dataset\720p_hevc\%~ni.yuv"  --BitstreamFile="G:\xiph_dataset\720p_hevc_bin\%~ni.bin"

jm-hm 50fps

for %i in ("G:\xiph_dataset\720p_avc\50fps\*.yuv") do TAppEncoder.exe -c G:\software\HM-HM-16.20\cfg\encoder_lowdelay_P_main.cfg –-InputFile="%i" --ReconFile="G:\xiph_dataset\720p_avc_hevc\%~ni.yuv"  --BitstreamFile="G:\xiph_dataset\720p_avc_hevc_bin\%~ni.bin"

jm-hm 60fps

for %i in ("G:\xiph_dataset\720p_avc\60fps\*.yuv") do TAppEncoder.exe -c G:\software\HM-HM-16.20\cfg\encoder_lowdelay_P_main.cfg –-InputFile="%i" --ReconFile="G:\xiph_dataset\720p_avc_hevc\%~ni.yuv"  --BitstreamFile="G:\xiph_dataset\720p_avc_hevc_bin\%~ni.bin"

HM解码

HM

CD G:\software\HM-HM-16.20\bin\vc2015\x64\Release
for %i in ("G:\xiph_dataset\720p_hevc_bin\HM\*.bin") do TAppDecoder.exe -b "%i"

JM-HM

CD G:\software\HM-HM-16.20\bin\vc2015\jm_hm_de\x64\Release
for %i in ("G:\xiph_dataset\720p_avc_hevc_bin\HM\*.bin") do TAppDecoder.exe -b "%i"

x.265

CD G:\software\HM-HM-16.20\bin\vc2015\x265_de\x64\Release
for %i in ("G:\xiph_dataset\720p_hevc_bin\x265\*.bin") do TAppDecoder.exe -b "%i"

JM-x.265

CD G:\software\HM-HM-16.20\bin\vc2015\jm_x265_de\x64\Release
for %i in ("G:\xiph_dataset\720p_avc_hevc_bin\x265\*.bin") do TAppDecoder.exe -b "%i"

部分转码实验
CD G:\software\HM-HM-16.20\bin\vc2015\part_hevc_de\x64\Release
for %i in ("G:\xiph_dataset\720p_split\out\*.bin") do TAppDecoder.exe -b "%i"

CD G:\software\HM-HM-16.20\bin\vc2015\part_avc_hevc_de\x64\Release
for %i in ("G:\xiph_dataset\partially transcoded\out\90_fir_out\*.bin") do TAppDecoder.exe -b "%i"

CD G:\software\HM-HM-16.20\bin\vc2015\part_avc_hevc_de\x64\Release
for %i in ("G:\xiph_dataset\partially transcoded\out\90_mid_out\*.bin") do TAppDecoder.exe -b "%i"

CD G:\software\HM-HM-16.20\bin\vc2015\part_avc_hevc_de\x64\Release
for %i in ("G:\xiph_dataset\partially transcoded\out\90_last_out\*.bin") do TAppDecoder.exe -b "%i"


x265编解码器

x265编码

cd C:\Users\hush\Desktop\x265entest\X265\Release
x265.exe --input "C:\Users\hush\Desktop\x265entest\yuv\720p50_mobcal_ter_000.yuv" --fps 50 --input-res 1280x720 --output "G:\xiph_dataset\720p_hevc_bin\x265\TEST.h265" --recon "G:\xiph_dataset\720p_hevc\x265\TEST.yuv" --bitrate 4000 --keyint 12 --min-keyint 12 --bframes 0 --rect --amp

cd G:\software\x265\x265_3.3\build\vc15-x86_64\Release
for %i in ("G:\xiph_dataset\720p_split\combine\*.yuv") do x265.exe --preset slow --input "%i" --fps 50 --input-res 1280x720 --output "G:\xiph_dataset\720p_split\out\%~ni.bin" --recon "G:\xiph_dataset\720p_split\recon\%~ni.yuv" --bitrate 4000 --keyint 12 --min-keyint 12 --no-scenecut --bframes 0 --rect --amp
x265 50fps

cd G:\software\x265\x265_3.3\build\vc15-x86_64\Release
for %i in ("G:\xiph_dataset\720p_split\50fps\*.yuv") do x265.exe --preset slow --input "%i" --fps 50 --input-res 1280x720 --output "G:\xiph_dataset\720p_hevc_bin\x265\%~ni.bin" --recon "G:\xiph_dataset\720p_hevc\x265\%~ni.yuv" --bitrate 4000 --keyint 12 --min-keyint 12 --no-scenecut --bframes 0 --rect --amp

x265 60fps

cd G:\software\x265\x265_3.3\build\vc15-x86_64\Release
for %i in ("G:\xiph_dataset\720p_split\60fps\*.yuv") do x265.exe --preset slow --input "%i" --fps 60 --input-res 1280x720 --output "G:\xiph_dataset\720p_hevc_bin\x265\%~ni.bin" --recon "G:\xiph_dataset\720p_hevc\x265\%~ni.yuv" --bitrate 4000 --keyint 12 --min-keyint 12 --no-scenecut --bframes 0 --rect --amp

jm_x265 50fps

cd G:\software\x265\x265_3.3\build\vc15-x86_64\Release
for %i in ("G:\xiph_dataset\720p_avc\50fps\*.yuv") do x265.exe --preset slow --input "%i" --fps 50 --input-res 1280x720 --output "G:\xiph_dataset\720p_avc_hevc_bin\x265\%~ni.bin" --recon "G:\xiph_dataset\720p_avc_hevc\x265\%~ni.yuv" --bitrate 4000 --keyint 12 --min-keyint 12 --no-scenecut --bframes 0 --rect --amp

jm_x265 60fps

cd G:\software\x265\x265_3.3\build\vc15-x86_64\Release
for %i in ("G:\xiph_dataset\720p_avc\60fps\*.yuv") do x265.exe --preset slow --input "%i" --fps 60 --input-res 1280x720 --output "G:\xiph_dataset\720p_avc_hevc_bin\x265\%~ni.bin" --recon "G:\xiph_dataset\720p_avc_hevc\x265\%~ni.yuv" --bitrate 4000 --keyint 12 --min-keyint 12 --no-scenecut --bframes 0 --rect --amp

部分转码的命令

50 fps fir
cd G:\software\x265\x265_3.3\build\vc15-x86_64\Release
for %i in ("G:\xiph_dataset\partially transcoded\yuv\50fps\90_fir\*.yuv") do x265.exe --preset slow --input "%i" --fps 50 --input-res 1280x720 --output "G:\xiph_dataset\partially transcoded\out\90_fir_out\%~ni.bin" --recon "G:\xiph_dataset\partially transcoded\recon\90_fir_recon\%~ni.yuv" --bitrate 4000 --keyint 12 --min-keyint 12 --no-scenecut --bframes 0 --rect --amp

50 fps mid
cd G:\software\x265\x265_3.3\build\vc15-x86_64\Release
for %i in ("G:\xiph_dataset\partially transcoded\yuv\50fps\90_mid\*.yuv") do x265.exe --preset slow --input "%i" --fps 50 --input-res 1280x720 --output "G:\xiph_dataset\partially transcoded\out\90_mid_out\%~ni.bin" --recon "G:\xiph_dataset\partially transcoded\recon\90_mid_recon\%~ni.yuv" --bitrate 4000 --keyint 12 --min-keyint 12 --no-scenecut --bframes 0 --rect --amp

50 fps last
cd G:\software\x265\x265_3.3\build\vc15-x86_64\Release
for %i in ("G:\xiph_dataset\partially transcoded\yuv\50fps\90_last\*.yuv") do x265.exe --preset slow --input "%i" --fps 50 --input-res 1280x720 --output "G:\xiph_dataset\partially transcoded\out\90_last_out\%~ni.bin" --recon "G:\xiph_dataset\partially transcoded\recon\90_last_recon\%~ni.yuv" --bitrate 4000 --keyint 12 --min-keyint 12 --no-scenecut --bframes 0 --rect --amp

60 fps fir
cd G:\software\x265\x265_3.3\build\vc15-x86_64\Release
for %i in ("G:\xiph_dataset\partially transcoded\yuv\60fps\90_fir\*.yuv") do x265.exe --preset slow --input "%i" --fps 50 --input-res 1280x720 --output "G:\xiph_dataset\partially transcoded\out\90_fir_out\%~ni.bin" --recon "G:\xiph_dataset\partially transcoded\recon\90_fir_recon\%~ni.yuv" --bitrate 4000 --keyint 12 --min-keyint 12 --no-scenecut --bframes 0 --rect --amp

60 fps mid
cd G:\software\x265\x265_3.3\build\vc15-x86_64\Release
for %i in ("G:\xiph_dataset\partially transcoded\yuv\60fps\90_mid\*.yuv") do x265.exe --preset slow --input "%i" --fps 50 --input-res 1280x720 --output "G:\xiph_dataset\partially transcoded\out\90_mid_out\%~ni.bin" --recon "G:\xiph_dataset\partially transcoded\recon\90_mid_recon\%~ni.yuv" --bitrate 4000 --keyint 12 --min-keyint 12 --no-scenecut --bframes 0 --rect --amp

60 fps last
cd G:\software\x265\x265_3.3\build\vc15-x86_64\Release
for %i in ("G:\xiph_dataset\partially transcoded\yuv\60fps\90_last\*.yuv") do x265.exe --preset slow --input "%i" --fps 50 --input-res 1280x720 --output "G:\xiph_dataset\partially transcoded\out\90_last_out\%~ni.bin" --recon "G:\xiph_dataset\partially transcoded\recon\90_last_recon\%~ni.yuv" --bitrate 4000 --keyint 12 --min-keyint 12 --no-scenecut --bframes 0 --rect --amp

JM编码器编码

JM编码命令

50fps

for %i in ("G:\xiph_dataset\720p_split\50fps\*.yuv") do lencod.exe -f G:\software\jm19.0\JM\bin\encoder_main.cfg –p InputFile ="%i" -p ReconFile ="G:\xiph_dataset\720p_avc\%~ni.yuv"  -p OutputFile= "G:\xiph_dataset\720p_avc_264\%~ni.264"

60fps

for %i in ("G:\xiph_dataset\720p_split\60fps\*.yuv") do lencod.exe -f G:\software\jm19.0\JM\bin\encoder_main.cfg –p InputFile ="%i" -p FrameRate=60 -p ReconFile ="G:\xiph_dataset\720p_avc\%~ni.yuv"  -p OutputFile= "G:\xiph_dataset\720p_avc_264\%~ni.264"

FFMPEG指令

视频文件信息

ffprobe -i F:\whole\NOREFINE\1080P\7M\30fps\out\aspen_1080p_000_7M.bin -v quiet -print_format json -show_format -show_streams


去除Y4M的头文件命令

for %i in ("G:\xiph_dataset\1080P\*.y4m") do ffmpeg -i "%i" -vf "scale=1280:720" -pix_fmt yuv420p "G:\xiph_dataset\1080P\YUV_420\%~ni.yuv"

for %i in ("G:\xiph_dataset\1080P\422\*.y4m") do ffmpeg -i "%i" -vf "scale=1280:720" -pix_fmt yuv422p "G:\xiph_dataset\1080P\YUV_422\%~ni.yuv"

按照30帧分割yuv

for %i in ("G:\xiph_dataset\1080P\YUV_420\*.yuv") do ffmpeg  -s 1280x720 -i "%i" -c:v rawvideo -pix_fmt yuv420p -f segment  -segment_frames 30,60,90,120,150,180,210,240,270,300,330,360,390,420,450,480,510,540,570,600,630,660,690,720,750,780 -reset_timestamps 1 -map 0 "G:\xiph_dataset\1080P\SPLIT\%~ni_%03d.yuv"


for %i in ("G:\xiph_dataset\1080P\YUV_422\*.yuv") do ffmpeg  -pixel_format yuv422p -f rawvideo -s 1280x720 -i "%i" -vf format=yuv422p -f segment  -segment_frames 30,60,90,120,150,180,210,240,270,300,330,360,390,420,450,480,510,540,570,600,630,660,690,720,750,780 -reset_timestamps 1 -map 0 "G:\xiph_dataset\1080P\SPLIT\%~ni_%03d.yuv"

ffmpeg -s 1280x720 -i "G:\xiph_dataset\1080P\YUV_420\riverbed_1080p25.yuv" -c:v rawvideo -pix_fmt yuv420p -f segment  -segment_frames 30,60,90,120,150,180,210,240,270,300,330,360,390,420,450,480,510,540,570,600,630,660,690,720,750,780 -reset_timestamps 1 -map 0 "G:\xiph_dataset\1080P\SPLIT\25fps\riverbed_1080p25_%03d.yuv"

### yuv转png
```cpp
hm
for %i in ("G:\xiph_dataset\720p_hevc\HM\*.yuv") do ffmpeg -s 1280x720 -i "%i" -vf "setpts=PTS-STARTPTS" -q:v 1 "G:\xiph_dataset\piexl_hevc\hm\%~ni_hevc_%2d.png"

x.265

for %i in ("G:\xiph_dataset\720p_hevc\x265\*.yuv") do ffmpeg -s 1280x720 -i "%i" -vf "setpts=PTS-STARTPTS" -q:v 1 "G:\xiph_dataset\piexl_hevc\x265\%~ni_hevc_%2d.png"

jm-hm
for %i in ("G:\xiph_dataset\720p_avc_hevc\HM\*.yuv") do ffmpeg -s 1280x720 -i "%i" -vf "setpts=PTS-STARTPTS" -q:v 1 "G:\xiph_dataset\piexl_avc_hevc\HM\%~ni_hevc_%2d.png"

jm-x265
for %i in ("G:\xiph_dataset\720p_avc_hevc\x265\*.yuv") do ffmpeg -s 1280x720 -i "%i" -vf "setpts=PTS-STARTPTS" -q:v 1 "G:\xiph_dataset\piexl_avc_hevc\x265\%~ni_hevc_%2d.png"

转码实验
fir
for %i in ("G:\xiph_dataset\partially transcoded\recon\90_fir_recon\*.yuv") do ffmpeg -s 1280x720 -i "%i" -vf "setpts=PTS-STARTPTS" -q:v 1 "G:\xiph_dataset\partially transcoded\pixel_avc_hevc\%~ni_hevc_%2d.png"

mid
for %i in ("G:\xiph_dataset\partially transcoded\recon\90_mid_recon\*.yuv") do ffmpeg -s 1280x720 -i "%i" -vf "setpts=PTS-STARTPTS" -q:v 1 "G:\xiph_dataset\partially transcoded\pixel_avc_hevc\%~ni_hevc_%2d.png"

last
for %i in ("G:\xiph_dataset\partially transcoded\recon\90_last_recon\*.yuv") do ffmpeg -s 1280x720 -i "%i" -vf "setpts=PTS-STARTPTS" -q:v 1 "G:\xiph_dataset\partially transcoded\pixel_avc_hevc\%~ni_hevc_%2d.png"

负样本
for %i in ("C:\Users\hush\Desktop\1\*.yuv") do ffmpeg -s 1280x720 -i "%i" -vf "setpts=PTS-STARTPTS" -q:v 1 "G:\xiph_dataset\partially transcoded\pixel_hevc\%~ni_hevc_%2d.png"



yuv拼接

import os

# 原始文件夹路径
# src_dir = r'G:\xiph_dataset\partially transcoded\yuv\50fps\fir'
# src_dir = r'G:\xiph_dataset\partially transcoded\yuv\50fps\mid'
src_dir = r'G:\xiph_dataset\partially transcoded\yuv\50fps\last'

# 目标文件夹路径
# dst_dir = r'G:\xiph_dataset\partially transcoded\yuv\50fps\90_fir'
# dst_dir = r'G:\xiph_dataset\partially transcoded\yuv\50fps\90_mid'
dst_dir = r'G:\xiph_dataset\partially transcoded\yuv\50fps\90_last'
# 每几个文件进行合并
merge_count = 3

# 获取原始文件夹下的所有文件名
files = os.listdir(src_dir)

# 按文件名进行排序
files.sort()

# 遍历每个文件
for i in range(0, len(files), merge_count):
    # 获取本次要合并的文件列表
    merge_files = files[i:i+merge_count]

    # 获取文件名前缀
    prefix = os.path.splitext(merge_files[0])[0]

    # 合并文件的后缀名
    suffix = '_'.join([f.split('_')[-1] for f in merge_files])

    # 合并后的文件名
    merged_filename = prefix + suffix

    # 合并后的文件路径
    merged_filepath = os.path.join(dst_dir, merged_filename)

    # 打开合并后的文件,以二进制写入模式
    with open(merged_filepath, 'wb') as merged_file:
        # 遍历每个要合并的文件
        for merge_file in merge_files:
            # 获取要合并的文件路径
            merge_filepath = os.path.join(src_dir, merge_file)

            # 打开要合并的文件,以二进制读取模式
            with open(merge_filepath, 'rb') as f:
                # 读取文件内容并写入合并后的文件
                merged_file.write(f.read())

猜你喜欢

转载自blog.csdn.net/qq_39969848/article/details/130235667