From subsecret
Jump to: navigation, search

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.

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