Linux Video Stream Processing Tool - Examples
Keywords: DVD, digital video, DV, encoder, divx, DivX;-), lame, source, posix, avifile, opendivx, codec, linux, AC3, program stream, video, audio, transcode, decoder, stream, YV12

Miscellaneous
Overview on the resizing/clipping options AVI-files with multiple audio tracks pass-through modes replacing audio creating music clips audio recompression fixing truncated AVI files audio only conversion audio track -> MP3 audio track -> PCM ASF audio -> MP3

resizing/clipping options
by Steffen Klupsch <steffen@vlsi.informatik.tu-darmstadt.de> Boundary Conditions (valid for transcode-0.5.0 and later): maximum image size is 1024x768 The video frame operations ordering is fixed: "-j -I -X -B -Z -Y -r -z -l -k -K -G -C" (executed from left to right) Shrinking the image with '-B' is not possible if the image width/height is not a multiple of 32. Expanding the image with '-X' is not possible if the image width/height is not a multiple of 32. The final frame width/height should be a multiple of 8. (to avoid encoding problems with some divx codecs) Reducing the video height/width by 2,4,8 Option '-r factor' can be used to shrink the video image by a constant factor, this factor can be 2,4 or 8. Clipping and changing the aspect ratio transcode uses 3 steps to produce the input image for the export modules Clipping of the input image. Changing the aspect ratio of the 1) output. Clipping of the 2) output. Used Options: The first clipping is defined by the option '-j top[,left[,bottom[,right]]]' if you don't specify all parameters, they will be assumed to be symmetric to the others. -j 80 is expanded to -j 80,0,80,0 (top,left,bottom,right) -j 80,8 is expanded to -j 80,8,80,8 -j 80,8,10 is expanded to -j 80,8,10,8 Changing the aspect ration can be done in 3 ways: (fast) shrinking the image with option '-B n[,m]' (fast) expanding the image with option '-X n,[m]' (high quality) resizing with option '-Z wxh' The 2nd clipping is defined by the option '-Y top[,left[,bottom[,right]]]' if you don't specify all parameters, they will be assumed to be symmetric to the others. Examples on Usage: Input data '16:9' 'widescreen' DVD data, output data should have 4:3 aspect ratio without black border. Analyze the input data, we assume a black border at the top and bottom of 66 pixel in a 720x576 pixel frame. Using the fast resizing option -B, shrinking the height to reach a correct aspect ratio: '-j 32,0 -B 4,0 -Y 24,0' Final image size: 720x336 Pixel Using the fast resizing options -X and -B, removing 1% at the left&right border, expanding the image width to PAL resolution, and shrinking the height to reach a correct aspect ratio: '-j 32,8 -X 0,2 -B 3,0 -Y 24,0' Final image size: 768x368 Pixel Using the fast -X resizing, expanding the image width, but removing 3% of the image at the left and the right border: '-j 64,24 -X 0,7' Final image size: 896x448 Pixel Using the slower -Z resizing, expanding the image width to PAL resolution: '-j 68,0 -Z 768x360' Final image size: 768x360 Pixel Using the slower -Z resizing, 800 Pixel image width: '-j 66,0 -Z 800x368' Final image size: 800x368 Pixel Using the slower -Z resizing, expanding the image width: '-j 64,0 -Z 960x448' Final image size: 960x448 Pixel Input data '16:9' DVD data without black borders, output data should have 4:3 aspect ratio. Using the fast resizing option -B, shrinking the height to reach correct aspect ratio: '-B 4,0' Final image size: 720x448 Pixel Using the fast -X resizing, expanding the image width, but removing 3% of the image at the left and the right border: '-j 0,24 -X 0,7' Final image size: 896x576 Pixel Using the slower -Z resizing, expanding the image width to PAL resolution: '-Z 768x472' Final image size: 768x472 Pixel Using the slower -Z resizing, 800 Pixel image width: '-Z 800x480' Final image size: 800x480 Pixel Using the slower -Z resizing, expanding the image width: '-Z 960x576' Final image size: 960x576 Pixel

pass-through modes
This section is devoted to the pass-through modes available, which maybe useful for some, not so common situations as outlined below. ### replacing audio ### creating video clips Suppose you have mastered a couple of DV clips, concatenated to a well defined playtime "clip1.avi" that accidently correspond to the length of your favorite music clip "clip2.mp3" in MP3 format. We want to keep the quality of the video and simply replace the PCM audio track. This is done by the following command:
transcode | -i clip.avi -p clip.mp3
| -P 1
|  | -o new_clip.avi -y raw

