[FFmpeg-user] XVID-Encoding with ffmpeg

Francois Visagie francois.visagie at gmail.com
Tue Mar 5 12:53:53 CET 2013


> -----Original Message-----
> From: ffmpeg-user-bounces at ffmpeg.org [mailto:ffmpeg-user-
> bounces at ffmpeg.org] On Behalf Of llarevo at gmx.net
> Sent: 05 March 2013 12:30
> To: FFmpeg user questions
> Subject: Re: [FFmpeg-user] XVID-Encoding with ffmpeg
> 
> Hi,
> 
> > > > > I would like to migrate from mencoder to ffmpeg, but I can't
> > > > > find sufficient information how to "translate" the parameters
> > > > > for encoding with xvid from the mencoder commandline to a
> > > > > sufficient ffmpeg commandline.
> > > >
> > > > I don't think there is an "encopts" option in ffmpeg. You will
> > > > need to translate all the xvid options to ffmpeg options.
> > > OK, I thought so.
> > >
> > > > > The xvidenc-configuration in mencoder is
> > > > >
> > > > > -xvidencopts
> > > > >
> > >
> pass=1:profile=dxnhtpal:(no)greyscale:me_quality=6:max_bframes=1:noq
> > > p
> > > el:nogmc:(no)cartoon:quant_type=mpeg:trellis:(no)interlacing:chroma_
> > > me:c
> > > hroma_opt:vhq=4
> > > >
> > > > For example, -pass 1 -bf 1 and so on.
> > > OK, I found these already, but not all of them.
> > >
> > > > >
> > > > > The most important part for me is profile=dxhtnpal because this
> > setting
> > > > > ensures a maximum bitrate over 3 sec not over 8 MBit/s, and a
> > > > > avaerage bitrate not higher than around 4,8 MBit/s (cf.
> > > > > http://www.mplayerhq.hu/DOCS/HTML/de/menc-feat-xvid.html)
> > > >
> > > >
> > > > Use the table on
> > > > http://www.mplayerhq.hu/DOCS/HTML/de/menc-feat-
> xvid.html#menc-
> > > feat-xvid-encoding-profiles
> > > > to help you translate it.
> > > I know that site. My problem is, that I don't find some options from
> > > the mplayer site in the ffmpeg man pages or ffmpeg-documentation.
> > >
> > > So my concrete question is: what is ffmpeg-syntax-equivalent for
> > >
> > > profile=htdxnpal
> > > me_quality=6
> > > quant_type=mpeg
> > > trellis
> > > interlacing
> > > chroma_me
> > > chroma_opt
> > > vhq=4
> > >
> > > Additional questions are:
> > >
> > > Where should I look for the syntax of these parameters?
> >
> > If ffmpeg's MPEG-2 and MPEG-4 syntax is similar or the same, some work
> > I did a while ago translating my mencoder MPEG-2 command line to
> > ffmpeg might be of use. Let me know if you want to have a look at it.
> 
> Any help is very appreciated. So if it is not to much effort, I would be
> interested in your command line. I'm new to ffmpeg, and I have also mpeg2-
> tasks to migrate from mencoder to ffmpeg.

Below the Windows batch file I use. What you should look out for:
* "REM MEncoder reference command line" - the mencoder command line I was
using at the time, i.e. the starting point of the translation
* "REM Reference command line" - the ffmpeg command line with options
translated as best I could
* The (uncommented) actual command line contains a couple of preference
changes since which probably won't interest you
* "rem Undocumented" - this section lists options I could not definitively
translate from documentation or command line help and enquired about on the
forum

You'll notice I haven't yet made the time to try replace some of the options
with presets ;-).

[CODE]
@echo off
setlocal

goto INIT

:HELP
echo.
echo ffmpegencode v1.8 (c) F. Visagie 2013/02/27
echo Function: encode PAL DV to DVD-compliant MPEG-2
echo.
echo Usage:
echo ffmpegencode "infile" [bitrate [aspect_ratio]] ["subsfile"]]] [pass]]]]
echo.
echo where:
echo 	"infile"	video file to encode
echo 	bitrate		set video bitrate in bits/s (default %BITRATE%, max
%MAXRATE%)
echo 	aspect_ratio	set new DISPLAY aspect ratio in W:H or 1.nnn format
(default unchanged)
echo 	"subsfile"	ASS text script with inlay subtitles
echo 	pass		nothing for uninterrupted 2-pass encoding
echo 			1 for pass 1 only
echo 			2 for pass 2 only
echo.
echo 	All value parameters accept 0 to indicate default/none
echo 	To ensure correct processing, double-quote space-separated filenames
echo 	Encoded output file is named infile%SUFFIX%
echo.
echo 	To display commands instead of executing for debugging purposes,
echo 	set external environment variable FFMPDBUG=echo, otherwise EMPTY

goto ERRPAUSE

