mjpeg-howto: Transcoding of existing MPEG-2
9 Transcoding of existing MPEG-2
********************************
For transcoding existing MPEG-2 streams from digital TV cards or DVD a
lower data-rate than for broadcast will give good results. Standard
VCD 1152 kbps typically works just fine for MPEG1. The difference is in
the Signal/Noise ratio of the original. The noise in the analog stuff
makes it much harder to compress.
One other very good guide that helps you transcoding videos can be
found at: http://www.bunkus.org/dvdripping4linux/index.html
You will also need to manually adjust the audio delay offset
relative to video when multiplexing. Very often around 150ms delay
seems to do the trick.
You have to download the ac3dec and mpeg2dec packages. You can find
them at mjpeg homepage ( http://sourceforge.net/projects/mjpeg ). You
also need sox and toolame.
In the scripts directory there is a `mpegtranscode' script that does
most of the work.
So transcoding looks like this:
`> mjpegtranscode -V -o vcd_stream mpeg2src.mpg'
`-V'
set's the options so that a VCD compatible stream is generated
`-o vcd_stream'
a vcd_stream.m1v (video) and vcd_stream.mp2 (audio) is created
`mpeg2src.mpg'
specifies the source stream
The script prints also something like this:
`> SYNC 234 mSec'
You will need to adjust the audio/video startup delays when
multiplexing to ensure audio and video are synchronized. The exact
delay (in milliseconds) that you need to pass to mplex to synchronize
audio and video using the "-v"" is printed by the extract_a52 tool
labeled "SYNC" when run with the "s" flag. This is the value th
mjpegtranscode script prints out after the `SYNC' word.
Then you need to multiplex them like this:
`> mplex -f 1 -O 234 vcd_stream.mp2 vcd_stream.m1v -o lowrate.mpg'
`-f 1'
Mux format is set to VCD
`-O 234'
Video timestamp offset in mSec, generated by the mjpegtranscoding
script, there negative values are allowed
`vcd_stream.mp2 & vcd_stream.m1v'
generated files by the script
`lowrate.mpg'
the VCD compatible output stream
Here we have a SVCD (MPEG-2 video) example:
`> mjpegtranscode -S -o svcd_stream mpeg2src.mpg'
You have to multiplex it with:
`> mplex -f 4 -O 234 svcd_stream.mp2 svcd_stream.m2v -o lowrate.mpg'
`Problem:' There is sometimes a problem with NTSC and VCD playback
because movies may be recoded with 3:2 pulldown NTSC with 60
fields/sec. mpeg2dec is designed for playback on computers and
generates the original 24frames/sec bitrate. If you encode the video
now 30frames/sec video is created. This video is now much too short for
the encoded audio.
The transcoding can be made to work but it must be done manually:
`> mpeg2dec -s -o pgmpipe mpeg2src.mpg | pgmtoy4m -a 59:54 -r 25:1
-i t | mpeg2enc -I 0 -f 4 -q 9 -V 230 -p -P -o svcd_stream.m2v'
The -p tells mpeg2enc to generate header flags for 3:2 pull down of
24fps movie. It may also work if you do not add the -p flag. You do
not need the -p flag when transcoding to VCD format because it is not
supported in mpeg1.
Menu