sabooky
5th June 2007, 21:29
Theres a lot of times where I have a target PSNR in mind, but have no clue what bitrate/quant settings will get me there. So I wrote this script to guess the settings needed by encoding some parts of the video file.
Using this script is very simple:
psnrencode.py [MENCODER OPTIONS] [FILE] [TARGET PSNR]
MENCODER OPTIONS: exclude -o and crf, bitrate, fixed_quant options. -profile is supported, only xvid/x264.
FILE : File you want to encode
Target PSNR : whatever your target psnr is...ex 44
Example:
lets say we want to encode the video using `mencoder -oac copy -ovc xvid -xvidencopts fixed_quant=2.00:chroma_opt:autoaspect title1.vob -o title1.avi`
We want to have a target PSNR of around 44. However we don't know what fixed_quant/bitrate will get us there.
simply run: `psnrencode.py -oac copy -ovc xvid -xvidencopts chroma_opt:autoaspect title1.vob 44` (you can exclude -oac, if you don't its ignored anyways)
Output Example:
using the the options from the last section, here's the output.
$ ./psnrencode.py -oac copy -ovc xvid -xvidencopts chroma_opt:autoaspect title1.vob 44
Pass (1/2):
46.17...46.5...46.94...45.15...46.26...45.98...44.45...45.63...47.02...43.79...46.01...46.32...47.19...47.62...47.92...45.88...47.22...47.25...
fixed_quant: 2.0
avg psnr: 46.2944444444
avg bitrate: 2469.44555556
Pass (2/2):
41.83...43.27...43.06...41.17...41.72...41.69...40.74...41.03...43.97...41.05...43.27...42.8...44.18...44.51...44.44...42.48...44.2...44.2...
fixed_quant: 4.0
avg psnr: 42.7561111111
avg bitrate: 1199.72738889
fixed_quant: 3.3
Should yield
PSNR guess:44.000
Would you like to test for bitrate (this will do another pass)? [Y/n]: y
43.29...44.39...44.53...42.82...43.65...43.33...41.87...42.88...44.98...41.68...43.95...43.91...45.09...45.55...45.7...43.61...45.25...45.23...
fixed_quant: 3.3
avg psnr: 43.9838888889
avg bitrate: 1532.34838889
Encode your video using either fixed_quant=3.3 or bitrate 1532 to get psnr 44
What it does:
Encodes 2% or 3,000 frames (whichever is bigger) of the video file, and gets the average psnr.
Runs a second pass using different crf/fixed_quant values again getting the average psnr.
Calculates the changes between the two passes and gives you its best guess at what will yield you the target psnr.
Optional: Run a third pass using the crf setting, this will give you the bitrate required to reach your goal, will also give you a more detailed guess at the expected output PSNR.
Link: http://pastebin.archlinux.org/3885
Notes:
Python and mencoder are required, also only tested on linux. May or may not run on windows.
YMMV, this script was written using my limited knowledge of python, and even less knowledge of encoding.
The code is very ugly and hard to read atm. However, if this script proves usefull, I'll rewrite and expand on it.
No guarantees, In my limited testing 3-4 videos the worse guess was about .7 psnr off, again YMMV.
If something like this already exists, that sucks. Guess it was a good learning experience then.
If this concept is completely wrong and useless, see previous line.
Using this script is very simple:
psnrencode.py [MENCODER OPTIONS] [FILE] [TARGET PSNR]
MENCODER OPTIONS: exclude -o and crf, bitrate, fixed_quant options. -profile is supported, only xvid/x264.
FILE : File you want to encode
Target PSNR : whatever your target psnr is...ex 44
Example:
lets say we want to encode the video using `mencoder -oac copy -ovc xvid -xvidencopts fixed_quant=2.00:chroma_opt:autoaspect title1.vob -o title1.avi`
We want to have a target PSNR of around 44. However we don't know what fixed_quant/bitrate will get us there.
simply run: `psnrencode.py -oac copy -ovc xvid -xvidencopts chroma_opt:autoaspect title1.vob 44` (you can exclude -oac, if you don't its ignored anyways)
Output Example:
using the the options from the last section, here's the output.
$ ./psnrencode.py -oac copy -ovc xvid -xvidencopts chroma_opt:autoaspect title1.vob 44
Pass (1/2):
46.17...46.5...46.94...45.15...46.26...45.98...44.45...45.63...47.02...43.79...46.01...46.32...47.19...47.62...47.92...45.88...47.22...47.25...
fixed_quant: 2.0
avg psnr: 46.2944444444
avg bitrate: 2469.44555556
Pass (2/2):
41.83...43.27...43.06...41.17...41.72...41.69...40.74...41.03...43.97...41.05...43.27...42.8...44.18...44.51...44.44...42.48...44.2...44.2...
fixed_quant: 4.0
avg psnr: 42.7561111111
avg bitrate: 1199.72738889
fixed_quant: 3.3
Should yield
PSNR guess:44.000
Would you like to test for bitrate (this will do another pass)? [Y/n]: y
43.29...44.39...44.53...42.82...43.65...43.33...41.87...42.88...44.98...41.68...43.95...43.91...45.09...45.55...45.7...43.61...45.25...45.23...
fixed_quant: 3.3
avg psnr: 43.9838888889
avg bitrate: 1532.34838889
Encode your video using either fixed_quant=3.3 or bitrate 1532 to get psnr 44
What it does:
Encodes 2% or 3,000 frames (whichever is bigger) of the video file, and gets the average psnr.
Runs a second pass using different crf/fixed_quant values again getting the average psnr.
Calculates the changes between the two passes and gives you its best guess at what will yield you the target psnr.
Optional: Run a third pass using the crf setting, this will give you the bitrate required to reach your goal, will also give you a more detailed guess at the expected output PSNR.
Link: http://pastebin.archlinux.org/3885
Notes:
Python and mencoder are required, also only tested on linux. May or may not run on windows.
YMMV, this script was written using my limited knowledge of python, and even less knowledge of encoding.
The code is very ugly and hard to read atm. However, if this script proves usefull, I'll rewrite and expand on it.
No guarantees, In my limited testing 3-4 videos the worse guess was about .7 psnr off, again YMMV.
If something like this already exists, that sucks. Guess it was a good learning experience then.
If this concept is completely wrong and useless, see previous line.