Creating DVDs from video files
Who needs HD?
Do you remember DVDs? Little plastic discs that are always in the wrong case, containing amazingly detailed versions of your favourite movies? Today we are going to figure out how to convert your old movies and burn them to a DVD in order to watch them on an ordinary standalone DVD player.
The web already contains tons of useful information on this; unfortunately a lot of it is outdated, incomplete or just plain wrong. Or written by weird people that want to create NTSC DVDs even though devices in civilized countries prefer PAL. Despite all that, I have to link to Ruh's Linux Powered DVD Production Guide and the entry on how to convert any movie to DVD video on the ArchWiki: both articles are excellent and I stole borrowed a lot from them.
So let's try to use all that information to write your old family videos to a DVD.
Softare
We are going to need some tools. All the applications involved are free software and should be available on any modern computer. This is what we need:
- ffmpeg, I used version n4.3.1
- mplex from the mjpegtools, I used version 2.2.0beta
- tcextract from the transcode package, I used version 1.1.7
- dvdauthor, I used version 0.7.2
- genisoimage from the cdrkit package, I used Version 1.1.11
... and of course an operating system. I used Parabola GNU/Linux for the job.
How it's done
Each video file we want on our DVD needs to go through the same three steps:
- Convert the audio track to a DVD format
- Convert the video track to a DVD format
- Combine the converted audio and video tracks to a new video file
When we are done, we can build an ISO image from the converted files and burn the image to a DVD. In the following examples, the original video file will be called file.mkv
.
Converting the audio track
For the DVD image, we need an AC-3 audio track. One might expect the audio track to be converted automatically when we convert the video track later on but unfortunately the current version of ffmpeg
does not appear to do that. Luckily it's not complicated:
$ ffmpeg -i file.mkv -map 0 -vn -sn -acodec ac3 file.ac3
This creates a new file called file.ac3
in the correct format. Check.
Converting the video track
This step is a bit more involved. In order to be able to merge the video files into a DVD image, we need the files to use the MPEG-ES format. Unfortunately I failed to create such a file directly with ffmpeg
, thus we are going to do this in two steps.
First we convert the existing video file to a format that is suitable for a DVD – luckily, ffmpeg
has presets for that. We need to specify that we want a video with 25 frames per second, otherwise the DVD player might not like it; you may want to change the 4:3 aspect ratio to match your video file (or not specify it at all):
$ ffmpeg -i file.mkv -an -f mpeg1video -vcodec mpeg2video -target pal-dvd -r 25 -aspect 4:3 file.mpg
That's going to take a while. Once it's done, we should have an MPEG video file (-f mpeg1video
) using the MPEG2 codec (-vcodec mpeg2video
) without audio (-an
) for PAL DVDs (-target pal-dvd
) with 25 frames per second (-r 25
) and a 4:3 aspect ratio (-aspect 4:3
). We can use that to extract the elementary stream that we need:
$ tcextract -i file.mpg -x mpeg2 > file.m2v
That's it. We're getting closer.
Combining the audio and video tracks
We now have separate audio and video tracks and would like to multiplex these into a complete file with both, audio and video. This is how we do it:
$ mplex -f 8 -M -o file.dvd file.m2v file.ac3
The option -f 8
specifies that we want to create a DVD.
Now our file is ready. If we want to add further video files to the DVD, now is the time to repeat these commands for all of them. I'll be waiting.
Creating a DVD image
Once our video files are ready, we can create a DVD image. We are not going to use a DVD menu and we will configure the individual video files to be chapters on the DVD, that way we can easily jump from one video to the next.
Nothing says "nineties" quite like XML, so it makes perfect sense that in order to create a DVD, we first need to write an XML file that defines the DVD's contents:
<dvdauthor>
<titleset>
<titles>
<pgc>
<vob file="file.dvd" />
</pgc>
</titles>
</titleset>
</dvdauthor>
We need a <vob ...>
line for each video file. This could look something like this:
<dvdauthor>
<titleset>
<titles>
<pgc>
<vob file="file1.dvd" />
<vob file="file2.dvd" />
<vob file="file3.dvd" />
<vob file="file4.dvd" />
<vob file="file5.dvd" />
</pgc>
</titles>
</titleset>
</dvdauthor>
We save this as dvd.xml
. Afterwards the following command uses the XML file to create a directory structure for the DVD:
$ VIDEO_FORMAT=PAL dvdauthor -o dvd -x dvd.xml
This creates a new directory called dvd
. If the directory already exists, the new contents are simply copied into the existing directory; this can create a bit of a mess and I would recommend removing the old directory first.
In addition to that, the DVD player needs a table of contents, otherwise it won't know what to play. This command creates just that, again in the dvd
directory:
$ VIDEO_FORMAT=PAL dvdauthor -o dvd -T
Now everything is in place and we can create an ISO image:
$ mkisofs -dvd-video -udf -o dvd.iso dvd/
And we're done. We now have an image that can be written to a DVD.
Checking the image
We could just write this to a DVD now and hope for the best. On the other hand, we could also try to verify that our image works correctly before potentially wasting a DVD-R.
The first thing we can try is VLC:
$ vlc dvd.iso
VLC should open the image and immediately start playing the first movie. The chapter selection in the playback menu should list all movies on the DVD and they should all be playable. Now we can also verify that the audio track is in sync with the video track.
The "codec information" dialog in VLC's "tools" menu allows us to verify that our videos have been correctly converted. It might look something like this:
VLC is smarter than your average DVD player and plays pretty much anything that resembles a video file; to be sure that our image really works, we have to write it to an actual, physical disc and try that in our DVD player. Ideally we would have a rewritable DVD-RW disc – that way we could tweak the parameters all day long without wasting DVDs.
Unfortunately my DVD writer does not support rewritable media, so I don't own any. Many standalone DVD players do however support cDVDs, also known as "mini-DVDs". These are plain old CDs that contain DVD data. Any old CD-RW can be turned into such a mini DVD and fits about 30 minutes of DVD-quality video; more than enough for a quick test. My Philips DVP3980 supports these discs and will play them just like normal DVDs.
Burning the DVD
Compared to the excitement of converting between various video formats, burning the actual disc is rather boring. No matter whether it's a DVD or a simple CD-RW, just type:
$ cdrecord -v dvd.iso
After a few relaxing minutes you are ready to watch your freshly burnt DVD. Enjoy the nineties.
Automating the boring stuff
Typing all these commands by hand (or even just copying them from this page) is too much work for any moderately lazy person, so I wrote a little Makefile
that converts all .mkv
files in a directory and merges them into a DVD image. make
is a bit sensitive concerning file names though, you might want to clean them first:
$ for file in *.mkv ; do mv -i "${file}" "$(echo ${file} | sed -e 's/[^A-Za-z0-9._-]/_/g')" ; done
Afterwards just put the Makefile in the same directory as your video files and let the computer do all the dirty work:
$ wget -q https://www.ott.net/creating-dvds-from-video-files/Makefile $ make
This is going to take a while. Use the time to prepare a healthy snack.