[LINUX/MENCODER] mencoder flv encode option
mencoder 1166685654_19.wmv -o test.flv -of lavf -oac mp3lame -lameopts abr:br=56 -srate 22050 -ovc lavc -lavcopts vcodec=flv:vbitrate=500:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames
Stupid video tricks with mplayer and mencoder
For people out there as lazy as I am (and by lazy, I mean "will spend four hours searching forums via google to find someone else who wanted to accomplish something tricky with one command line, and asked smarter people rather than dig through documentation to come up with the solution") I'm putting together a short list of simple but (imho) interesting things to do with mplayer and mencoder because I have had to do them at one point or another, and why should you suffer the pain of broken google links and forced forum registrations?
First, get mplayer. I'm not going into the esoterics of how to set it up for your system, I use windows and cygwin, and the latest windows binary with the all codecs package works for me.
And now, in no particular order...
- Converting a video file of arbitrary format to a sequence of images
- Jpeg
mplayer -nosound -vo jpeg inputfile
- Png
mplayer -nosound -vo png:z=n inputfile*where n is a number from 0-9 for compression quality (9 = best compression, but slowest)
I always try and use png because they're usually better quality. If you're just grabbing stills for email or the web, use jpeg.
- Jpeg
- Creating a flash video (.flv) file for web streaming
- From a video source
mencoder inputfile -ffourcc FLV1 -of lavf -ovc lavc -lavcopts vcodec=flv:acodec=mp3:abitrate=56 -srate 22050 -o outputfile - From a sequence of images
mencoder mf://*.png -mf w=360:h=240:fps=12:type=png -of lavf -ffourcc FLV1 -ovc lavc -lavcopts vcodec=flv:acodec=mp3:abitrate=56 -srate 22050 -o outputfileObviously, replace the width, height, and frames per second above with the w/h/fps of your video. If you're using jpegs, use '*.jpeg' and 'type=jpeg' instead of png above. If you don't have any audio, use this:
mencoder mf://*.png -mf w=360:h=240:fps=12:type=png -of lavf -ffourcc FLV1 -ovc lavc -lavcopts vcodec=flv -o outputfile
- From a video source
- Creating a flash player for your streaming .flv file
- Jeroen's Free Flash Video Player
I really shouldn't have to say anything else about this great offering, the documentation in the zip file and his web page tell you everything you need to know. Basically once you have a .flv file, you want to embed it in flash (.swf) or, better yet, stream it off a server to avoid the lengthy download. Most users out there are able to view flash, and developers who post video in other formats (asf, quicktime, or whatever) have problems with some percentage of browsers, depending on their audience. Using flash avoids this issue, and using flv lets you stream the video without the expense of a dedicated streaming server. But coding a player from scratch is a pain in the ass, and although I attempted a compile of Ming for windows to try and use Klaus's method I realized (again, being lazy) there was an even easier way. Steal Jeroen's terrific code, point it at your .flv and you're done! He even gives you the .fla file if you want to mess with the flash application and integrate it with your own. The controls and UI are clean, and it's free for non-commercial use (donation for commercial purposes).
- Jeroen's Free Flash Video Player
- Official documentation:
- http://www1.mplayerhq.hu/MPlayer/DOCS/HTML/en/mencoder.html
Note: The actual program man page differs from, and has additional information not included in, the
online docs. It's a good idea to refer to the man page. You can find the mencoder one here:
Mencoder man page
This is a nice Wiki with some tips and help on Mencoder:
http://en.gentoo-wiki.com/wiki/HOWTO_Mencoder_Introduction_Guide
Critically, the docs include a magic incantation that seems to generate a working flash video file: -
mencoder \videos\soph1.wmv -o soph4.flv -of lavf -oac mp3lame -lameopts abr:br=56
-ovc lavc -lavcopts vcodec=flv:vbitrate=500:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -srate 22050 - I'm still trying to work out what all these options do, but the output does seem to work.
The 'srate' is the audio sampling rate. This is important because Flash video only supports these audio sampling rates: - 11025
- 22050
- 44100
-
Usage
- General format is:
- mencoder <input file> -o <output file> -ovc <video codec> [.. video options] -oac <audio codec> [..audio options] -of <output format coder> [...output format options..]
- The biggest trick I've noticed with mencoder is that you can defer down to libavcodec for everything, in which case the mencoder options take values which basically say: "just defer to libavcodec".
Examples:
-of lavf Use libavformat to determine output file format (otherwise you get avi by default)
-oac lavc Use libavcodec to do the audio encoding
-ovc lavc Activate libavcodec for video encoding
"lavf" refers to audio/video file format (eg. .mov, .3gp, .avi., .mp4) as opposed to "lavc", which refers to codec.
-
Options
- -vf Add a chain of video filters. These can include "scale" (see below) for scaling the image. Also "harddup" will generate "hard" duplicate frames. See audio sync below for why this is important.
- -oac Set the output audio codec
values: copy, pcm, mp3lame (use Lame mp3 encoder), lavc (use libavcodec)
Use '-nosound' to disable processing the audio stream. - -of Set the output container format
Use -of help to get a list of container formats - −ovc Set the output video codec
Use -ovc help to get the list of codecs. Use 'lavc' to defer down to the libavcodec library from ffmpeg. Then you need to specify the actual codec to use with the -lavcopts argument (see below).
copy no encoding, just copy
lavc use the libavcodec library (best quality says the app)
vfw use the Video For Windows codecs. I haven't had much luck with this.
What's tricky with mencoder is that you set the output codec, but then each
codec takes its own set of options.
You specify options to the codec with this syntax: - -<name of codec>opts option1:option2=value:option3,...
- −lavcopts
- acodec=value I guess this overrides -oac and uses the libavcodec for audio encoding.
Values include: mp2, mp3, ac3 - abitrate=<value>
- vcodec=<value>
Check the manual. Flash (Sorenson) is "flv". - mpeg1video
- mpeg2video
- msmpeg4v2
- mpeg4
- You can also specify format options. So to use libavcodec for generating the
container format, use:
-of lavf -lavfopts <...options>
Where options include: - format=mpg|asf|avi|swf|flv|mov|mp4
Here is a complete example: - mencoder /videos/dexp.mpg -o dell.avi -ovc lavc -oac lavc -lavcopts acodec=mp3:vcodec=msmpeg4v2 -of lavf -lavfopts format=avi
- This says:
- Input file is /videos/dexp.mpg
- Output file is dell.avi
- -ovc lavc : Use libavcodec as the video codec
- -oac lavc : Use libavcodec as the audio codec
- -lavcopts ... : Set the libavcodec options
- acodec=mp3 - Use mp3 for audio encoding
- vcodec=msmpeg4v2 - Use msmpeg4v2 codec for video encoding
- -of lavf : Use libavformat for building the output container
- -lavfopts format=avi : Use avi container format
- Setting output frame size
- Use:
- -vf scale=<width>:<height>
- like:
-vf scale=320:240
Add ",harddup" to force real copies of duplicate frames. - Fixing Audio Sync Problems
'LINUX' 카테고리의 다른 글
[LINUX/FFMPEG] Hooking Up The SMPTE VC-1 Decoder In FFmpeg (0) | 2009.10.06 |
---|---|
[LINUX/Ubuntu/FFMPEG] VLC player에서 WMV9코덱 동영상을 재생하기 위한 방법 (0) | 2009.10.06 |
[LINUX/FFMPEG] Hooking Up The SMPTE VC-1 Decoder In FFmpeg
Hooking Up The SMPTE VC-1 Decoder In FFmpeg
Filed under: Open Source Multimedia — Multimedia Mike @ 5:22 pm
Some people have asked me for my code to make the SMPTE VC-1 reference decoder work with FFmpeg,
slow though it may be. I suppose I could make a patch. But the official version of FFmpeg is whatever happens to be in CVS at the current moment. So any patch I could produce would work for maybe a day. So get ready to do a little editing on your local FFmpeg CVS tree.
The steps:
- procure the VC1_reference_decoder_release6.zip file from the main site and unzip the tree somewhere
- have a copy of FFmpeg’s CVS tree handy; the rest of these instructions will assume that you are sitting in the root of the FFmpeg tree
- create a directory called libavcodec/libvc1
- copy all of the *.c and *.h files from VC1_reference_decoder_release6/decoder/ into libavcodec/libvc1/
- copy all of the *.c and *.h files from VC1_reference_decoder_release6/shared/ into libavcodec/libvc1/
- place the libvc1-makefile.txt into libavcodec/libvc1/Makefile
- change directory into libavcodec/libvc1 and type ‘make’
- change directory back to the FFmpeg root
- place the smpte-vc1.c file into libavcodec/
- edit
libavcodec/vc9.c, go the very end of the file, and add #if 0/#endif
around the wmv3_decoder AVCodec structure; this will keep it from
conflicting with the new SMPTE WMV3 decoder - edit libavcodec/Makefile and add smpte-vc1.o to the end of the OBJS list
- edit the top-level Makefile and add “-L./libavcodec/libvc1 -lvc1″ (without the quotes) to FFLIBS
- run ‘./configure’ at the top level if you have not already done so for this tree
- run ‘make’ at the top level
'LINUX' 카테고리의 다른 글
[LINUX/MENCODER] mencoder flv encode option (0) | 2009.10.06 |
---|---|
[LINUX/Ubuntu/FFMPEG] VLC player에서 WMV9코덱 동영상을 재생하기 위한 방법 (0) | 2009.10.06 |
[LINUX/Ubuntu/FFMPEG] VLC player에서 WMV9코덱 동영상을 재생하기 위한 방법
Instructions for compiling VLC with VC-1 (WMV9) support under Ubuntu Breezy
Install dependencies available from the Ubuntu repositories (main and universe)
$ sudo apt-get install libwxgtk2.6-dev libdvbpsi3-dev libmpeg2-4-dev libmad0-dev libasound2-dev libesd0-dev x11proto-video-dev libdvdnav-dev liba52-0.7.4-dev libflac-dev libfreetype6-dev libid3tag0-dev libogg-dev libpng12-dev libspeex-dev libtheora-dev libvorbis-dev libxml2-dev zlib1g-dev gcc g++ automake1.9 autoconf libtool subversion cvs libx11-dev
Install libdvdcss (DVD support)
$ mkdir ~/videolan ; cd ~/videolan
$ wget http://downloads.videolan.org/pub/videolan/vlc/0.8.2/contrib/libdvdcss-1.2.8.tar.bz2
$ tar -jxvf libdvdcss-1.2.8.tar.bz2 ; cd libdvdcss-1.2.8
$ ./configure --prefix=/usr ; make ; sudo make install
Compile faad2 (AAC support)
$ cd ~/videolan ; wget http://downloads.videolan.org/pub/videolan/vlc/0.8.2/contrib/faad2-20040923.tar.bz2
$ tar -jxvf faad2-20040923.tar.bz2 ; cd faad2-20040923
$ ./configure --prefix=/usr ; cd libfaad ; make
Compile ffmpeg (support for H264 and many other codecs)
$ cd ~/videolan ;svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
$ cd ffmpeg ; ./configure --enable-pp --enable-gpl ; make
Compile libvc1 (WMV9 support)
$ cd ~/videolan ; wget http://nanocrew.net/sw/libvc1-1.0.tar.gz ; tar -zxvf libvc1-1.0.tar.gz
$ wget http://www.multimedia.cx/VC1_reference_decoder_release6.zip
$ unzip VC1_reference_decoder_release6.zip
$ cp VC1_reference_decoder_release6/decoder/*.[ch] libvc1-1.0/src/.
$ cp VC1_reference_decoder_release6/shared/*.[ch] libvc1-1.0/src/.
$ cd libvc1-1.0 ; ./bootstrap ; ./configure --prefix=/usr ; make
Install VLC
$ cd ~/videolan ; svn co svn://svn.videolan.org/vlc/trunk vlc-trunk
$ cd vlc-trunk ; wget -O - http://nanocrew.net/sw/vlc-libvc1.diff | patch -p0
$ ./bootstrap ; ./configure --with-ffmpeg-tree=../ffmpeg --enable-faad --with-faad-tree=../faad2-20040923 --enable-esd --enable-flac --enable-theora --enable-libvc1 --with-libvc1-tree=../libvc1-1.0 --disable-hal
$ make ; sudo make install
P.S 현재 ffmpeg의 cvs가 종료되었기 때문에 따로 받도록 수정하였으며, VC1 decoder도 마찬가지로 원본이 깨져있기 때문에 따로 받을 수 있도록 링크를 수정하였다.
또한 X11 developer library도 설치를 할 것..안 그러면 최종 make단계에서 xext 에러가 남..
'LINUX' 카테고리의 다른 글
[LINUX/MENCODER] mencoder flv encode option (0) | 2009.10.06 |
---|---|
[LINUX/FFMPEG] Hooking Up The SMPTE VC-1 Decoder In FFmpeg (0) | 2009.10.06 |