rem Version History
rem v1.1 2009/05/20:	Added separate pass 1/2 support
rem v1.2 2009/05/20:	Removed Avisynth input for r19192 & later
rem v1.3 2009/09/04:	Restored Avisynth input for subtitle inlays
rem v1.4 2010/04/27:	Explicitly require quoted filenames, esp. for adding
subtitles
rem v1.5 2012/08/14:	Updated for ffmpeg version N-43418-g633b90c
rem			Added bitrate parameter
rem			Added copyright tag
rem 			Added DEBUG flag
rem v1.6 2012/08/24:	Changed DEBUG flag to external environment variable
FFMPDBUG
rem 			Removed built-in denoising
rem v1.7 2012/10/28:	Use environment variables to get date and time
instead of using commands
rem v1.8 2013/02/27:	Added aspect ratio support

:INIT
rem Default encode settings
rem -----------------------

rem Production bitrates
set BITRATE=6090000
set MAXRATE=9000000
set MUXRATE=10080000

rem Bitrates for testing
rem Following bitrate causes buffer underflow and MuxMan P-STD buffer
underflow (with -maxrate 9800000)
rem set BITRATE=9000000
rem set MAXRATE=9800000
rem Following muxrate leaves enough room for audio and triggers buffer
underflow for illegal video
rem set MUXRATE=9928000

set ASPECT=
set SUBSFILE=
set PASSOPT=

set PSNR=
rem set PSNR=-psnr
set SUFFIX=.mpg
set METADATA=-metadata copyright="Encode (c) Francois Visagie
francois.visagie at gmail.com"
set INPUT=

REM Parse input file
if [%1] == [] goto HELP
if [%1] == [?] goto HELP
if [%1] == [-?] goto HELP
if [%1] == [/?] goto HELP
if [%1] == [h] goto HELP
if [%1] == [-h] goto HELP
if [%1] == [/h] goto HELP
if [%1] == [help] goto HELP
if [%1] == [-help] goto HELP
if [%1] == [/help] goto HELP

rem Preserve input filename
set INPUT=%1

if exist %1. goto QUOTIN
echo.
echo Invalid input file %1!
echo HINT: If it contains spaces, enclose input filename in quotes

:ERRPAUSE
echo 

echo.
pause
goto EXIT

:QUOTIN
rem Ensure input file name quoted

echo %INPUT% | find """" > NUL
if not errorlevel 1 goto CHKBIT
set INPUT="%INPUT%"

:CHKBIT
if [%2] == [] goto CHKOUT
if [%2] == [0] goto CHKASPCT
set BITRATE=%2

:CHKASPCT
if [%3] == [] goto CHKOUT
if [%3] == [0] goto CHKSUBS
echo %3 | find ":" > NUL
if not errorlevel 1 goto SETASP
echo %3 | find "." > NUL
if not errorlevel 1 goto SETASP

echo.
echo Invalid aspect ratio %3!
goto ERRPAUSE

:SETASP
set ASPECT=-aspect %3

:CHKSUBS
if [%4] == [] goto CHKOUT
if [%4] == [0] goto CHKPASS
if exist %4. goto QUOTSUBS
echo.
echo Invalid subtitle file %4!
echo HINT: If it contains spaces, enclose subtitle filename in quotes
goto ERRPAUSE

:QUOTSUBS
rem Ensure subtitle file name quoted

set SUBSFILE=%4
echo %SUBSFILE% | find """" > NUL
if not errorlevel 1 goto CHKPASS
set SUBSFILE="%SUBSFILE%"

:CHKPASS
if [%5] == [] goto CHKOUT
if [%5] == [1] goto SETPASS1
if [%5] == [2] goto SETPASS2
echo.
echo Invalid pass number %5!
goto ERRPAUSE

:SETPASS1
set PASSOPT=1
goto CHKOUT
:SETPASS2
set PASSOPT=2

:CHKOUT
rem Now we're committed and may over-write output file
set OUTPUT=%INPUT%%SUFFIX%
if not exist %OUTPUT%. goto MAIN
echo 

echo.
echo %OUTPUT% already exists!
echo Press Ctrl-C to abort, else
echo.
pause
goto MAIN

:MISSFILE
set MISSMESG=Missing pass 1 file (ffmpeg2pass-?.log
if not [%SUBSFILE%] == [] set MISSMESG=%MISSMESG% or %AVSCRIPT%
set MISSMESG=%MISSMESG%)!
echo.
echo %MISSMESG%
goto ERRPAUSE


:MAIN

set FFINPUT=%INPUT%
rem Use distinct variable for AVS script to protect input file from
accidental deletion
set AVSCRIPT=

if [%SUBSFILE%] == [] goto CHKPASS#
set FFINPUT=%INPUT%.AVS
set AVSCRIPT=%FFINPUT%

:CHKPASS#
if [%PASSOPT%] == [2] goto ENDPASS

set PASS=1
set VB_STRAT=-b_strategy 1
if not [%FFMPDBUG%] == [echo] if exist ffmpeg2pass-?.log del
ffmpeg2pass-?.log

if [%SUBSFILE%] == [] goto LOGSTART
echo OpenDMLSource(%INPUT%)>%AVSCRIPT%
echo TextSub(%SUBSFILE%)>>%AVSCRIPT%

