Preamble
Three great virtues of a programmer; Laziness, Impatience and Hubris. – Larry Wall
- Laziness: The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful and document what you wrote so you don’t have to answer so many questions about it.
- Impatience: The anger you feel when the computer is being lazy. This makes you write programs that don’t just react to your needs, but actually anticipate them. Or at least pretend to.
- Hubris: The quality that makes you write (and maintain) programs that other people won’t want to say bad things about.
Some background and notes
Bitrate
DVD-Video discs have a raw bitrate of 11.08 Mbit/s, with a 1.0 Mbit/s overhead, leaving a payload bitrate of 10.08 Mbit/s. Of this, up to 3.36 Mbit/s can be used for subtitles, a maximum of 10.08 Mbit/s can be split amongst audio and video, and a maximum of 9.80 Mbit/s can be used for video alone. A DVD video can have up to 1536 kbps of audio information, but for each audio track the limit is 448 kbps. You can have mono, stereo or 5.1 audio tracks.
(average bitrate) * (movie length in seconds) = (total of bits)
And knowing how many bits you have in the DVD you can calculate your bitrate with great precision (see table below).
For example if you have a 2 hours movie (7200 seconds), a single 448 kbits per seconds audio track (usual value for 6 channels audio) and a DVD-R SL you might calculate:
37658558464 / 7200 - 448000 = 4782355
DVD disc capacity
Capacity differences of writable DVD formats
Type | Sectors | # of bits | Bytes | KiB | MiB | GiB | |
---|---|---|---|---|---|---|---|
DVD-R SL | 2,298,496 | 37658558464 | 4,707,319,808 | 4,596,992 | 4,489.250 | 4.384 | |
DVD+R SL | 2,295,104 | 37602983936 | 4,700,372,992 | 4,590,208 | 4,482.625 | 4.378 | |
DVD-R DL | 4,171,712 | 68349329408 | 8,543,666,176 | 8,343,424 | 8,147.875 | 7.957 | |
DVD+R DL | 4,173,824 | 68383932416 | 8,547,991,552 | 8,347,648 | 8,152.000 | 7.961 |
Note: All sizes are expressed in their binary sense (i.e. 1 Gigabyte = 1,073,741,824 bytes).
Bitrate budge calculation
The following is adapted from here.
The basic bitrate formula is:
( Size – ( Audio x Length )) / Length = Video bitrate
- L = Lenght of the whole movie in seconds
- S = Size you like to use in KB (note 700 MB x 1024 = 716 800 KB)
- A = Audio bitrate in KB/s (note 224 kbit/s = 224 / 8 = 28 KB/s)
- V = Video bitrate in KB/s, to get kbit/s multiply with 8.
- 8 bit = 1 byte.
- 1024 = 1 kilo in the computer world.
Example 90 minutes video, L = 90 x 60 = 5 400 seconds 700 MB CD but be sure that if fits use a bit lower like 695 MB, S = 695 x 1024 = 711 680 KB Audio bitrate, A = 224 kbit/s / 8 = 28 KB/s
(711 680 – (5400 x 28) ) / 5400 = 104 KB/s x 8 = 830 kbit/s.
A couple of calculators you can use:
-
from Dr. Lex site
-
a simpler one from 3ivx
Some scripts to do the job
Bitrate calculation and encoding
1 2 3 4 5 6 7 8 9 10 11 |
bitrate() { # ... to get video length in seconds find . -maxdepth 1 -iname '*.ts' -exec ffprobe -v quiet -of csv=p=0 -show_entries format=duration {} \; | paste -sd+ -| bc if [ "$len" -gt 5580 ] then vidrate=$((1000*((4570*8192)/$len-448))); echo "The calculated vidrate is $vidrate"; fi } |
and use ffmpeg to encode the video(s) to dvd format. See parameters from ffmpeg source code and a blog here.
1 2 3 4 5 6 7 |
ffmpeg -i "$avi" -c:v mpeg2video -f dvd -s 720x480 -pix_fmt yuv420p -r 29 -g 18 -b:v $vidrate -maxrate 8000000 -minrate 0 -bufsize 1835008 -packetsize 2048 -aspect $aspect $pana -pass 1 -an -y /dev/null; ffmpeg -i "$avi" -c:v mpeg2video -c:a ac3 -f dvd -s 720x480 -pix_fmt yuv420p -r 29 -g 18 -b:v $vidrate -maxrate 8000000 -minrate 0 -bufsize 1835008 -packetsize 2048 -muxrate 10080000 -b:a 448000 -ar 48000 -pass 2 -aspect $aspect $pana "$mpg"; # or #ffmpeg -i "$avi" -y -target $standard-dvd -b:v $vidrate -pass 1 -aspect $aspect $pana /dev/null; #ffmpeg -i "$avi" -y -target $standard-dvd -b:v $vidrate -aspect $aspect $pana "$mpg"; |
I tried with -target ntsc-dvd , it took 5 min longer with 2nd setting to encode 2 hours video.
Authorizing DVD
generate xml:
1 2 3 4 5 6 7 8 9 10 11 12 |
<dvdauthor> <vmgm /> <titleset> <titles> <pgc> <vob file="video.mpg" /> </pgc> </titles> </titleset> </dvdauthor> |
authorizing
1 2 3 |
dvdauthor -o dvd -x dvd.xml |
Burn
Create a iso image or burn:
1 2 3 4 |
genisoimage -dvd-video -V $name -o $name.iso dvd/ mkisofs -dvd-video -udf -o dvd.iso dvd/ |
Some resoures
http://grapsus.net/blog/post/A-script-for-splitting-videos-using-ffmpeg
https://wiki.archlinux.org/index.php/Convert_any_Movie_to_DVD_Video
http://radagast.ca/linux/dvd_authoring/dvd_authoring.html
http://dvdauthor.sourceforge.net/
https://tuxicity.wordpress.com/2006/12/01/avi-to-dvd-with-ffmpeg-and-dvdauthor/
https://sourceforge.net/p/dvdauthor/mailman/message/26498862/
https://wiki.archlinux.org/index.php/Optical_disc_drive
https://trac.ffmpeg.org/wiki/FFprobeTips
About the feature image
DVD-RW Drive operating with the protective cover removed.
image from https://en.wikipedia.org/wiki/DVD.
and about the lasers.
MAY
About the Author:
Beyond 8 hours - Computer, Sports, Family...