РУС|ENG

Articles & How-to's Brochures



www.media-kb - media knowledge base


All rights reserved (c) 2001-2007 NetUP Inc. (www.netup.tv)
Reprinting, republishing and any further distribution,
regardless of format, require written permission from NetUP Inc.

Transcoding Movies
from DVD's into MPEG Files

A script for transcoding movies from DVDs into mpeg files of a required format has been developed by NetUP Inc. The script and utilities work under Linux OS (Gentoo Linux). The script can be downloaded from the url: code_dvd.pl. The output video file format:

Video: definition: 480x576, ratio: 4:3, mpeg2 program stream, bitrate 4096 kbps, 25.00 fps
Audio: AC-3,  48000 Hz, stereo, 128 kb/s or MPEG Audio layer 2 (Audio: mp2, 48000 Hz, stereo, 128 kb/s)

MPEG Audio layer 2 is more preferred as it is supported by more software.

The script performs the following steps:

1. Dumps a required track and an audio track (en) from the DVD using mplayer[1]:

mplayer -dvd-device /dev/dvd -dumpstream -dumpfile Deja_vu.dump dvd://2 -alang en

The output file is Deja_vu.dump containing the full dump of the track (audio and video). These files can be prepared in advance using a PC with several DVD drives, and after that the transcoding can be done using several machines.

2. Then the obtained file is transcoded using transcode[2]:

transcode -i Deja_vu.dump -s 4 -Z 480x576 -F mpeg2 -y ffmpeg --no_split -o Deja_vu -N 0x50 --export_asr 2 -w 4096 --video_max_bitrate 4096 -m Deja_vu.mp2 --export_fps=25 -J fps=23.976:25

Video is transcoded with the resolution 480x576 and 4 Mbps bitrate into the Deja_vu.m2v file. Audio is transcoded into the Deja_vu.mp2 file as MPEG Layer 2 audio. Audio format can be set using the option -N 0x50. If -N 0x2000 is set, then audio is saved in AC-3 format. The parameters of audio and video can be changed as required. The given values were used because the output files were to be played using AmiNET 110 IP set-top-box. As VoD/nVoD server it was used NetUP VoD Server.

The option -J fps=23.976:25 must be set if the source video has a frame rate different from 25 fps.

3. Merges the obtained audio and video files (mplex tool from the media-video/mjpegtools[3] package is used):

mplex  -f 8 -o Deja_vu.mpg Deja_vu.m2v Deja_vu.mp2

The result is the final Deja_vu.mpg file containing both video and audio data in the format specified. The file can be checked using VLC. There should be no mistiming between audio and video. If the mistiming takes place, the file can be treated manually. For details see "Fixing a Mistiming Between Audio and Video".

Fixing a Mistiming Between Audio and Video
(if time stamps have been lost)

The mistiming happens if in the very beginning of the file video lasts for several seconds with no audio. This effect is processed correctly if time stamps (PTS/DTS) are saved. But if they are lost, the file can be corrected manually. For that several kbytes in the beginning of the video file can be cut (normally 20 to 200 kbytes).

The command to cut the file part is:

mpgtx -s -o hottabych_dvd.m2v.fixed hottabych_dvd.m2v [35k-]

In this example 35 kbytes of data is cut out in the beginning of the hottabych_dvd.m2v file, and the result is saved into the hottabych_dvd.m2v.fixed file.

Then video and audio are to be merged together using the command:

mplex  -f 8 -o hottabych_dvd.mpg hottabych_dvd.m2v.fixed hottabych_dvd.ac3

To check if the sync is ok, preview the hottabych_dvd.mpg file (it is not necessary to wait until the merging is fully processed). Often it is hard to guess the number of kbytes to be cut. In this case it is necessary to check (aurally) if there is any delay in the video (or audio). Usually this can be clearly seen in dialogs.

If audio is delayed, the part of the video file to be cut in the beginning is to be increased. The iteration is to be repeated until audio and video are synchronized (the mistiming becomes imperceptible).

References on the Internet:

  1. Mplayer project website - http://www.mplayerhq.hu
  2. Transcode project website - http://www.transcoding.org
  3. Mjpegtools project website - http://mjpeg.sourceforge.net/

Discuss this article on the forum...

 

Phone: +7 (495) 543-9220 (ext 0), email: info@netup.tv