x264 CRF bequem gescriptet

Dieser Artikel ist komplett veraltet. Es gibt inzwischen eine ganze Reihe von Helferskripten, die ihre eigenen Kapitel erhalten haben.

Seit es das Preset/Tuning-System gibt, ist x264 an sich ja schon hübsch und bequem bedienbar. Naja … fast. Ihr kennt das sicher: Eine Logdatei will man haben und x264 64bit verwenden. Aber mal braucht man AviSynth für intensiveres Filtern und muss dann über Avs2yuv pipen, mal reicht ein simpler Crop und AviSynth/Avs2yuv ist unnötiger Balast.

Das artet sehr schnell in mühsame Tipparbeit aus – und wer will sich schon die Syntax mit den ganzen Pipes und Stream-Umleitungen merken. Deswegen habe ich mir nach und nach ein Python-Skript gebastelt, das alle Varianten abdeckt. Im Idealfall reicht dann ein

venc Quelldatei

fürs 1-Pass-CRF-Encoding incl. Logdatei. Wer das genauso nützlich findet wie ich, sollte einen Blick ans Ende dieses Beitrags wagen. ;-)

Das venc-Skript läuft mit Python 3.2 (oder neuer; ältere 3.x könnten klappen, 2.x nicht) unter Windows. Außerdem nötig sind x264, MuldeR’s Logger, evtl. Avs2yuv und evtl. ein installiertes AviSynth. Standardmäßig wird davon ausgegangen, dass die 32bit-Version von x264 x264.exe heißt, die 64bit-Version x264_x64.exe. Die Aufrufe der Tools und x264-Standardoptionen könnt ihr am Anfang der Skriptdatei im Abschnitt User config anpassen.

Wenn die Quelldatei ein AviSynth-Skript ist, nutzt venc unter 64bit-Windows automatisch den Weg

Quelle.avs ⇒ AviSynth 32bit ⇒ Avs2yuv ⇒ x264 64bit ⇒ Ziel

oder bei anderen Quellformaten direkt

Quelle ⇒ x264 64bit ⇒ Ziel.

Unter 32bit-Windows wird natürlich 32bit x264 verwendet und der Umweg über Avs2yuv fällt auch automatisch weg. Außerdem legt venc immer eine Logdatei namens encstats.txt an.

Hier ist der komplette venc-Hilfetext:

x264 encoding script v2.0
Encodes video with x264 in 1-pass CRF mode. Logs information about x264 version,
encoding configuration and x264’s info output to encstats.txt.

Usage: venc [--mkv|--mp4|--264] infile [sar] [crf] [more options]
Example: venc --mp4 "D:Video filesSource.avs" 16:11 19 --preset fast

The order of the parameters is important!
Only the [more options] section is passed to x264 as is.

Output formats
Can be omitted (defaults to .mkv) or one of the following:
--mkv Matroska container
--mp4 MP4 container
--264 raw H.264 stream

infile
AviSynth script or any other valid x264 input file.
On 64bit Windows if infile is an avs script 64bit x264 via avs2yuv is used
by default. Call the script as venc32 to force usage of x264 32bit.
If infile is not an avs script 64bit x264 is used automatically.
On 32bit Windows obviously 64bit is never used.

The output file is created in the same folder as infile with "-ENCODED" added
to its name. Existing output files are overwritten.

The three x264 config sections are optional. But if you specify one of them
you must specifiy all preceding ones as well.

[sar]
Pixel aspect ratio in x264 compatible notation. Defaults to 1:1.

[crf]
CRF quality level. Defaults to 20.

[more options]
Additional x264 options. Defaults to:
--preset slow --tune film
Do not use this section to override CRF or SAR!

Ich hoffe, der eine oder andere kann etwas mit dem Skript anfangen. Wenn Fragen auftauchen, einfach einen Kommentar posten.

Damit man venc tatsächlich einfach mit venc aufrufen kann anstatt venc.py, muss man Windows pythonisieren. Systemsteuerung › System › Erweiterte Systemeinstellungen › Umgebungsvariablen: Dort unter Systemvariablen die Variable PATHEXT bearbeiten und .py als neue Endung hinzufügen. Ab/anmelden bzw. Neustart dürfte nötig sein.

Download: venc.py 2.0 (Veraltet! Siehe Hinweis am Artikelanfang.)

Kommentare