Tag Archive for 'mencoder'

Usefull Commands: Video

  • Change the aspect ratio of a film for the playback. Standard aspect ratio are : 1.33 (4:3), 1.66 (1.66:1), 1.77 (16:9) and 2.35 (2.35:1):
    mplayer -aspect 2:1 ./video.avi
    
  • Play the video with subtitles:
    mplayer -sub ./subtitle_file.txt ./video.avi
    
  • This will extract audio track no. 128, downmix the AC3 sound to PCM and write the results to file.wav:
    mplayer -vo null -hardframedrop -aid 128 -ao pcm -aofile file.wav dvd://1
    
  • This will extract the audio, convert it to PCM and write the resulting wave file to audio.wav:
    mplayer -vo null -hardframedrop -ao pcm:file=audio.wav myvideo.avi
    
  • Extract to chapter.txt the chapter file of the track n°1 of the DVD:
    dvdxchap -t 1 /mnt/cdrom > chapter.txt
    
  • Show all subtitles streams:
    mplayer -vo null -ao null -frames 0 -v 2 dvd://1 >&1 | grep sid
    
  • Extract the raw subtitle stream. The -a 0x21 option correspond to the subtitle stream’s hexadecimal number (= 0×20 + id of the stream):
    tccat -i /space/st-tng/dic1/ -T 1 -L | tcextract -x ps1 -t vob -a 0x22 > subs-en
    
  • Create a rotated copy of the file.avi video (rotate=1 : clockwise ; rotate=2 : anti-clockwise):
    mencoder -vop rotate=2 -oac pcm -ovc lavc ./source.avi -o ./dest.avi
    
  • Preview a video composed of all jpeg files from the current folder at 15fps (mplayer only support jpeg, png, tga and sgi formats):
    mplayer "mf://*.jpg" -mf fps=15
    
  • Create a 15fps video from all jpeg files of the current folder:
    mencoder "mf://*.jpg" -mf fps=15 -ovc lavc -o ./dest.avi
    
  • Encode a SVCD to AVI file:
    mencoder -oac lavc -ovc lavc vcd://1 -o ./svcd.avi
    
  • Transcode video to raw format (be carefull: usually the output video got annoying audio delay):
    mencoder -oac pcm -ovc raw -ofps 25 -noskip ./video.wmv -o ./video.avi
    
  • Encode a video using the default mpeg4 codec at 400 kbps for video and mp3 codec at constant 32 kbps bitrate for audio:
    mencoder -oac mp3lame -lameopts cbr:preset=32 -ovc lavc -lavcopts vbitrate=400 in.avi -o out.avi
    
  • Enhance the sharpness of the video:
    mplayer video.avi -vf smartblur=.6:-.5:0,unsharp=l5x5:.8:c5x5:.4
    
  • Merge multiple video into one:
    avimerge -i part1.avi part2.avi -o big-file.avi
    
  • Cut a video to keep the first 5.4 seconds:
    mencoder big-file.avi -ss 0 -endpos 5.4 -ovc copy -oac copy -o cutted.avi
    
  • Cut a video to keep everything exept the first 5.4 seconds:
    mencoder big-file.avi -ss 5.4 -ovc copy -oac copy -o cutted.avi
    
  • Show all mplayer filter list:
    mplayer -vf help
    
  • Get help of a particular filter (eq2 in this example):
    mplayer -vf eq2=help
    
  • Here is the filter I use to light up a video taken in the dark with my cheap camera. Of course it add noise but thanks to this we can distinguish shapes in the dark.
    mencoder -vf eq2=1.61:1.95:0.54:2.43 -oac pcm -ovc lavc video.avi -o bright-vid.avi
    
  • And this is the command to preview the result of the filter used above:
    mplayer video.avi -vf eq2=1.61:1.95:0.54:2.43
    
  • This is how I convert raw videos taken with my digital camera into ISO standard MPEG-4 (DivX 5, XVID compatible) videos [to encode in grayscale, add :gray option to -lavcopts]:
    mencoder source.avi -ovc lavc -oac lavc -ffourcc DX50 -lavcopts vcodec=mpeg4:vbitrate=400:v4mv:mbd=2:trell:autoaspect:dia=2:acodec=mp3:abitrate=32:vpass=1 -vf hqdn3d -o output.avi
    mencoder source.avi -ovc lavc -oac lavc -ffourcc DX50 -lavcopts vcodec=mpeg4:vbitrate=400:v4mv:mbd=2:trell:autoaspect:dia=2:acodec=mp3:abitrate=32:vpass=2 -vf hqdn3d -o output.avi
    
  • Play all videos of the current folder fullscreen at 4x speed with 50% more brightness:
    mplayer -speed 4 -brightness 50 -fs ./*.avi
    
  • Extract audio stream from a video:
    mplayer -dumpaudio -dumpfile audio.ac3 video_source.mpg
    
  • Here are some commands to get informations about the nature of a video:
    mplayer -frames 0 -identify ./video.avi
    tcprobe -i ./video.avi
    ffmpeg -i ./video.avi
    file ./video.avi
    
  • Test XV video driver output via gstreamer v0.10:
    gst-launch-0.10 videotestsrc ! xvimagesink
    

A/V sync problems: VLC better than Mencoder

Today I tried to transcode a bunch of videos using my favorite script. I need to do this because the videos produced with my cheap camera use Mjpeg as video codec and raw-data as audio codec. This result of incredible large files. To share my videos with friends, I transcode them to mpeg4/mp3 files. This is all the dirty work my script is supposed to handle.

Unfortunately I didn’t use it since I upgraded Mandriva from 2005 to the 2006 release. As you can guess, it wasn’t working: mencoder gave me the following “Audio LAVC, couldn’t find encoder for codec mp3″ error message. First, I though it was because of a bad version of ffmpeg. Looking at the source RPM from PLF repository gave me the proof that my version was compiled with the right options.

To bypass this problems, I used the -mp3lame as output audio codec. This introduced horrible A/V sync. :( For 3 hours, I tried to play with mencoder options without success. I was completetly desesperated… until I tried VLC. In less than 10 minutes I was able to get the expected result: perfect A/V sync movie file !

Thanks to the VLC wiki, I also discovered the h264 video codec, which is a good codec for low bitrates. Even if it produce bigger files compared to my older method (the latter can be found in the first version of the script), the quality is very awesome and video artefacts (ringings and blockings) are so reduced that it’s now very hard to distinguish. So I decided to use h264 in the new version of my script.

There is still an inconvenient of using VLC instead of mencoder: VLC is transcoded at real time ! I tried the “hurry-up” parameters without effects. This is sad but acceptable, since my goal is to archive my tiny videos.

To summarize, here is the command line I use to do transcoding via VLC:

vlc --sout-all "input_video.avi" :sout='#transcode{vcodec=h264, acodec=mp3, ab=32,channels=1, audio-sync}:std{access=file, mux=mp4, url="output_video.mp4"}' vlc:quit -I dummy

This command is far from perfect and I plan to dig into VLC help to tune h264 codec.

HowTo Compile and Use xvidcap

Compile gvidcap !

Get the last stable source code archive on xvidcap Sourceforge project page or download it from the CVS:

cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/xvidcap co -P xvidcap

Install required dependencies:

urpmi gcc automake libgtk+2-devel ffmpeg-devel liblame0-devel

Dirty compile:

make distclean [optional]
CPPFLAGS=-I/usr/include/ffmpeg LDFLAGS=-L/usr/bin/ffmpeg
./configure --with-gtk2 --with-forced-embedded-ffmpeg && make gvidcap
make gvidcap
make install [optional]

Quick test:

./src/gvidcap &

Use gvidcap !

Raw capture:

gvidcap --gui no -v --file ~/img_%04d.xwd --frames 0 --fps 10 --cap_geometry 1024x768+0+0

The following can be used but it slow down the machine (png compression require too cpu):

gvidcap --gui no -v --compress 9 --file ~/img_%04d.png --frames 0 --fps 10 --cap_geometry 1024x728+0+0

Convert .xwd images to .png images because mplayer only support .png, .jpg, .tga and .sgi image file format:

convert img_*.xwd img_%04d.png && rm -rf ./*.xwd

Preview the video:

mplayer "mf://*.png" -mf fps=10

Make a video from successive screenshots:

mencoder "mf://*.png" -mf fps=10 -ovc lavc -o ./video.avi

Documentation: