Create High Quality Flash Videos in Ubuntu
I recently got a nice new camera that can shoot HDTV videos, and the only way to show off the awesome quality to the world is by creating flash videos by myself. Here is an example:
I use Ubuntu, so this tutorial won’t work on Windows. I have encoded the video into the H.264 format, left the original resolution at 848 x 480, and the framerate at 30 Hz. I use constant quality setting because then the video look very good even when the camera moves quickly, and it uses less bitrate when not needed. The disadvantage is that the required bitrate is uneven, so make sure youre buffer is large enough before you start playing.
Here is how to do this:
- Encode your video with mencoder (click to install). It has to be x264 for video (0 or 1 bframes), and faac for audio.
- Convert the result into an mp4 using mp4creator (click to install), as described here.
- Now you have an mp4 file that can be played with JW player. Download it, have a look at the readme.html, and follow the example described there.
- The player requires 20 pixels in height, so add this to the SWFObject creation.
I have written a small ruby script to convert any movie to a MP4 file. The first parameter is the input file, second parameter is the framerate. Save this file as e.g. convert2mp4.rb.
#!/usr/bin/ruby
# constant quality setting
if ARGV.size != 3
puts "usage: #{__FILE__} <inputvideo> <framerate> <quality, 1.0-50.0>"
exit
end
# set output filenames
input = ARGV[0]
rate = ARGV[1]
quality = ARGV[2]
noext = input.gsub(/\.\w*$/, "")
converted = '"' + noext + '_tmp.avi"'
aac = '"' + noext + '.aac"'
h264 = '"' + noext + '.h264"'
mp4 = '"' + noext + '.mp4"'
# encode
cmd = "mencoder \"#{input}\" -o #{converted}"
cmd += " -ovc x264 -x264encopts threads=auto:crf=#{quality}:subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=1:b_pyramid:weight_b"
cmd += " -oac faac -faacopts br=192 -channels 2 -srate 48000"
puts cmd
system(cmd)
# convert to mp4
system("rm -f #{mp4}")
system("mplayer #{converted} -dumpaudio -dumpfile #{aac}")
system("mplayer #{converted} -dumpvideo -dumpfile #{h264}")
system("mp4creator -create=#{aac} #{mp4}")
system("mp4creator -create=#{h264} -rate #{rate} #{mp4}")
system("mp4creator -hint=1 #{mp4}")
system("mp4creator -hint=2 #{mp4}")
system("mp4creator -optimize #{mp4}")
system("rm -f #{aac} #{h264} #{converted}")
Have fun!
7 Responses to “Create High Quality Flash Videos in Ubuntu”
Leave a Reply
Thanx for the tutorial, the result looks very good.
Three questions:
What type of camera is that?
How did you mount it to your head?
What software did you use on Ubuntu to pull the video off of your camera and edit it?
Hi tc!
I have used a Panasonic Lumix DMC TZ5, here is a review.
To mount it on the head I have basically used a bicycle helmet and a rubber band. It looks a bit adventerous, but it is very sturdy. I would like to create a blog entry on how to do this but I need a second camera to take pictures…
To get the video off the camera I just plug it in, it is recognized as an USB disk and you can copy the mpg file. I did not edit the movie at all but just converted it into MP4 as described.
I tried this on an avi and an ogg file and i get errors. Does this only work on particular file types?
/media/USB\ Disk/convert2mp4.rb thine-eyes-ask.ogg 1 50
mencoder “thine-eyes-ask.ogg” -o “thine-eyes-ask_tmp.avi” -x264encopts threads=auto:crf=50:subq=6:partitions=all:8x8dct:me=umh:frameref=5:bframes=1:b_pyramid:weight_b -oac faac -faacopts br=192 -channels 2 -srate 48000
MEncoder 2:1.0~rc2-0ubuntu19+medibuntu1 (C) 2000-2007 MPlayer Team
CPU: Intel(R) Core(TM)2 Duo CPU T7300 @ 2.00GHz (Family: 6, Model: 15, Stepping: 10)
CPUflags: Type: 6 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled with runtime CPU detection.
success: format: 0 data: 0×0 – 0x17b5dfb4
[Ogg] stream 0: video (Theora v3.2.1), -vid 0
[Ogg] stream 1: audio (Vorbis), -aid 0
Ogg file format detected.
VIDEO: [theo] 720×480 24bpp 29.970 fps 0.0 kbps ( 0.0 kbyte/s)
[V] filefmt:18 fourcc:0x6F656874 size:720×480 fps:29.97 ftime:=0.0334
No video encoder (-ovc) selected. Select one (see -ovc help).
Exiting…
MPlayer 1.0rc2-4.3.3 (C) 2000-2007 MPlayer Team
CPU: Intel(R) Core(TM)2 Duo CPU T7300 @ 2.00GHz (Family: 6, Model: 15, Stepping: 10)
CPUflags: MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled with runtime CPU detection.
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing thine-eyes-ask_tmp.avi.
File not found: ‘thine-eyes-ask_tmp.avi’
Failed to open thine-eyes-ask_tmp.avi.
Exiting… (End of file)
MPlayer 1.0rc2-4.3.3 (C) 2000-2007 MPlayer Team
CPU: Intel(R) Core(TM)2 Duo CPU T7300 @ 2.00GHz (Family: 6, Model: 15, Stepping: 10)
CPUflags: MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled with runtime CPU detection.
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing thine-eyes-ask_tmp.avi.
File not found: ‘thine-eyes-ask_tmp.avi’
Failed to open thine-eyes-ask_tmp.avi.
Exiting… (End of file)
mp4creator: can’t open file thine-eyes-ask.aac: No such file or directory
mp4creator: can’t open file thine-eyes-ask.h264: No such file or directory
MP4ERROR: FindTrackIndex: Track id 1 doesn’t exist
mp4creator: couldn’t create hint track, no media samples
MP4ERROR: FindTrackIndex: Track id 2 doesn’t exist
mp4creator: couldn’t create hint track, no media samples
Hi Janson! I had a bug in the script, I have forgotten the option -ovc x264. I have updated it, now it should work
i can not get this to work either
i am sooooooooo confused
this is the error i get
Error decoding sei message
i am testing it on a .mov file i downloaded from apple.com/trailers
seems to be an older howto, but hey, ist still working. thx