From subsecret
Jump to: navigation, search

Transcoding with VLC

VLC while mainly being known for being a good video player, can also be used as a tool for transcoding. Since it has good support for most formats, it is a good choice when wanting a powerful and yet relatively simple transcoder.

It is possible to both do transcoding from commandline and from the graphical user interface. However the graphical user interface lacks many options (ie. cropping), and the commanline options are not build in a standardized way. This guide will give some very useful commands for transcoding with VLC through commandline.

VLC comes with 2 executables, vlc and cvlc. both accept the same options, but when using cvlc the GUI will not be launched. This is very useful when transcoding on a remote machine without access to a desktop.

Commands

Example command:

vlc "/path/to/input.vob" --sout='#transcode{vcodec=VP80,vb=5000,acodec=vorbis,ab=128,channels=2}:std{access=file,mux="ffmpeg{mux=webm}",dst="/path/to/output.webm"}'


Codec options:

  • vcodec is the video codec used, in this case VP80 (webm). vb is the video bitrate set to 5000 bit/sec
  • acodec is the audio codec used, in this case vorbis. ab is the audio bitrate set to 128 bit/sec. 2 channels for stereo sound
  • mux is set to webm (webm required VB80 as video codec and vorbis as audio codec)
  • No video filters are used in this example

Cropping

When encoding a video that contains a black frame around it, it is very useful to peel away the black frame and only leave the actual image-part behind. This can be done by cropping the video. First it is however necessary to know what part to crop away

Find area to be cropped with VLC graphical user interface

  • Play the video you want to encode. Click the "Show extended settings" icon, left to the playlist button. In the popup select "Video Effects" and "Crop". Now you can visually inspect the best values for cropping.
  • Note: When encoding a video, the width and height needs to be divisible by 16. So the Left+Right cropped pixels should add up to a number that can be divided by 16. The same for Top+Bottom.

If you find that right side should be cropped by 18 and left by 10. 18+10 = 28. So you neeed to either crop by 4 pixels more or 12 pixels less.
VLCExtendedSettings.png

Find area to be cropped with mplayers cropdetect

The video player mplayer has a crop-detect features. Run the video from the commandline with cropdetect:

mplayer /path/to/input.vob -vf cropdetect

Browse the video till you find a place representative of the area needing to be cropped. Now quit mplayer and see what is writting in the console:

[CROP] Crop area: X: 30..689  Y: 83..492  (-vf crop=656:400:32:88).

mplayer unfortunately uses a different crop format than VLC. To convert you will need to look at the very first ouput of mplayer: The video format:

VIDEO:  MPEG2  720x576  (aspect 2)  25.000 fps  8000.0 kbps (1000.0 kbyte/s)

So the crop area is Left: 30 Right: 720 - 689 = 31 Top: 83 Bottom: 576 - 492 = 84 Again Left+Right and Top+Bottom has to be divisible by 16.

Cropping during transcoding

After specificing vb, add the values for TOP, LEFT, RIGHT and BOTTOM

vfilter=croppadd{cropleft=LEFT,croptop=TOP,cropright=RIGHT,cropbottom=BOTTOM}

ie.

vfilter=croppadd{cropleft=16,croptop=16,cropright=16,cropbottom=16}

The command will now look like:

vlc "/path/to/input.vob" --sout='#transcode{vcodec=VP80,vb=5000,vfilter=croppadd{cropleft=16,croptop=16,cropright=16,cropbottom=16},acodec=vorbis,ab=128,channels=2}:std{access=file,mux="ffmpeg{mux=webm}",dst="/path/to/output.webm"}'

Deinterlacing

Some videoes are interlaced. When things in the video are moving left or right this can be seen as jagged lines. An example can be seen here: http://justsayyes.files.wordpress.com/2007/06/interlace1.jpg VLC comes with filters that can deinterlace the video. The simplest way is to simply add deinterlace to the video options.

vlc "/path/to/input.vob" --sout='#transcode{vcodec=VP80,vb=5000,deinterlace,acodec=vorbis,ab=128,channels=2}:std{access=file,mux="ffmpeg{mux=webm}",dst="/path/to/output.webm"}'

This will use the default "blend" deinterlace mode. Many favors the Yadif (2x) deinterlace mode. To use this you need to also add --sout-deinterlace-mode=yadif2x

vlc "/path/to/input.vob" --sout-deinterlace-mode=yadif2x --sout='#transcode{vcodec=VP80,vb=5000,deinterlace,acodec=vorbis,ab=128,channels=2}:std{access=file,mux="ffmpeg{mux=webm}",dst="/path/to/output.webm"}'

Two-pass encoding with h264 / x264

Unfortunately VLC has not implemented two-pass encoding support for webm. h264 codec has to be used. Two-pass has the advantage of using the bitrate better by using more bits on hard parts and fewer on easy parts. Here is an example of two-pass encoding with h264

#First pass. Put stats in stats.log file
vlc test.avi --sout-x264-stats=stats.log --sout-x264-pass=1 --sout-deinterlace-mode=yadif2x --sout='#transcode{vcodec=h264,vb=5000,deinterlace,acodec=mp3,ab=128,channels=2}:std{access=file,mux=mp4,dst="test-encoded.mp4"}' vlc://quit 
#Second pass. Use stats.log file for better encoding and replace original encoded file with new one
vlc test.avi --sout-x264-stats=stats.log --sout-x264-pass=2 --sout-deinterlace-mode=yadif2x --sout='#transcode{vcodec=h264,vb=5000,deinterlace,acodec=mp3,ab=128,channels=2}:std{access=file,mux=mp4,dst="test-encoded.mp4"}' vlc://quit 

Adding vlc://quit will make VLC quit after it has finished the transcoding

Other

Disable audio on video by setting acodec=none