if not [%FFMPDBUG%] == [echo] goto LOGSTART
echo.
echo %AVSCRIPT%:
echo.
type %AVSCRIPT%
echo.
del %AVSCRIPT%

:LOGSTART
if [%FFMPDBUG%] == [echo] goto ENCODE
echo Start %INPUT% >%OUTPUT%.time.txt
:BEGNPASS
if [%FFMPDBUG%] == [echo] goto ENCODE
echo Start pass %PASS% >>%OUTPUT%.time.txt
echo The current date is: %DATE% >>%OUTPUT%.time.txt
echo The current time is: %TIME% >>%OUTPUT%.time.txt

:ENCODE
REM MEncoder reference command line
rem mencoder -field-dominance 1 -mc 0 -vf hqdn3d=2:1:2,harddup -oac lavc
-ovc lavc -lavcopts
abitrate=128:acodec=ac3:autoaspect:ilme:ildct:keyint=15:mbd=2:top=0:trell:vb
itrate=%BITRATE%:vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vstric
t=0%PSNR%:vmax_b_frames=2%VB_STRAT%:dia=2:preme=2:predia=2:mbcmp=6:precmp=2:
cmp=2:subcmp=6:last_pred=2:mv0:mv0_threshold=0 -of mpeg -mpegopts
format=dvd:muxrate=%MUXRATE%:tsaf %1 -o %OUTPUT% >%OUTPUT%.%PASS%.txt

REM Reference command line
rem ffmpeg -y -top 0 -async 0 -nr 20 -i %FFINPUT% -aspect 4:3 -target
pal-dvd -muxrate %MUXRATE% -acodec ac3 -ab 128000 -flags ildct+ilme+mv0 -g
15 -mbd 2 -trellis 1 -bufsize 1835000 -strict 0 -bf 2 %VB_STRAT% -mbcmp 6
-preme 2 -precmp 2 -pre_dia_size 2 -cmp 2 -dia_size 2 -subcmp 6 -last_pred 2
-mv0_threshold 0 %PSNR% -maxrate %MAXRATE% -vcodec mpeg2video -b:v %BITRATE%
-pass %PASS% %METADATA% %OUTPUT%
REM Fast test encode
rem ffmpeg -y -i %FFINPUT% -target pal-dvd -acodec ac3 -ab 128000 -flags
ildct+ilme -maxrate %MAXRATE% -vcodec mpeg2video -b:v %BITRATE% -pass %PASS%
%OUTPUT%

%FFMPDBUG% ffmpeg -y -top 0 -async 0 -i %FFINPUT% %ASPECT% -target pal-dvd
-muxrate %MUXRATE% -acodec ac3 -ab 128000 -flags ildct+ilme+mv0 -g 15 -mbd 2
-trellis 1 -bufsize 1835000 -strict 0 -bf 2 %VB_STRAT% -mbcmp 6 -preme 2
-precmp 2 -pre_dia_size 2 -cmp 2 -dia_size 2 -subcmp 6 -last_pred 2
-mv0_threshold 0 %PSNR% -maxrate %MAXRATE% -vcodec mpeg2video -b:v %BITRATE%
-pass %PASS% %METADATA% %OUTPUT%

if [%FFMPDBUG%] == [echo] goto CHKEND
echo End pass %PASS% >>%OUTPUT%.time.txt
echo The current date is: %DATE% >>%OUTPUT%.time.txt
echo The current time is: %TIME% >>%OUTPUT%.time.txt

:CHKEND
if %PASS% == 2 goto END
if [%PASSOPT%] == [1] goto END
:ENDPASS
if not [%FFMPDBUG%] == [echo] if not exist ffmpeg2pass-?.log goto MISSFILE
if not [%FFMPDBUG%] == [echo] if not [%SUBSFILE%] == [] if not exist
%AVSCRIPT%. goto MISSFILE
set PASS=2
set VB_STRAT=
goto BEGNPASS


:END
echo 

rem pause

if [%PASSOPT%] == [1] goto EXIT
if exist ffmpeg2pass-?.log del ffmpeg2pass-?.log
if not [%SUBSFILE%] == [] if exist %AVSCRIPT%. del %AVSCRIPT%

:EXIT
set BITRATE=
set MAXRATE=
set MUXRATE=
set ASPECT=
set SUBSFILE=
set PASSOPT=
set PSNR=
set SUFFIX=
set METADATA=
set INPUT=
set OUTPUT=
set MISSMESG=
set FFINPUT=
set AVSCRIPT=
set PASS=
set VB_STRAT=
endlocal

rem Undocumented
rem ------------
rem -vsync parameter					queried: no response
rem -nr parameter					queried: -nr 600 max
rem -ilme {parameter?}					-flags ilme seems to
work
rem -flags syntax					+ (at least between
flags)
rem existence of keyframe interval specification?	-g 15
rem -trellis parameter					queried: 0 no
trellis, 1 trellis 
[/CODE]

> 
> Thank You!
> --
> Felix
> 
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user



More information about the ffmpeg-user mailing list