def EncodeWithSVT_HEVC(infile, QP, framenum, framerate, width, height, outfile, preset): args = " -i %s -w %d -h %d -encMode %s -hierarchical-levels 3" \ " -intra-period 100 -scd 0 -rc 0 -q %d -n %d -b %s"\ % (infile, width, height, preset, QP, framenum, outfile) cmd = SVTHEVC + args ExecuteCmd(cmd, LogCmdOnly)
def EncodeWithSVT_AV1(infile, QP, framenum, framerate, width, height, outfile, preset): args = " --preset %s --scm 2 --lookahead 0 --hierarchical-levels 3 -n %d" \ " --keyint 255 -rc 0 -q %d -w %d -h %d -b %s -i %s"\ % (str(preset), framenum, QP, width, height, outfile, infile) cmd = SVTAV1 + args ExecuteCmd(cmd, LogCmdOnly)
def FFMPEG_CalQualityMetrics(origfile, recfile, num, w, h, logfilePath): #calculate psnr using ffmpeg filter to get psnr_u and psnr_v #here we have to pass the psnr_log file name to FFMPEG without the target #log path first, then copy the result psnr log to the target log path after #the ffmpeg call. it doesn't work if the full path is directly passed to FFMPEG psnr_log = GetFfmpegLogFile(recfile, BinPath) psnr_log = os.path.basename(psnr_log) args = " -s %dx%d -pix_fmt yuv420p -i %s -s %dx%d -pix_fmt yuv420p -i %s" \ " -frames:v %d -lavfi psnr=%s -f null -" % \ (w, h, origfile, w, h, recfile, num, psnr_log) cmd = FFMPEG + args ExecuteCmd(cmd, LogCmdOnly) #move the psnr log to the target log path target = os.path.join(logfilePath, psnr_log) cmd = "move %s %s" % (psnr_log, target) ExecuteCmd(cmd, LogCmdOnly)
def EncodeWithFfmpeg_HEVC(infile, QP, num,fr, width, height, outfile, preset): EncodeProfile = 'main' args = " -y -s %dx%d -pix_fmt yuv420p -r %s -i %s -frames:v %d -g %d -bf 7" \ " -bsf:v hevc_mp4toannexb -c:v libx265 -preset %s -profile:v %s " \ "-x265-params \"qp=%d:aq-mode=0:b-adapt=0:bframes=7:b-pyramid=1:" \ "no-scenecut=1:no-open-gop=1:input-depth=8:output-depth=8\" %s" % ( width, height, fr, infile, num, int(2 * fr), # gop size = 2 seconds preset, EncodeProfile, (QP+3), outfile) cmd = FFMPEG + args ExecuteCmd(cmd, LogCmdOnly)
def RescaleWithFfmpeg(infile, inw, inh, outw, outh, algo, outfile, num, app_path): args = " -y -s:v %dx%d -i %s -vf scale=%dx%d -c:v rawvideo -pix_fmt yuv420p" \ " -sws_flags %s+accurate_rnd+full_chroma_int+full_chroma_inp+bitexact"\ "+print_info -sws_dither none" \ % (inw, inh, infile, outw, outh, algo) if (algo == 'lanczos'): args += " -param0 5 " args += " -frames %d %s" % (num, outfile) cmd = FFMPEG + args ExecuteCmd(cmd, LogCmdOnly)
def UpScaling(infile, num, inw, inh, outw, outh, path, algo): upScaleOut = GetUpScaledOutFile(infile, inw, inh, outw, outh, path, algo) Utils.CmdLogger.write("::Upscaling\n") if (inw == outw and inh == outh): cmd = "copy %s %s" % (infile, upScaleOut) ExecuteCmd(cmd, LogCmdOnly) else: # call separate process to do the upscaling VideoRescaling(infile, num, inw, inh, outw, outh, upScaleOut, algo) return upScaleOut
def DownScaling(input, num, inw, inh, outw, outh, path, algo): dnScalOut = GetDownScaledOutFile(input, inw, inh, outw, outh, path, algo) Utils.CmdLogger.write("::Downscaling\n") if (inw == outw and inh == outh): cmd = "copy %s %s" % (input, dnScalOut) ExecuteCmd(cmd, LogCmdOnly) else: # call separate process to do the downscaling VideoRescaling(input, num, inw, inh, outw, outh, dnScalOut, algo) return dnScalOut
def RescaleWithHDRTool(clip, outw, outh, algo, outfile, num, cfg_path, LogCmdOnly=False): cfg_file = GenerateCfgFile(clip, outw, outh, algo, outfile, num, cfg_path) args = " -f %s" % cfg_file cmd = HDRConvert + args ExecuteCmd(cmd, LogCmdOnly)
def CalculateDownScaledMD5(clip, dnw, dnh, path, algo, LogCmdOnly): dnScaleMD5 = GetDownScaledMD5File(clip, dnw, dnh, path, algo) if LogCmdOnly == 1: if Platform == "Linux": cmd = "md5sum %s &> %s" % (clip.file_path, dnScaleMD5) ExecuteCmd(cmd, 1) else: f = open(dnScaleMD5, 'wt') dnScaledOut = GetDownScaledOutFile(clip, dnw, dnh, path, algo) MD5 = md5(dnScaledOut) f.write(MD5) f.close()
def EncodeWithAOM_AV1(infile, QP, framenum, framerate, width, height, outfile, preset): args = " --verbose --codec=av1 -v --psnr --ivf --frame-parallel=0 --cpu-used=%s" \ " --limit=%d --auto-alt-ref=1 --passes=1 --end-usage=q --i420" \ " --min-gf-interval=16 --max-gf-interval=16 --gf-min-pyr-height=4 " \ " --gf-max-pyr-height=4 --threads=1 --lag-in-frames=19 --end-usage=q " \ " --kf-min-dist=65 --kf-max-dist=65 --use-fixed-qp-offsets=1 --deltaq-mode=0 " \ " --enable-tpl-model=0 --enable-keyframe-filtering=0 " \ " --fps=60/1 --input-bit-depth=8 --qp=%d -w %d -h %d -o %s %s"\ % (preset, framenum, 4*QP, width, height, outfile, infile) cmd = AOMENC + args ExecuteCmd(cmd, LogCmdOnly)
def UpScaling(clip, num, outw, outh, path, cfg_path, algo, LogCmdOnly=False): upScaleOut = GetUpScaledOutFile(clip, outw, outh, algo, path) Utils.CmdLogger.write("::Upscaling\n") if (clip.width == outw and clip.height == outh): if Platform == "Windows": cmd = "copy %s %s" % (clip.file_path, upScaleOut) else: cmd = "cp %s %s" % (clip.file_path, upScaleOut) ExecuteCmd(cmd, LogCmdOnly) else: # call separate process to do the upscaling VideoRescaling(clip, num, outw, outh, upScaleOut, algo, cfg_path, LogCmdOnly) return upScaleOut
def VMAF_CalQualityMetrics(origfile, recfile, fmt, num, w, h, bit_depth, logfilePath, LogCmdOnly=False): vmaf_log = GetVMAFLogFile(recfile, logfilePath) args = " -r %s -d %s --aom_ctc v1.0 -q --threads 4 -o %s" \ % (origfile, recfile, vmaf_log) cmd = VMAF + args ExecuteCmd(cmd, LogCmdOnly)
def EncodeWithAOM_AV1(clip, test_cfg, QP, framenum, outfile, preset, enc_perf, enc_log, LogCmdOnly=False): args = " --verbose --codec=av1 -v --psnr --obu --frame-parallel=0" \ " --cpu-used=%s --limit=%d --passes=1 --end-usage=q --i%s " \ " --use-fixed-qp-offsets=1 --deltaq-mode=0 " \ " --enable-tpl-model=0 --enable-keyframe-filtering=0 --fps=%d/%d " \ " --input-bit-depth=%d --bit-depth=%d --cq-level=%d -w %d -h %d" \ % (preset, framenum, clip.fmt, clip.fps_num, clip.fps_denom, clip.bit_depth, clip.bit_depth, QP, clip.width, clip.height) # For 4K clip, encode with 2 tile columns using two threads. # --tile-columns value is in log2. if (clip.width >= 3840 and clip.height >= 2160): args += " --tile-columns=1 --threads=2 --row-mt=0 " else: args += " --tile-columns=0 --threads=1 " if test_cfg == "AI" or test_cfg == "STILL": args += " --kf-min-dist=0 --kf-max-dist=0 " elif test_cfg == "RA" or test_cfg == "AS": args += " --min-gf-interval=16 --max-gf-interval=16 --gf-min-pyr-height=4" \ " --gf-max-pyr-height=4 --kf-min-dist=65 --kf-max-dist=65" \ " --lag-in-frames=19 --auto-alt-ref=1 " elif test_cfg == "LD": args += " --kf-min-dist=9999 --kf-max-dist=9999 --lag-in-frames=0" \ " --min-gf-interval=16 --max-gf-interval=16 --gf-min-pyr-height=4 " \ " --gf-max-pyr-height=4 --subgop-config-str=ld " else: print("Unsupported Test Configuration %s" % test_cfg) args += " -o %s %s" % (outfile, clip.file_path) cmd = AOMENC + args + "> %s 2>&1" % enc_log if (EnableTimingInfo): if Platform == "Windows": cmd = "ptime " + cmd + " >%s" % enc_perf elif Platform == "Darwin": cmd = "gtime --verbose --output=%s " % enc_perf + cmd else: cmd = "/usr/bin/time --verbose --output=%s " % enc_perf + cmd ExecuteCmd(cmd, LogCmdOnly)
def DownScaling(clip, num, outw, outh, path, cfg_path, algo, LogCmdOnly=False): dnScaledOut = GetDownScaledOutFile(clip, outw, outh, path, algo) Utils.CmdLogger.write("::Downscaling\n") if (clip.width == outw and clip.height == outh): if Platform == "Windows": cmd = "copy %s %s" % (clip.file_path, dnScaledOut) else: cmd = "cp %s %s" % (clip.file_path, dnScaledOut) ExecuteCmd(cmd, LogCmdOnly) else: # call separate process to do the downscaling VideoRescaling(clip, num, outw, outh, dnScaledOut, algo, cfg_path, LogCmdOnly) CalculateDownScaledMD5(clip, outw, outh, path, algo, LogCmdOnly) return dnScaledOut
def DecodeWithAOM(test_cfg, infile, outfile, dec_perf, decode_to_yuv, LogCmdOnly=False): if decode_to_yuv: args = " --codec=av1 --summary --rawvideo -o %s %s" % (outfile, infile) else: args = " --codec=av1 --summary -o %s %s" % (outfile, infile) cmd = AOMDEC + args if EnableTimingInfo: if Platform == "Windows": cmd = "ptime " + cmd + " >%s" % dec_perf elif Platform == "Darwin": cmd = "gtime --verbose --output=%s " % dec_perf + cmd else: cmd = "/usr/bin/time --verbose --output=%s " % dec_perf + cmd ExecuteCmd(cmd, LogCmdOnly)
def EncodeWithSVT_AV1(clip, test_cfg, QP, framenum, outfile, preset, enc_perf, enc_log, LogCmdOnly=False): #TODO: update svt parameters args = " --preset %s --scm 2 --lookahead 0 --hierarchical-levels 3 -n %d" \ " --keyint 255 -rc 0 -q %d -w %d -h %d -b %s -i %s"\ % (str(preset), framenum, QP, clip.width, clip.height, outfile, clip.file_path) cmd = SVTAV1 + args + "> %s 2>&1" % enc_log if EnableTimingInfo: if Platform == "Windows": cmd = "ptime " + cmd + " >%s" % enc_perf elif Platform == "Darwin": cmd = "gtime --verbose --output=%s " % enc_perf + cmd else: cmd = "/usr/bin/time --verbose --output=%s " % enc_perf + cmd ExecuteCmd(cmd, LogCmdOnly)
def DecodeWithFfmpeg(infile, outfile): args = " -y -i %s -pix_fmt yuv420p -c:v rawvideo %s" % (infile, outfile) cmd = FFMPEG + args ExecuteCmd(cmd, LogCmdOnly)
def DecodeWithAOM(infile, outfile): args = " --codec=av1 --i420 --rawvideo --summary -o %s %s" % (outfile, infile) cmd = AOMDEC + args ExecuteCmd(cmd, LogCmdOnly)
def VMAF_CalQualityMetrics(origfile, recfile, num, w, h, logfilePath): vmaf_log = GetVMAFLogFile(recfile, logfilePath) args = " yuv420p %d %d %s %s %s --log %s --psnr --ssim --ms-ssim "\ % (w, h, origfile, recfile, Model_Pkg_File, vmaf_log) cmd = VMAF + args ExecuteCmd(cmd, LogCmdOnly)