From subsecret
Jump to: navigation, search
Line 1: Line 1:
=Transcoding with VLC=
=Transcoding with VLC=
VLC while mainly 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.  
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.
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.
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=
=Commands=
Example command:
Example command:

Revision as of 13:17, 22 June 2013

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.

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 "yadif2x" 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"}'