HOWTO Create an SVCD with MPEG Multichannel Sound

Software Requirements

For the transcoding process you need the following software:

You can find information about these packages in my Software section.

The Transcoding Process

The transcoding process is the more or less the same as described in HOWTO create SVCDs from DVB recordings. The only difference is in the handling of the audio stream, since we now have AC3 audio as the input:

  1. for i in 1 2 3 4 5 ; do \
      (extract_ac3 $i.vdr -s 1 > $i\_de.ac3);
    done
    

    Extract the Dolby Digital (AC3) streams from the MPEG program streams (VDR files) and write to files 1_de.ac3 ... 5_de.ac3.

  2. for i in 1 2 3 4 5 ; do \
      export AC3_6CH=$i\_en; \
      ~/src/ac3dec-010404-6chout/ac3dec -o null $i\_de.ac3; \
    done
    

    Take AC3 files, decode them, and write the PCM files. For each AC3 file, e.g. 1_de.ac3, six files 1_de_xx.ac3 are written where x is c (center), l (front left), lfe (low-frequency effect), ls (left surround), r (front right), rs (right surround), respectively.

    Note that you need my patched version of ac3dec to obtain the six-channel write feature.

  3. for i in *.pcm; do \
      sox -t raw -r 48000 -s -w -c 1 $i -t raw -r 44100 -s -w -c 1 $i.44; \
    done
    

    This step resamples each PCM file from 48000 Hz to 44100 Hz sampling rate (needed for compliant SVCDs).

  4. rm *.pcm
    for i in *.44; do mv $i ${i%.44}; done
    

    This deletes all 48000 Hz PCM files and renames the 44100 Hz files.

  5. ~/src/dist10/tool/pcm2aiff/pcm2aiff2 "1_de" -c5 -r0
    

    This line takes the 1_de_c.pcm ... 1_de_rs.pcm files as input and combines them into a single AIFF file suitable for the MPEG encoder.

  6. export MPEGTABLES=~/src/dist10/mc/encoder/tables
    ~/src/dist10/mc/encoder/musicin -b 224 -m s -n d -o -L -e 1_de.aiff
    

    This encodes the AIFF file into a MPEG layer 2 multichannel 3/2.1 stream. You should not go below a bitrate of 224 kbit/s.

You can use my transcode_mc.sh script to automate this tedious process. Note that there are some configurable parameters at the beginning of this script:

Note: You also need my split_pcm program for this script.

The resulting MPEG audio stream can then be multiplexed as described in HOWTO create SVCDs from DVB recordings. Since MPEG multichannel audio is backwards-compatible to regular MPEG layer 2 audio the SVCD should play back on every player that can play SVCDs. My Onkyo receiver recognizes the audio as being MPEG 3/2.1 when it comes via S/P-DIF.

Variations Without VDR

If you have gotten your MPEG program streams from some other source and not from VDR (or you don't like to modify and restart VDR every time), you can use the mpeg3split and mpeg3cat programs from mpeg2_movie/libmpeg3 to first concatenate your elementary video or audio streams and then split them again (you need my patched mpeg3split for files larger than 2 GB). The steps would be for the video part:

  1. for i in 1 2 3 4 5; do \
      (~/src/dvb-cvs/DVB-0.8/apps/mpegtools/pes2vid_es video_ps_$i.mpg > $i.mpg); \
    done
    

    This takes the files video_ps_1.mpg ... video_ps_2.mpg and extracts the elementary video streams into separate files. Read mpegtools/README for information on how to obtain pes2vid_es.

  2. mpeg3cat 1.mpg 2.mpg  ... > es_video.mpg
    

    This concatenates the elementary video streams into one file. The resulting file may be larger than 2 GB, so make sure that your filesystem supports this (ext2 with a Linux 2.4.1 kernel works for me).

  3. ~/src/mpeg2_movie-1.5/libmpeg3/mpeg3split -b 1308957000 es_video.mpg
    

    Use mpeg3split to create evenly sized elementary video streams (you need my patched version with large file support). These can then be transcoded to SVCD format. The transcoding process (i.e. the mplex program) gives you information on the number of video frames in each elementary video stream. You should record this information as it is needed to properly cut the audio streams.

Now we come to splitting the audio for MPEG multichannel encoding. You should already have created the PCM files with 44100 Hz sampling rate. Now follow these steps:

  1. cat 1_de_l.pcm ... 5_de_l.pcm > de_l.pcm
    ...
    cat 1_de_rs.pcm ... 5_de_rs.pcm > de_rs.pcm
    

    Combine individual PCM files into 6 PCM files for each channel.

  2. The de_x.pcm files need to be split again so that they match the elementary video streams in playback duration. Suppose the first video stream has 55600 frames, then each 1_de_xx.pcm file should have the size 55600/25*2*44100 = 196156800 bytes. Explanation: 55600/25 is the playback duration of the video in seconds. Each second has 44100 samples of audio with 2 bytes length. Use UNIX tools like head and tail to split the PCM files.

Now you can create the AIFF file and encode it to MPEG multichannel.

After the final multiplex step you should be especially careful to check synchronization of audio and video (e.g. with xine, before writing to CD-R). If there is a problem you can re-multiplex with a different delay by giving the -v xxx or -a yyy options to mpegtools/mplex where xxx and yyy are the video and audio delays, respectively.



© 2001 Peter Hofmann
Last Update: 01.07.2001