1) Accomplish transferring a video media file (.avi, .mpg, .wmv, .mov, .mkv, .ogm, etc.) to DVD media in a format that will allow it to be played on a standalone DVD player.
2) Create professional style menus with audio to allow selection of Titles, Chapters and other menus.
To make things easier to read, we'll be using some real filenames, always keeping them with any created files and saved config files in the same directory.
For the purpose of the exercise, 2 video files have been downloaded for free from www.matrix-xp.com and renamed to 'matrix.avi' and 'outtakes.avi'.
We'll also be using the THX theme at the start of the DVD and have named this 'thx.mpg'.
Note any copyright issues for your location if you intend to use these for anything other than private use.
transcode -i matrix.avi \ -y ffmpeg \ --export_prof dvd-pal \ --export_asr 3 \ -o matrix \ -D0 \ -s2 \ -m matrix.ac3 \ -J modfps=clonetype=3 \ --export_fps 25
transcode -i outtakes.avi \ -y ffmpeg \ --export_prof dvd-pal \ --export_asr 3 \ -o outtakes \ -D0 \ -s2 \ -m outtakes.ac3 \ -J modfps=clonetype=3 \ --export_fps 25
transcode -i thx.mpg \ -y ffmpeg \ --export_prof dvd-pal \ --export_asr 3 \ -o thx \ -D0 \ -s2 \ -m thx.ac3 \ -J modfps=clonetype=3 \ --export_fps 25
transcode -i matrix.avi \ -y ffmpeg \ --export_prof dvd-ntsc \ --export_asr 3 \ -o matrix \ -D0 \ -s2 \ -m matrix.ac3 \ -J modfps=clonetype=3 \ --export_fps 29.97
transcode -i outtakes.avi \ -y ffmpeg \ --export_prof dvd-ntsc \ --export_asr 3 \ -o outtakes \ -D0 \ -s2 \ -m outtakes.ac3 \ -J modfps=clonetype=3 \ --export_fps 29.97
transcode -i thx.mpg \ -y ffmpeg \ --export_prof dvd-ntsc \ --export_asr 3 \ -o thx \ -D0 \ -s2 \ -m thx.ac3 \ -J modfps=clonetype=3 \ --export_fps 29.97
The above will produce 6 files, 'matrix.m2v', 'matrix.ac3', 'outtakes.m2v', 'outtakes.ac3', 'thx.m2v' and 'thx.ac3' which have been split from the original into video and audio files. The video(.m2v) has now been re-encoded into a DVD compliant mpeg2 format and the audio(.ac3) has been encoded into an AC3 DVD audio stream.
The above transcode lines will convert and encode to an aspect ratio of 16:9. If an aspect ratio of 4:3 is desired then replace '--export_asr 3' with '--export_asr 2' in your transcode line. Dvdauthor will only work correctly on files with aspect ratios of either 4:3 or 16:9.
Convert 2-channel stereo audio track to 5.1 surround sound (optional)
Using the above transcode lines will result in a 2-channel stereo audio track.
Depending on the brand of 5.1 surround sound entertainment system, this may result in the audio only being present on the centre and sub channels.
Find out if the original .avi/.mpg file already contains a 5.1 AC3 audio track:
mplayer -vo dummy -identify original.avi 2> /dev/null | grep 5.1
A positive output would look something like:
AC3: 5.1 (3f+2r+lfe) 48000 Hz 384.0 kbit/s
If it does, then extract it using 'tcextract' (part of the transcode package) and use it in your mplex line below instead. In this way, front to rear panning will not be lost on true 5.1 audio tracks, and no added conversion is necessary:
tcextract -d2 -i matrix.avi -a0 -x ac3 | tcextract -d2 -x ac3 -t raw > matrix.ac3
If it doesn't, then using the existing 2-channel audio track, it is possible to create a 5.1 surround sound track so that the audio will be present on all 6 channels (front to rear panning is lost).
See here -> http://mightylegends.zapto.org/dvd/dvdauthor_howto_surround.html
Combine the new audio and video files into one DVD mpg
mplex -f8 -o matrix_dvd.mpg matrix.m2v matrix.ac3 mplex -f8 -o outtakes_dvd.mpg outtakes.m2v outtakes.ac3 mplex -f8 -o thx_dvd.mpg thx.m2v thx.ac3
Test the files in mplayer or xine. eg. 'mplayer -vo xv matrix_dvd.mpg'
Add subtitles using a subtitle file.
There are many different subtitle file formats (.sub (MicroDVD), .srt, .ssa, .smi, .rt, .txt, .aqt, .jss, .js, .ass), for this exercise we're using the .srt format.
The .srt format has the following syntax:
1 00:00:04,700 --> 00:00:06,736 The weather is nice today
2 00:00:06,900 --> 00:00:09,494 Yes it is but not as nice as yesterday
It represents a time span in 'hours:minutes:seconds,milliseconds' to show the subtitle text.
Here is one created for matrix.avi -> http://mightylegends.zapto.org/dvd/matrix.srt
Make a directory in your home directory called '.spumux/', then copy the Vera.ttf font from your xorg/xfree fontpath to ~/.spumux/
Font does not have to be Vera.ttf, can be any other TrueType Font (.ttf), if the font is changed then also edit the subtitle.xml file below.
Use spumux to merge the subtitle text into the DVD video.
Spumux is part of the dvdauthor package. It is configured via an .xml file. Here is the xml config file we will use, save it as 'subtitle.xml':
File: <subpictures> <stream> <textsub filename="matrix.srt" characterset="ISO8859-1" fontsize="18.0" font="Vera.ttf" horizontal-alignment="center" vertical-alignment="bottom" left-margin="60" right-margin="60" top-margin="20" bottom-margin="30" subtitle-fps="25" movie-fps="25" movie-width="720" movie-height="570"/> </stream> </subpictures>
Specified 'subtitle-fps', 'movie-fps', 'movie-width' and 'movie-height' are important.
If you are using NTSC, then it will be 'subtitle-fps="29.97" movie-fps="29.97" movie-width="720" movie-height="472"'
DVDAuthor supports both textual and graphical forms of subtitles, but if using a graphical format, the process becomes more involved.
The user must first extract and prepare the subtitle images for each dialog using a tool such as 'vobsub2pgm' that is contained in the 'subtitleripper' suite of tools, located here -> http://subtitleripper.sf.net
Then create an spumux.xml file that looks something like this:
In this example, 'Matrix0001.png' is an image of the dialog "The weather is nice today", and 'Matrix0002.png' is an image of the dialog "Yes it is, but not as nice as yesterday", the xoffset/yoffset tags are used to position where the image will be placed on the 720x576/480 TV canvas.
File: <subpicture> <stream> <spu image="Matrix0001.png" start="00:00:4.7" end="00:00:6.7" xoffset="178" yoffset="480" /> <spu image="Matrix0002.png" start="00:00:6.9" end="00:00:9.5" xoffset="178" yoffset="480" /> </stream> </subpicture>
To make things easier, here is a script that automates the extraction of the subtitle images (using 'vobsub2pgm') and creates an spumux.xml file with the images, timestamps and offsets -> http://mightylegends.zapto.org/dvd/vobsub2spumux.sh
Merge the subtitles into the DVD video:
spumux -s0 subtitle.xml < matrix_dvd.mpg > matrix_dvd.mpg.temp mv matrix_dvd.mpg.temp matrix_dvd.mpg
If multiple subtitles are needed, then for each subtitle stream, increment spumux's '-s' value by 1
(eg. 'spumux -s3 subtitle.xml < matrix_dvd.mpg > matrix_dvd.mpg.temp' to add the 4th subtitle stream).
If different subtitle colours other than the default grey are desired, then it is necessary to patch the dvdauthor-0.6.11 source and re-compile.
Patch available here -> http://mightylegends.zapto.org/dvd/dvdauthor-0.6.11_subtitle_colours.diff
Apply the patch:
patch -p1 < /path/to/dvdauthor-0.6.11_subtitle_colours.diff
Then re-compile dvdauthor.
Create a palette.rgb file specifying the text outline and text colours in RGB hex:
File: 000000 ffff00
The first hex code is the text outline colour (black), the second hex code is the text colour (yellow).
A full list of supported colours and their relevant RGB hex codes can be found in /usr/share/doc/ImageMagick-<version>/www/color.html
Adjust the dvdauthor.xml file mentioned below like so:
File: <titles> <subpicture lang="en"/> <pgc palette="palette.rgb"> <vob file="matrix_dvd.mpg" chapters="0,0:30,1:00,1:30,2:30,3:00,3:30,4:00"/>
File types other than AVI or MPEG
Note: I think the author intended the
following as a workaround to tcprobe being unable to
handle the filetypes. Rather than do all this, I
think that the scripts found HERE will do the
For file types other than .avi/.mpeg, such as .wmv, .mov, .asf, .mkv, .ogm and .bin (S)VCD etc. it's necessary to first encode the movie to .avi with mencoder, like this:
mencoder -o output_file.avi \ -ovc lavc \ -lavcopts vbitrate=5000 \ -fourcc DX50 \ -oac pcm \ -srate 48000 \ -ofps 25 your_movie.mov
mencoder -o output_file.avi \ -ovc lavc \ -lavcopts vbitrate=5000 \ -fourcc DX50 \ -oac pcm \ -srate 48000 \ -ofps 29.97 your_movie.mov
Then proceed as normal with the above transcode line.
If transcode errors out and refuses to encode your file, use mplayer to feed the file to transcode like this:
transcode -i matrix.avi \ -x mplayer,mplayer \ -y ffmpeg \ --export_prof dvd-pal \ --export_asr 3 \ -o matrix \ -D0 \ -s2 \ -m matrix.ac3 \ -J modfps=clonetype=3 \ --export_fps 25
Remember that you can preview the .m2v file with mplayer or xine while it is still being encoded with transcode. No need to wait until encoding is completely finished before seeing the result, handy for very large movies.
Alternatively, transcode has a preview option available so that the movie can be watched (video only) as it's being encoded with the '-J pv=cache=30' option, like so (note that this will incur a slight performance hit and encoding will be slower as a result):
transcode -i matrix.avi \ -y ffmpeg \ --export_prof dvd-pal \ --export_asr 3 \ -o matrix \ -D0 \ -s2 \ -m matrix.ac3 \ -J pv=cache=30,modfps=clonetype=3 \ --export_fps 25
To preview whether AV sync is going to be correct, only encode a small amount of the movie by adding '-c 0-00:05:00' to the end of your transcode line. This will encode just the first 5 minutes of the movie, then you will need to merge(mux) the two AV streams as mentioned above using mplex. Preview the resultant .mpg file in mplayer/xine.
The video quality does suffer, but not in a visually noticeable way. Quality will always be subjective, but for my eyes I can only really see a difference when viewing on a PC while TV playback quality is still superb (your mileage may vary, depends greatly on the quality of the original file).
As --export_prof is not used, some ffmpeg options need to be manually set, save the settings in a file called 'ffmpeg.cfg':
File: [mpeg2video] vrc_minrate=0 vrc_maxrate = 7000 vrc_buf_size = 1792
The following transcode lines do both, reduce the resolution and video bitrate (by not using '--export_prof dvd-*', transcode's video bitrate defaults to 1800 kbits/s).
transcode -i matrix.avi \ -y ffmpeg \ -F mpeg2 \ -Z 352x288 \ --export_asr 3 \ --encode_fields t \ -o matrix \ -D0 \ -E 48000,16,2 \ -b 224 \ -N 0x2000 \ -s2 \ -m matrix.ac3 \ -J modfps=clonetype=3 \ --export_fps 25
transcode -i matrix.avi \ -y ffmpeg \ -F mpeg2 \ -Z 352x240 \ --export_asr 3 \ --encode_fields b \ -o matrix \ -D0 \ -E 48000,16,2 \ -b 224 \ -N 0x2000 \ -s2 \ -m matrix.ac3 \ -J modfps=clonetype=3 \ --export_fps 29.97
Set the video bitrate manually by using '-w', eg. add '-w 3000' to your transcode line if a video bitrate of 3000 kbits/s is desired.
One major drawback of reducing the resolution is that transcode's '--export_prof' option cannot be used, so if an aspect ratio conversion is necessary, we lose the benefits of auto pre_clip/zoom which '--export_prof' provides.
You will know an aspect ratio conversion is necessary if the encoded output file's video is squashed/stretched using the above transcode lines.
An easy way around this is to do a dummy run using '--export_prof' on the input file and let transcode do the calculations, like so:
transcode -i matrix.avi \ -y ffmpeg \ --export_prof dvd \ --export_asr 3 \ -c 0-00:00:00 2>&1 | grep "pre clip frame"
An example output would look something like:
[transcode] V: pre clip frame | 512x384 (-48,0,-48,0)
It is the values in brackets that we need. Using those values we can now convert the aspect ratio like this: For PAL:
transcode -i matrix.avi \ -y ffmpeg \ -F mpeg2 \ -Z 352x288 \ --export_asr 3 \ --encode_fields t \ -j -48,0,-48,0 \ -o matrix \ -D0 \ -E 48000,16,2 \ -b 224 \ -N 0x2000 \ -s2 \ -m matrix.ac3 \ -J modfps=clonetype=3 \ --export_fps 25
transcode -i matrix.avi \ -y ffmpeg \ -F mpeg2 \ -Z 352x240 \ --export_asr 3 \ --encode_fields b \ -j -48,0,-48,0 \ -o matrix \ -D0 \ -E 48000,16,2 \ -b 224 \ -N 0x2000 \ -s2 \ -m matrix.ac3 \ -J modfps=clonetype=3 \ --export_fps 29.97
Creating the menus
Open up The Gimp and make a new image of size 720×576, with a resolution of 75dpi in the x-axis and 80dpi in the y-axis.
Make a new image of size 720x480, with a resolution of 81dpi in the x-axis and 72dpi in the y-axis.
Right click on the image, select Image -> Alpha -> Add channel.
Right click on the image, select image -> Layers -> Layers, Channels and Paths
Create a layer called 'button_highlight'.
Create a layer called 'button_select'.
Select the background layer and draw the menu background.
I chose to use the matrix 'green data dribble' as the background, which I downloaded from a free wallpaper website.
Scaled the image to the correct 720x576, right click image -> Image -> Scale Image and set. Then copy/pasted it into the background layer of my new image.
I wanted to have selectable snapshots of each movie in the menu.
Snapshots were taken using xine, images were scaled using gimp, then pasted into the background layer.
Select the button_highlight layer and draw the button outlines. To see howto draw perfect rectangles, squares and circles in the gimp, see here -> http://mightylegends.zapto.org/dvd/gimp_circles-n-squares.html
Hide the button_highlight layer and save the background layer.
Do this by selecting the button_highlight layer and using the Opacity slider in the Layers, Channels and Paths dialog box to make it disappear.
Click on the background layer, right click on the image, select File -> Save as
Save background layer as 'matrix_menu_background.jpg' (can be almost any image format).
Save the button_highlight layer in the same way. Use the opacity slider to bring the button_highlight layer back up, and hide the background layer.
Click on the button_highlight layer, right click on the image, select File -> Save as
Save button_highlight layer as 'matrix_menu_highlight.png'.
(NOTE - Button layer MUST be a .png)
Select the button_select layer and draw the button outlines exactly the same as button_highlight, but in a different color. An easy way to do this is to open matrix_menu_highlight.png, right click image, select Image -> Colors -> Color map rotation, set the colour to something different, but that will still be visible against the menu background colour.
Save new colour image as 'matrix_menu_select.png'.
(NOTE - MUST also be a .png)
Once your comfortable with the above, and everything is working, have a shot at creating an animated DVD menu.
See here -> http://mightylegends.zapto.org/dvd/dvdauthor_howto_animenu.html
Putting it all together
Convert the menu background into a DVD .mpg.
convert matrix_menu_background.jpg ppm:- | ppmtoy4m -n50 -F25:1 -A59:54 -I p -r -S 420mpeg2 | mpeg2enc -n p -f8 -b5000 -a3 -o matrix_menu_background.m2v
convert matrix_menu_background.jpg ppm:- | ppmtoy4m -n50 -F30000:1001 -A10:11 -I p -r -S 420mpeg2 | mpeg2enc -n n -f8 -b5000 -a3 -o matrix_menu_background.m2v
Create some background audio for the menu:
ffmpeg -i your_music_file.mp3 -f wav menu_audio.wav
Use 'normalize' to make audio softer/louder if necessary:
normalize -a -10dB menu_audio.wav
Convert to AC3 audio:
ffmpeg -i menu_audio.wav -ab 224 -ar 48000 menu_audio.ac3
If you do not want any audio present in your menu, it is still necessary to create a silent audio file for mplex so the DVD menus will work correctly. Like this:
dd if=/dev/zero bs=4 count=99999 | sox -t raw -wsr 48000 - -t wav -r 48000 - | ffmpeg -i - -ab 224 -ar 48000 -ac 2 menu_audio.ac3
Merge background menu video/audio:
mplex -f8 -o matrix_menu.mpg matrix_menu_background.m2v menu_audio.ac3
Use spumux to merge button_highlight and button_select images into the menu video. Here is the xml config file we will use, save it as 'spumux.xml':
File: <subpictures> <stream> <spu start="00:00:00.0" end="00:00:00.0" highlight="matrix_menu_highlight.png" select="matrix_menu_select.png" autooutline="infer" autoorder="rows"/> </stream> </subpictures>
Create final menu .mpg:
spumux spumux.xml < matrix_menu.mpg > matrix_menu_final.mpg
A successful output should look something like this:
INFO: Picture had 2 colors INFO: Converting filenames to ANSI_X3.4-1968 INFO: Picture had 2 colors INFO: Picture had 2 colors INFO: Constructing blank img INFO: Autodetect 0 = 0x0-720x576 INFO: Pickbuttongroups, success with 1 groups, useimg=1 INFO: Found EOF in .sub file. INFO: Max_sub_size=4456 WARN: Read 0, expected 4 INFO: 1 subtitles added, 0 subtitles skipped, stream: 32, offset: 0.18
Authoring the DVD
Dvdauthor is configured via a .xml file. Here is the .xml config file we will use, save it as 'dvdauthor.xml':
File: <dvdauthor dest="DVD">
<vmgm> <menus> <video widescreen="nopanscan" /> <pgc> <vob file="thx_dvd.mpg"/> <post> jump titleset 1 menu; </post> </pgc> </menus> </vmgm>
<titleset> <menus> <video widescreen="nopanscan" /> <pgc> <button> jump title 1; </button> <button> jump title 2; </button> <vob file="matrix_menu_final.mpg"/> <post> jump cell 1; </post> </pgc> </menus>
<titles> <video widescreen="nopanscan" /> <pgc> <vob file="matrix_dvd.mpg" chapters="0,0:30,1:00,1:30,2:30,3:00,3:30,4:00"/> <post> call menu; </post> </pgc>
<pgc> <vob file="outtakes_dvd.mpg" chapters="0,0:30,1:00,1:30,2:30,3:00,3:30,4:00,4:30,5:00"/> <post> call menu; </post> </pgc> </titles>
For an explanation on what 'panscan' is, see here -> http://en.wikipedia.org/wiki/Pan_&_scan
Authoring with no menus
To create a more simple DVD with no menus or THX intro, use the dvdauthor.xml config below:
File: <dvdauthor dest="DVD"> <vmgm /> <titleset> <titles> <video widescreen="nopanscan" /> <pgc> <vob file="matrix_dvd.mpg" chapters="0,0:30,1:00,1:30,2:30,3:00,3:30,4:00"/> </pgc> <pgc> <vob file="outtakes_dvd.mpg" chapters="0,0:30,1:00,1:30,2:30,3:00,3:30,4:00,4:30,5:00"/> </pgc> </titles> </titleset> </dvdauthor>
Create a directory named 'DVD'. Create the DVD file structure with:
dvdauthor -x dvdauthor.xml
Test the new menus in xine before burning:
Xine should play from the folder as though it's playing from a DVD.
Understanding the hierarchical structure of a DVD
Menus can be associated with either the whole disk (VMGM=Video Manager Menu) or with a titleset (VTSM=Video Titleset Menu), there can be more than one menu of either type.
VMGM menus are typically used when selection of more than one VTSM in a different Titleset is required, as one VTSM cannot jump to another VTSM in a different Titleset.
A VTSM menu can only jump to:
My DVD player (and others?) defaults to the first VTSM when pressing the 'Disc' button on the remote. If this is the case, and you want to setup menu access to different VTSMs at the VMGM level, then you may need to setup the first VTSM like so:
<titleset> <menus> <pgc> <post> jump vmgm menu; </post> </pgc> </menus> <titles>....
So that pressing 'Disc' will take you to the VMGM Menu.
Create the DVD image and burn it
Use growisofs, part of the dvd+rw-tools package.
growisofs -Z /dev/dvd -dvd-video DVD/
Jerky video and skipping audio
This shouldn't happen, but here are some possible causes:
[mpeg2video] vrc_minrate=0 vrc_maxrate = 7000 vrc_bufsize=1792This will set an average video bitrate of 5000kbits/sec (using Transcode's default) but set a bitrate ceiling of 7000 kbits/sec (Transcode defaults to 9000kbits/sec).
Hopefully the DVD worked !
Here is a flow-chart diagram to aid in getting an overall view of the processes -> ["http://mightylegends.zapto.org/dvd_images/dvdauthor_howto.png"]
More sophisticated menus can be generated by having menus within menus within menus - this is a kickstart guide only, using 2 titles and chapters every 30 seconds.
It may seem complex and time consuming first time through, but once it's been done a couple of times it becomes very quick and easy.
Some nice progress is also currently being made on a complete GUI based DVD authoring tool for Linux.
Some that stand out are:
DVDStyler -> http://dvdstyler.sourceforge.net/
QDVDAuthor -> http://qdvdauthor.sourceforge.net/
KMediaFactory -> http://susku.pyhaselka.fi/damu/software/kmediafactory/