Note: The MP3 stream must be identified by tcprobe. If this fails, we need to supply the import module options "-x dv,mp3" to make sure, the audio is decoded properly. The "-y raw" export module simply writes the video chunks as is together with the re-encoded audio. MP3 pass-through, similar to AC3 pass-through with options "-A -N 0x2000" is not yet available.

### audio recompression

The following situation is not uncommon. Suppose your single AVI-file "movie128.avi" is about 2x700MB+15MB, i.e., too large to fit on 2 CD's. Fortunately, the audio is MP3 with a bitrate of 128kbps, which is the default. We recompress the audio to 96kbps to reduce the filesize below 2x700MB. Let's also double the volume of the sound, if possible, or use the recommended value given by tcscan.

transcode | -i movie128.avi
| -P 1 -b 96 -s 2.0
|  | -o movie96.avi -y raw

This is reasonable fast since video is only passed through and the audio quality is still ok. After you are done, use avisplit to split the file into 2 chunks.

### fixing truncated AVI files

The AVI file header is updated (written to disk), whenever video/audio parameter are set. If transcode or hardware crashes, the truncated file is in most cases playable for advanced players. Repairing the AVI-file index is also possible via pass-through option "-P3".

transcode -i crashed.avi -o new.avi -P3 -u X

Option "-u X" with X>>10 enhances pass-through speed.

audio only conversion
Audio only conversion is also possible with transcode. Certainly, there are tons of tools out there, doing the same job, so I will concentrate on useful examples, mainly DVD ripping and encoding on the fly, using options "-p" for input and "-m" for output. ### audio track -> MP3 Some DVDs have a separate AC3 (Dobly Digital) film soundtrack, which you might want to convert to MP3. Music DVDs have tracks with uncompressed audio which is LPCM format (linear PCM), you want to archive. In this particular case, you might need to add "-d" for audio byte swapping. You need to check with tcprobe which audio track is the right one. We do it in 1 step for track 2 and write to the file "track.mp3":
transcode | -p /dev/dvd/ -T 1,-1 -a 2
|  | -y raw -m track.mp3

### audio track -> PCM

If you prefer uncompressed PCM data for further processing, add "-N 0x1" in the command above:

transcode | -p /dev/dvd/ -T 1,-1 -a 2
|  | -y raw -m track.pcm -N 0x1

### ASF audio -> MP3

I had this ASF (advanced stream format) Genesis audio file lying around and tried the avifile import module. Since no auto-probing is available for ASF streams in the current version, you must play around with the sample rate. CD quality is 44100 Hz samplerate:

transcode | -p carpet_crawler_1999.asf -x null,af6
| -e 44100 -E 44100 -b 112
|  | -y null,raw -m carpet_crawler_1999.mp3

AVI-files with multiple audio tracks
- ### HowTo: Before you start, try to find the best bitrate for video encoding with multiple audio tracks by using tcprobe with option "-b n*128", for example, if you want n MP3 audio tracks with 128kbps bitrate each. A first session produces the file movie.avi with a single audio track "-a 0". Now, we use a similar command to extract a second audio track from the source. Suppose, we used the example modules "vmod,amod" for video and audio extraction. The second session goes as follows. This session will be much faster, since no video is de/encoded. (1) transcode the second audio track "-a 1" into an AVI container file named add-on.avi This looks like:
  transcode -i (...) -x null,amod -g 0x0 -y raw -a 1 -o add-on.avi -u 50
- The resulting file is only a temporary file but enables proper processing with avimerge. The export module "-y raw" is fine, since it writes proper (0 bytes) video frames. Set video import module to "null". If all goes well, both files should be identical with respect to the number of frames. Choose the proper audio track with "-a". Try also to increase the internal buffers "-u" for speedup. (2) merge this track into movie.avi
  avimerge -i movie.avi -o dualaudiomovie.avi -p add-on.avi
(3) Repeat steps (1-2) for even more audio tracks, if you wish. For best results, I recommend doing this procedure with a single AVI movie file. All avi* post-processing tools now support multiple audio tracks. --- Note: transcode supports reading from multiple-audio tracks but only writes (exports) to single audio/video AVI-files.

Last modified: Thu May 16 12:59:16 CEST 2002