Thursday, August 14, 2014

How to Convert DVD to mp4: Part 2- Handling Audio

The last conversion script works for video but creates terrible audio. The reason is easy to see. Lets run ffprobe on the first VOB.

ffprobe VTS_01_1.VOB

Here are the results:

Input #0, mpeg, from 'VTS_01_1.VOB':
Duration: 00:26:01.26, start: 0.280633, bitrate: 5501 kb/s
Stream #0:0[0x1bf]: Data: dvd_nav_packet
Stream #0:1[0x1e0]: Video: mpeg2video (Main), yuv420p(tv), 720x480 [SAR 32:27 DAR 16:9], max. 7000 kb/s, 33.33 fps, 59.94 tbr, 90k tbn, 59.94 tbc
Stream #0:2[0x20]: Subtitle: dvd_subtitle
Stream #0:3[0x21]: Subtitle: dvd_subtitle
Stream #0:4[0x22]: Subtitle: dvd_subtitle
Stream #0:5[0x23]: Subtitle: dvd_subtitle
Stream #0:6[0x24]: Subtitle: dvd_subtitle
Stream #0:7[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
Stream #0:8[0x89]: Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 768 kb/s
Stream #0:9[0x82]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
Unsupported codec with id 1145979222 for input stream 0

Clearly, there are multiple audio streams. Not specifying a particular stream will cause all audio inputs to get inserted into the audio conversion chain, and this produces muck.

To specify a particular stream, let's use a filter to map it. This is the most reliable way to ensure that only the required stream is mapped. We will use the "anull" filter, which does nothing to the audio, but just passes it on untouched. We will in this example use the stereo stream, that is stream 0:7. So we will provide the input pad to anull as 0:7.

To check the quality of the audio I did tests both with wav output as well as aac. These are short quality checks:

ffmpeg -i VTS_01_1.VOB -y -ss 10 -t 50 -filter_complex '[0:7]anull[ao]' -map '[ao]' -acodec pcm_s16le -b:a 900k -f wav test.wav


ffmpeg -i VTS_01_1.VOB -y -ss 10 -t 50 -filter_complex '[0:7]anull[ao]' -map '[ao]' -acodec aac -strict -2 -b:a 256k test.m4a

Results of both these tests were fine. So the final audio conversion portion was modified and inserted into the older mp4 conversion script. This now becomes:

#!/bin/sh

cat VTS_01_[1234567].VOB | ffmpeg -i - -y -strict -2 -acodec aac -ab 256k -pass 1 -vcodec libx264 -filter_complex "yadif,hqdn3d=5:3:8:8,unsharp=5:5:0.5:3:3:0.3,curves=master='0.2/0.28';[0:7]anull[ao]" -map '[ao]' -threads 4 -b:v 1200k -pix_fmt yuv420p -flags +loop -cmp chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 1 -trellis 0 -refs 1 -bf 3 -b_strategy 2 -coder 1 -me_range 16 -g 250 -keyint_min 75 -sc_threshold 40 -i_qfactor 0.71 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -f mp4 /dev/null

cat VTS_01_[1234567].VOB | ffmpeg -i - -y -strict -2 -acodec aac -ab 256k -pass 2 -vcodec libx264 -filter_complex "yadif,hqdn3d=5:3:8:8,unsharp=5:5:0.5:3:3:0.3,curves=master='0.2/0.28';[0:7]anull[ao]" -map '[ao]' -threads 4 -b:v 1200k -pix_fmt yuv420p -flags +loop -cmp chroma -partitions +parti4x4+partp8x8+partb8x8 -mixed-refs 1 -subq 6 -trellis 1 -refs 5 -bf 3 -b_strategy 2 -coder 1 -me_range 16 -g 250 -keyint_min 75 -sc_threshold 40 -i_qfactor 0.71 -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -movflags +faststart outfile.mp4 

No comments:

Post a Comment