From 31ba6cf2f64ee2046fbee7d57a84c09f591ba82f Mon Sep 17 00:00:00 2001 From: Javanaut Date: Sat, 21 Oct 2023 10:21:16 +0200 Subject: [PATCH] refine quality test --- bin/ffx.py | 106 +++++++++++++++++++++++++---------------------------- 1 file changed, 50 insertions(+), 56 deletions(-) diff --git a/bin/ffx.py b/bin/ffx.py index 265d612..b9ab471 100755 --- a/bin/ffx.py +++ b/bin/ffx.py @@ -38,14 +38,16 @@ def generateVP9Pass2Tokens(q): '-frame-parallel', '0', '-g', '9999', '-aq-mode', '0', '-auto-alt-ref', '1', '-lag-in-frames', '25'] +def generateCropTokens(start, length): -def generateOutputTokens(f): - return ['-f', 'webm', f] - -def generateTestOutputTokens(f, q): - fTokens = f.split('.') - return ['-f', 'webm', fTokens[:-1] + [f" q{q}"] + fTokens[-1]] + return ['-ss', str(start), '-t', str(length)] +def generateOutputTokens(f, q=''): + if q: + fTokens = f.split('.') + return ['-f', 'webm', fTokens[:-1] + [f" q{q}"] + fTokens[-1]] + else: + return ['-f', 'webm', f] inputFilename = sys.argv[1] @@ -58,18 +60,12 @@ if 'vp9' in sys.argv: targetFormat = 'vp9' -testQualities = [] -testTokens = [q for q in sys.argv if q.startswith('test=')] -if testTokens: - qualitiesString = testTokens[0].split('=')[1] +qualities = [DEFAULT_QUALITY] +qualitiesTokens = [q for q in sys.argv if q.startswith('q=')] +if qualitiesTokens: + qualitiesString = qualitiesTokens[0].split('=')[1] testQualities = qualitiesString.split(',') - -quality = DEFAULT_QUALITY -qualityTokens = [q for q in sys.argv if q.startswith('q=')] -if qualityTokens: - quality = int(qualityTokens[0].split('=')[1]) - preset = DEFAULT_AV1_PRESET presetTokens = [p for p in sys.argv if p.startswith('p=')] if presetTokens: @@ -96,6 +92,13 @@ if dtsTokens: if not dtsBandwidth.endswith('k'): dtsBandwidth += "k" +cropStart = -1 +cropLength = -1 +cropTokens = [c for c in sys.argv if c.startswith('crop=')] +if cropTokens: + cropString = cropTokens[0].split('=')[1] + cropStart, cropLength = cropString.split(',') + output = executeProcess(["ffprobe", "-show_streams", "-of", "json" ,inputFilename]) @@ -150,65 +153,56 @@ for aStream in audioStreams: audioStreamIndex += 1 - -outputTokens = ['-f', 'webm', outputFilename] - nullTokens = ['-f', 'null', '/dev/null'] -testTokens = ['-ss', '60', '-t', '180'] - - +for quality in qualities: + if targetFormat == 'av1': -if testQualities: + commandSequence = commandTokens + mappingTokens + generateAV1Tokens(quality, preset) + audioTokens - for testQ in testQualities: + if len(qualities) > 1: + commandSequence += generateOutputTokens(outputFilename, quality) + else: + commandSequence += generateOutputTokens(outputFilename) + + if cropStart > -1: + commandSequence += generateCropTokens(cropStart, cropLength) - if targetFormat == 'av1': - commandSequence = commandTokens + mappingTokens + generateAV1Tokens(testQ, preset) + audioTokens + testTokens + generateTestOutputTokens(outputFilename, testQ) - - print(f"Command Sequence: {commandSequence}") + print(f"Command Sequence: {commandSequence}") - executeProcess(commandSequence) + executeProcess(commandSequence) - if targetFormat == 'vp9': + if targetFormat == 'vp9': - commandSequence1 = commandTokens + generateVP9Pass1Tokens(testQ) + testTokens + nullTokens - - print(f"Command Sequence 1: {commandSequence1}") - - executeProcess(commandSequence1) - - commandSequence2 = commandTokens + mappingTokens + generateVP9Pass2Tokens(testQ) + audioTokens + testTokens + generateTestOutputTokens(outputFilename, testQ) - - print(f"Command Sequence 2: {commandSequence2}") - - executeProcess(commandSequence2) + commandSequence1 = commandTokens + generateVP9Pass1Tokens(quality) + nullTokens -else: + if cropStart > -1: + commandSequence += generateCropTokens(cropStart, cropLength) + - if targetFormat == 'av1': - - commandSequence = commandTokens + mappingTokens + generateAV1Tokens(quality, preset) + audioTokens + generateOutputTokens(outputFilename) - - print(f"Command Sequence: {commandSequence}") - - executeProcess(commandSequence) - - if targetFormat == 'vp9': - - commandSequence1 = commandTokens + generateVP9Pass1Tokens(quality) + audioTokens + nullTokens - print(f"Command Sequence 1: {commandSequence1}") executeProcess(commandSequence1) - commandSequence2 = commandTokens + mappingTokens + generateVP9Pass2Tokens(quality) + audioTokens + generateOutputTokens(outputFilename) - + commandSequence2 = commandTokens + mappingTokens + generateVP9Pass2Tokens(quality) + audioTokens + + + if cropStart > -1: + commandSequence += generateCropTokens(cropStart, cropLength) + + + if len(qualities) > 1: + commandSequence2 += generateOutputTokens(outputFilename, quality) + else: + commandSequence2 += generateOutputTokens(outputFilename) + + print(f"Command Sequence 2: {commandSequence2}") executeProcess(commandSequence2) +