Compare commits

..

No commits in common. "7a3d43921102a59779ce7dc60529ae1d88de87bf" and "8d350e572d0c62aa23174a0e8f7a59813161e969" have entirely different histories.

3 changed files with 0 additions and 237 deletions

2
.gitignore vendored
View File

@ -1,2 +0,0 @@
vmaf.json
*.csv

View File

@ -1,172 +0,0 @@
#!/usr/bin/env python3
import os
import time
import csv
import ffmpy
from multiprocessing import cpu_count
from collections import OrderedDict
import json
# always round timestamp to integer
def now():
return int(time.time())
def write_line(
codec: str,
crf: str,
preset: str,
infile: str,
outfile: str,
outfilesize: float,
enctime: int,
vmafmean: float,
vmafmin: float,
):
"""
Write line to data csv
Parameters:
codec (str): Codec used
crf (str): CRF used
preset (str): Preset used
infile (str): Input file name
outfile (str): Output file name
outfilesize (float): Size of output file
enctime (int): Time to encode
vmafmean (float): Mean VMAF score
vmafmin (float): Min VMAF score
"""
with open(datafile, "a", newline="") as file:
write = csv.writer(file)
write.writerow(
(
codec,
crf,
preset,
infile,
outfile,
outfilesize,
enctime,
vmafmean,
vmafmin,
)
)
if __name__ == "__main__":
encoding = {
"libx264": {
"crf": [15, 20, 25, 30, 35],
"presets": ["fast", "medium", "slow", "veryslow"],
},
"libx265": {
"crf": [15, 20, 25, 30, 35],
"presets": ["fast", "medium", "slow", "veryslow"],
},
"libaom-av1": {"crf": [20, 25, 30, 35, 40], "presets": [0, 2, 4, 6]},
"libsvtav1": {"crf": [20, 25, 30, 35, 40], "presets": [0, 4, 8, 12]},
}
if not os.path.isdir("encoded"):
os.mkdir("encoded")
datafile = "data-" + str(now()) + ".csv"
with open(datafile, "w", newline="") as file:
write = csv.writer(file)
write.writerow(
(
"Codec",
"CRF",
"Preset",
"Input file",
"Output file",
"Output file size (MiB)",
"Encode time (s)",
"VMAF Score (mean)",
"VMAF Score (min)",
)
)
for codec in encoding:
for crf in encoding[codec]["crf"]:
for preset in encoding[codec]["presets"]:
outputfile = os.path.join(
"encoded",
(
"Sparks_in_Blender-codec_"
+ codec
+ "-crf_"
+ str(crf)
+ "-preset_"
+ str(preset)
+ ".mkv"
),
)
# libaom needs additional options
if codec == "libaom-av1":
ff = ffmpy.FFmpeg(
inputs={"Sparks_in_Blender.webm": None},
outputs={
outputfile: "-c:v {videocodec} -crf {crf} -b:v 0 -cpu-used {preset} -row-mt 1 -tiles 2x2 -g 240 -map 0:v:0 ".format(
videocodec=codec,
crf=crf,
preset=preset,
)
},
)
else:
ff = ffmpy.FFmpeg(
inputs={"Sparks_in_Blender.webm": None},
outputs={
outputfile: "-c:v {videocodec} -crf {crf} -preset {preset} -g 240 -map 0:v:0 ".format(
videocodec=codec,
crf=crf,
preset=preset,
)
},
)
starttime = now()
ff.run()
endtime = now()
difftime = int(endtime - starttime)
outputfilesize = os.path.getsize(outputfile) / 1024 / 1024
ffvmaf = ffmpy.FFmpeg(
inputs=OrderedDict(
[(outputfile, None), ("Sparks_in_Blender.webm", None)]
),
outputs={
"-": "-filter_complex libvmaf=log_fmt=json:n_threads={cputhreads}:log_path=vmaf.json -f null".format(
cputhreads=cpu_count()
)
},
)
ffvmaf.run()
with open("vmaf.json", "r") as file:
vmaf = json.load(file)
write_line(
codec=codec,
crf=crf,
preset=preset,
infile="Sparks_in_Blender.webm",
outfile=outputfile,
outfilesize=outputfilesize,
enctime=difftime,
vmafmean=vmaf["pooled_metrics"]["vmaf"]["mean"],
vmafmin=vmaf["pooled_metrics"]["vmaf"]["min"],
)

View File

@ -1,63 +0,0 @@
# Notes
`ffmpeg -i almatrailer2016a.mp4 -map 0:v:0`
`ffmpeg -i eso1902a.mp4 -map 0:v:0`
`ffmpeg -i Sparks_in_Blender.webm -map 0:v:0`
```
$crf: CRF, see encoder documentation for valid values
$preset: Encoder preset, see documentation for values
$keyint: Keyframe interval. Set to (fps * 10) for consistency
```
## H.264
`-c:v libx264 -crf $crf -preset $preset -g $keyint`
CRF: 051
Presets:
```
ultrafast
superfast
veryfast
faster
fast
medium
slow
slower
veryslow
placebo
```
## H.265
`-c:v libx265 -crf $crf -preset $preset -g $keyint`
CRF: 0-51
Presets:
```
ultrafast
superfast
veryfast
faster
fast
medium
slow
slower
veryslow
placebo
```
## AV1
### libaom
`-c:v libaom-av1 -crf $crf -b:v 0 -cpu-used $preset -row-mt 1 -g $keyint -tiles 2x2`
CRF: 0-63
Presets: 0-6
### SVT-AV1
`-c:v libsvtav1 -crf $crf -preset $preset -g $keyint`
CRF: 0-63
Presets: 0-12