Making FLV files with FFmpeg or MEncoder
July 8th, 2007 by heathenxOk folks. It seems I’m back in encoding hell. I am looking for the best and most popular streaming format known to mankind. Why, because I want to move away from our shockwave files to a format that allows for true streaming. Furthermore, our shockwave files are rather large. In some cases over 100MB. I think I want pure flash files but I’m keeping an open mind.
I know how to convert my H264 AVI files to FLV (Flash). So far I can make a beautiful 1:1 FLV file but the file size grows to 2-4 times that of the input AVI. No good. I can also make several shitty FLV’s that are pixelated when played. So basically, I can make really good one or really bad ones. Nothing in between.
What I need is some help. Who out there knows of a FFmpeg or MEncoder guru who is willing to lend a hand? All one has to do is download episode 024 or 025 (these are for sure encoded in H264 format) and try converting it to a flash file. Resolution has to be 800×600 with decent sounding audio.
Help me Obi-Won Kenobi. You are my last hope.
July 11th, 2007 at 12:13 pm
Alright. I finally contacted a few mencoder gurus from the opensuse community and have been working with them for the last few days. These guys are incredible. Absolutely fabulous. They have helped me immensely. I am now in the process of re-encoding my original screencasts into H.264 AVI files that lend themselves into making better FLV files.
My goal was to get a better streaming format for everyone. Those SWF’s are mighty large in size. So far I have seen my FLV’s 1/3 to 2/3 smaller in file size with just a tad reduction in video quality.
I have encoded so many videos in the last couple of days that my eyes are bleeding and my fingers are blistered from using the keyboard (causing me to make even more typos than I already make.)
July 12th, 2007 at 3:13 am
So what were the settings you ended up using? Please share!
I’ve been trying the same thing, with much the same results. Even if I compress to keep the filesize of the AVI about the same as the flv, it looks pixelated…
July 12th, 2007 at 11:29 am
Well, let me give you a tip. If you are using Linux then I highly recommend Microchip’s two programs called h264enc and xvidenc.
http://h264enc.sourceforge.net/
http://xvidenc.sourceforge.net/
Both of these scripts will output a mencoder script (if you save it) and then encode your video. Without Microchip’s help and advice then I would still be in encoding hell, most likely.
The key for us was to eliminate b-frames from our original h264 videos. B-frames are not bad and do aid in the compression of the final video but they do interfere when one wants to convert the AVI into an FLV. Both FFmpeg and mencoder struggled to convert and video with b-frames in it. That goes for our original h264′s and xvid’s.
So, this is how we convert our screencast output (AVI, OGG, WMV) into h264 AVI video without b-frames:
nice -n 0 mencoder input.avi -ofps 26000/1001 -vf scale=800:600:0:0::::0:1 -sws 10 -af resample=22050:0:2 -srate 22050 -oac mp3lame -lameopts cbr:br=128:aq=4:vol=1.5:mode=1:highpassfreq=0:lowpassfreq=0 -ovc x264 -x264encopts qp=2:me=hex:nodct_decimate:nointerlaced:no8x8dct:threads=1:nofast_pskip:nobrdo:trellis=1:scenecut=40:chroma_qp_offset=0:ip_factor=1.4:pb_factor=1.3:nomixed_refs:noglobal_header:nobime:keyint=250:keyint_min=25:frameref=1:bframes=0:nob_adapt:nob_pyramid:noweight_b:subq=5:chroma_me:nocabac:nodeblock -o output_h264.aviThen, to convert this AVI to FLV:
mencoder output_h264.avi -oac mp3lame -lameopts cbr:br=128 -af resample=22050 -srate 22050 -ovc lavc -lavcopts vcodec=flv:vqscale=2:mbd=2:trell:cmp=2:precmp=2:subcmp=2:mbcmp=2:dia=2:cbp:v4mv:autoaspect -of lavf -lavfopts format=flv:i_certify_that_my_video_stream_does_not_use_b_frames -vf scale=800:600 -sws 10 -o output.flvDon’t ask me what all of those switches in the mencoder script are for. I am still getting an education. I suggest reading the man page for mencoder.
There are many, many ways to encode videos with mencoder (or ffmpeg). It is a very powerful program.
Hope that helped.
July 12th, 2007 at 11:32 am
Good grief, WordPress! Can’t we do a little better job with the text above? ;(
Sorry everyone.
August 10th, 2007 at 10:58 pm
instead of compressing a mp3 sound track directly with mencoder, I prefer to do it in a separate mp3 file using my favorite tools, then multiplex it to the final FLV file using fmpeg or mencoder. I first export the audio track to a wav file, in order to normalize it using “normalize-audio”. Then I like to use ecasound for its Dyson compressor, especially to create a low bit rate mp3 intended to play on bad speakers. I use lame to compress the mp3 file because it gives me more control and maybe produce better VBR mp3s than mencoder.
November 27th, 2007 at 8:21 pm
I just wrote up a post on my blog about how to do this using ffmpeg. Check out my blog post on transcoding to flv. The secret is to use a 2-pass encoding in ffmpeg. Without 2 passes, ffmpeg’s bitrate control is very very bad, and produces files that are far too large.
Looking at heathenx’s script, I think thats not a very optimal solution. It looks like you’re transcoding twice, but I could just be misreading those lines since they’re formatted to poorly.
November 27th, 2007 at 9:05 pm
Well, to this day I still cannot get a good flv video with ffmpeg in comparison to mencoder. Let me try your method.