View Full Version : Video conversion using open-source tools
[If this is covered elsewhere, my apologies, but after reading through scads of video-conversion related posts, I didn't see it anywhere.]
For anyone wishing to convert various types of video files to Clie MPG format using open-source tools and without IC, read on.
I've been using the technique described below for many months with good results. The resultant file sizes are reasonably small and the quality is good. My target device is a TH-55; playback software is Movie Player.
Please note that there may be more efficient methods of using these tools; specifically, I imagine the "ffmpeg" step can be combined with the "transcode" step but haven't had the time to fully investigate. Please consider this advice a (possibly faulty) baseline for conversion workflow. In other words, your mileage may vary and my advice may be non-optimal. But it works well for me and, I hope, for you.
Requirements:
Transcode (http://www.transcoding.org)
ffmpeg (http://ffmpeg.sourceforge.net)
Note that most linux distributions have pre-built packages for these tools.
Assumes:
Input file is foo.avi (can be nearly any type, though)
Intermediate file is foo.320x240.avi
File output file is MOV00001.MPG
Commands:
% transcode -i foo.avi -o foo.320x240.avi -F mpeg4 -y ffmpeg -Z 320x240 -J resample -E 44100
% ffmpeg -f avi -b 800 -g 300 -bf 2 -i foo.320x230.avi MOV00001.MPG
Usage notes:
- While the transcode command is running, play the resulting file (if your OS allows playing an open file) with mplayer or similar tool.
-- If the video is upside-down, stop and redo the transcode command with the "-z" option.
-- If some skin tones are blue, stop and redo the transcode command with the "-k" option
-- If transcode runs into difficulties with B frames ("vop not coded" or similar error) and fails, but mplayer can play the file with no difficulty, redo the transcode command specifying mplayer as the video import module with "-x mplayer"
-- If the resulting video is too dark or too light, correct the gamma with the "-G value" option, where value is 0.0-10.0 and 1.0 means "change nothing", a value lower than 1.0 will brighten the picture and a value above 1.0 will darken it. For brightening, I've had good results with -G .5 through .8
Feedback would be appreciated. I'm pretty sure there are some probably superstitious command-line options in use, since I'm not fully familiar with all the options of transcode and ffmpeg. And perhaps mencoder could be used as a 1-pass solution.
Example input and output sizes:
Input: "The Wire, Season 3 Episiode 11" Runtime: ~1 hr
Format: RIFF, AVI, v=XVID 23.976 512x384 a=48000Hz 131kbps
Size: 341MB
Output file size: 199MB
-C
Karim
01-04-2005, 01:33 PM
Can't you do the resize on the second set of commands?
RavenTen
01-04-2005, 02:57 PM
Requirements:
Transcode (http://www.transcoding.org)
ffmpeg (http://ffmpeg.sourceforge.net)
Note that most linux distributions have pre-built packages for these tools.
Assumes:
Input file is foo.avi (can be nearly any type, though)
Intermediate file is foo.320x240.avi
File output file is MOV00001.MPG
Commands:
% transcode -i foo.avi -o foo.320x240.avi -F mpeg4 -y ffmpeg -Z 320x240 -J resample -E 44100
% ffmpeg -f avi -b 800 -g 300 -bf 2 -i foo.320x230.avi MOV00001.MPG
... [clipped for brevity]
Feedback would be appreciated. I'm pretty sure there are some probably superstitious command-line options in use, since I'm not fully familiar with all the options of transcode and ffmpeg. And perhaps mencoder could be used as a 1-pass solution.
Example input and output sizes:
Input: "The Wire, Season 3 Episiode 11" Runtime: ~1 hr
Format: RIFF, AVI, v=XVID 23.976 512x384 a=48000Hz 131kbps
Size: 341MB
Output file size: 199MB
Okay, please humor me here, as I'm attempting to decode your command-line string ...
-i is your input file name.
-o is your output file name
"-F mpeg4" is the video Codec string
"-y ffmpeg" is indicating that you want to transcode to Mpeg4 using ffmpeg?
-Z is the resample from DVD size to whatever size you want to convert it to.
"-J resample -E 44100" is merely an audio resample from typical audio to 44100 output.
So, the intermediate step, converts from your AVI (whatever that AVI file is set up as) to an Mpeg4 using ffmpeg at 320x240 with an audio sampling rate of 44100.
You are then taking the AVI output from transcode and running it through ffmpeg ...
"-f avi" does a force format to the AVI format.
-b 800 sets your bitrate to 800kb/s
-g sets the gop_size (what is the group of picture size?)
-bf 2 sets your B-Frames to 2
-i foo.30x240.avi mov00001.mpg merely sets your input file, and our output file.
So ... there doesn't appear to be an implication that you are transcoding to MPEG-1 ... other than doing the -g function (which apparently is used mostly for streaming video stuff?) you are doing a rename from .avi to .mpg and tweaking the file to 44100 for audio.
What (if you don't mind my innate curiosity) are the respective stats on the output file? (just to make sure that I'm not missing anything here ...)
I'm _expecting_ to see it as an Mpeg4 (no idea on the framerate) 320x240 with 44100 audio. (mpeg 3 or 4 though ... now there is a good question ...)
If that is the case ... then can we merely rename Mpeg4 AVI files as .mpg and play them using the movie player? (grins maniacly at the possibility) I think I'm going to try it ...
-R
Karim: You're right, the rescaling can be done with ffmpeg. I haven't had good luck resampling audio with ffmpeg, and since the operation is (so far) two steps, I left the rescaling to transcode.
RavenTen: I realize I neglected to describe the output format in my original post. The output, unless I'm being misled by mplayer, is mpeg1, but with decent quality and filesize (I was under the impression mpeg4 files needed to be named .MQV and have a special atom identitier?).
At any rate, here's what mplayer reports:
Playing wire311.mpg.
MPEG-PS file format detected.
VIDEO: MPEG1 320x240 (aspect 1) 23.976 fps 0.0 kbps ( 0.0 kbyte/s)
AUDIO: 44100 Hz, 2 ch, 16 bit (0x10), ratio: 8000->176400 (64.0 kbit)
Selected audio codec: [mp3] afm:mp3lib (mp3lib MPEG layer-2, layer-3)
As I mentioned, I thought I was probably using some seriously superstitious options. It looks as if my transcode command can omit the -F and -y options without affecting behavior. These options may well be artifacts of my experiments trying to produce mpeg4 files in a form expected by Movie Player in .MQV files, but I gave up on that until I can properly produce AAC (format 0x6134706D) audio, which so far I am unable to either encode or decode with mplayer and friends.
To confirm the supposition about spurious options, I'm currently reprocessing an input avi file in two ways:
- transcode without -F and -y options, to be followed by the usual ffmpeg command
- ffmpeg (in an attempt at a single pass) with rescaling (-s) and audio rate changed to 44.1kHz and 128kbps. My previous efforts at solely using ffmpeg resulted in loss of audio sync.
R10, I'm curious what results you see.
Best,
-C
RavenTen
01-04-2005, 04:54 PM
Okay, upon further research ... it appears that ffmpeg when given a .mpg output string outputs to mpeg-1.
One can also force audio in ffmpeg ...
`-ar freq'
set the audio sampling freq (default = 44100 Hz)
`-ab bitrate'
set the audio bitrate in kbit/s (default = 64)
`-ac channels'
set the number of audio channels (default = 1)
It is also possible to set the size ...
`-s size'
set frame size. The format is `WxH' (default 160x128).
So ... it MIGHT be possible to go direct from your .avi source direct to mpeg-1
As a side note ... it _LOOKS_ like one can go from .vob to .avi ... and as ffmpeg can do mpeg-1 as well ... it might be possible to go direct to mpeg-1 using a string similar to this one ...
ffmpeg -i foo_1.vob -f mpg -s 320x240 -vcodec mpeg1 -b 800 -g 300 -ar 44100 -acodec mp3 -ab 128 foo.mpg
This is a DVD ripper example, input from a VOB file, output to an MPEG-1 file with MPEG-1 video and MP3 audio, GOP size is 300 that means an INTRA frame every 10 seconds for 29.97 fps input video. Also the audio stream is MP3 encoded so you need LAME support which is enabled using --enable-mp3lame when configuring.
The single pass with ffmpeg just finished and seemed to work this time, without audio sync problems. I did:
ffmpeg -f avi -b 800 -g 300 -bf 2 -ar 44100 -ab 128 -s 320x240 -i {inputfile} {outputfile}
I don't know why I ultimately did it in two passes except as an artifact of trying to produce mpeg4 Clie-compatible output. It also occurs to me that file sizes may have been somewhat smaller using transcoder and ffmpeg as opposed to ffmpeg alone. I'll crank up another hour-long test to confirm this, as well.
r10, I agree going from .vob to .mpg is probably addressed by this process. Btw, I hope I didn't mislead you too badly with those spurious mpeg4-related options...
BTW: It appears this topic (using ffmpeg to produce mpeg1 videos without using IC) has been covered, for OS X at least, in this thread: http://www.1src.com/forums/showthread.php?t=28344&page=1&pp=15
(although I haven't tried the options specified in the ffmpegX template supplied in the thread)
RavenTen
01-04-2005, 09:07 PM
The single pass with ffmpeg just finished and seemed to work this time, without audio sync problems. I did:
ffmpeg -f avi -b 800 -g 300 -bf 2 -ar 44100 -ab 128 -s 320x240 -i {inputfile} {outputfile}
BTW: It appears this topic (using ffmpeg to produce mpeg1 videos without using IC) has been covered, for OS X at least, in this thread: http://www.1src.com/forums/showthread.php?t=28344&page=1&pp=15
(although I haven't tried the options specified in the ffmpegX template supplied in the thread)
There is something to be said for command-line tools. *chuckles*
The ffmpeg settings in the mac article appear to have no b-frames and no i-frames and the audio settings are at 48000 and a bit-rate of 96
In any case, the ffmpeg coder settings for ffmpegx appear to be -f avi -s 320x240 -b 251 -f 23.976 -g 240 -qmin 2 -qmax 15 -ar 48000 -ab 96
however ... as an interesting side note ... the file given as an example appears to be merely a mutexed MPEG-1 file however it seems to have 'standard' 30fps video. Not NSTC film ... *ponders thoughtfully*
Forget bout that. Its way too complicated. An awesome tool, which produces amazing results is HandBrake. Its avail as freeware for MacOS and a limited version for Windows. HandBrake get your data directly from your DVD and encodes them directly to MPEG. And you could change all necesarry settings within a useful mask (even two pass encoding is supported !). And the resulting MPEG 4 is indeed compatible with Kinoma Player EX 3.
There is something to be said for command-line tools. *chuckles*
Amen! :)
In any case, the ffmpeg coder settings for ffmpegx appear to be -f avi -s 320x240 -b 251 -f 23.976 -g 240 -qmin 2 -qmax 15 -ar 48000 -ab 96
however ... as an interesting side note ... the file given as an example appears to be merely a mutexed MPEG-1 file however it seems to have 'standard' 30fps video. Not NSTC film ... *ponders thoughtfully*
It would be interesting to see what, if any, difference the encoding options make (b-frames vs. no b-frames, qmin/qmax settings, etc). If anyone's interested, I'll post the difference in characteristics/ quality/ size when the encoding completes (note it's -r fps, not -f).
Forget bout that. Its way too complicated. An awesome tool, which produces amazing results is HandBrake. Its avail as freeware for MacOS and a limited version for Windows. HandBrake get your data directly from your DVD and encodes them directly to MPEG. And you could change all necesarry settings within a useful mask (even two pass encoding is supported !). And the resulting MPEG 4 is indeed compatible with Kinoma Player EX 3.
Handbrake looks like an interesting GPL'd project, thanks for the recommendation.
I'm not sure I care much about Kinoma Player EX 3, though, given I have a TH55. I don't think Kinoma utilizes the DSP, so I imagine battery life and performance will suffer. Moreover, the trial version doesn't support MPEG 4 -- a showstopper issue right there. Also many people seem to be complaining about performance (on TH55, NX73V, Tungsten E, Treo 600) in the Kinoma forums
here (http://www.kinoma.com/forum/showthread.php?t=578)
UnLoGiC
01-14-2005, 06:50 PM
I'm working on something that also open source and does conversion, have a look at http://unlogic.no-ip.biz/umc
It's not finished but I'm about 50% with the coding...
vBulletin v3.0.3, Copyright ©2000-2012, Jelsoft Enterprises Ltd.