Converting ffmpeg options to x264 equivalents
Posted: 03 Jun 2017 01:29
Hello. I'm looking to switch from ffmpeg to x264 as my video encoder (since I'm already using libx264, it seems a natural jump). I believe I've found most of what I need already, but I'm missing two options - an equivalent for '+full_chroma_inp', and an equivalent for forcing a keyframe at 00:00:00.000. I also would like to know if there's an equivalent to the ffmpeg shortcuts in the scale filter (input width, input height, and maintain aspect ratio), or if I'll need to use some tricky variable juggling.
As far as the scaler question goes, it may end up being irrelevant but I would still like to know if it can be done wholly in the encoder. If I have to use pointresize in avisynth then I'll use avisynth for scaling (and the end goal involves helping a bunch of people migrate from standard avisynth to an x64 compatible fork anyway - they already use x264 for their encoding and want to migrate from x86 to x64 builds, but they use Avisynth for scaling and cleanup)
The windows batch file I'm starting from is this:
The x264 command with tricky variable juggling is as follows:
As far as the scaler question goes, it may end up being irrelevant but I would still like to know if it can be done wholly in the encoder. If I have to use pointresize in avisynth then I'll use avisynth for scaling (and the end goal involves helping a bunch of people migrate from standard avisynth to an x64 compatible fork anyway - they already use x264 for their encoding and want to migrate from x86 to x64 builds, but they use Avisynth for scaling and cleanup)
The windows batch file I'm starting from is this:
Code: Select all
@echo off
set /p fn="Filename? "
@echo.
set /p src="Source? "
@echo.
set /p scale="Scale value? (common values are 2, 4, 8)"
@echo.
choice /m "Are there subtitles?"
@echo.
IF errorlevel 2 goto Encode
IF errorlevel 1 goto Subtitle
:Subtitle
set /p sub="Subtitle file name? "
goto Subencode
:Encode
cls
ffmpeg -i %src% -sws_flags neighbor+full_chroma_inp -c:v libx264 -crf 20 -bf -1 -b_strategy 2 -force_key_frames 00:00:00.000 -pix_fmt yuv420p -c:a aac -b:a 192k -vf scale=%scale%*iw:-1 %fn%
if errorlevel 1 goto :Fail
@echo ----------------------
@echo Encoding complete.
pause >nul
goto :eof
:Subencode
cls
ffmpeg -i %src% -sws_flags neighbor+full_chroma_inp -c:v libx264 -crf 20 -bf -1 -b_strategy 2 -force_key_frames 00:00:00.000 -pix_fmt yuv420p -c:a aac -b:a 192k -vf subtitles=%sub% -vf scale=%scale%*iw:-1 %fn%
if errorlevel 1 goto :Fail
@echo ----------------------
@echo Encoding complete.
pause >nul
goto :eof
:Fail
@echo ----------------------
@echo Encode failed, please review FFMPEG output.
@echo I will go ahead and delete %fn% for you.
pause >nul
del %fn%
goto :eof
Code: Select all
mediainfo --Inform="Video;%%Width%%" %src% > temp.txt
set /p iw=<temp.txt
set /a iw=%iw%*%scale%
mediainfo --Inform="Video;%%Height%%" %src% > temp.txt
set /p ih=<temp.txt
set /a ih=%ih%*%scale%
goto :Encode
:Encode
cls
x264 --crf 20 --bframes -1 --b-adapt 2 --output-csp i420 --output %fn% --video-filter resize:%iw%,%ih%,1:1:point %src%