Log in

View Full Version : Convert multi language DVD using ffmpeg


ravs
22nd March 2018, 20:16
I try to convert a multi language DVD movie into an mkv or ogv video, with the first 2 audio tracks using ffmpeg.

I copied the VOBs of a DVD to the harddrive (using MS-W and ripit4me and DVDDecrypter since I cannot get it to work on Linux alone, I tried installing libdvdcss-1.4.0-x86_64 but the VOBs are still not readable, not even for the "file" command. See also here: http://forum.doom9.org/showthread.php?=t=1753332 )

This is the info I get via playing the merged VOB files of the main video
(I merged the main VOBs into one single VOB file using "cat Whatever*.VOB > P_V0.VOB" and played it via mpv to get the below info)Playing: P_V0.VOB
(+) Video --vid=1 (mpeg2video 720x576 25.000fps)
Subs --sid=1 (dvd_subtitle)
Subs --sid=2 (dvd_subtitle)
VO: [opengl] 720x576 => 1024x576 yuv420p
(+) Video --vid=1 (mpeg2video 720x576 25.000fps)
Audio --aid=1 (ac3 6ch 48000Hz)
Audio --aid=2 (ac3 6ch 48000Hz)
Audio --aid=3 (ac3 6ch 48000Hz)
Audio --aid=4 (ac3 2ch 48000Hz)
Subs --sid=1 (dvd_subtitle)
Subs --sid=2 (dvd_subtitle)
Subs --sid=3 (dvd_subtitle)
(+) Video --vid=1 (mpeg2video 720x576 25.000fps)
Audio --aid=1 (ac3 6ch 48000Hz)
Audio --aid=2 (ac3 6ch 48000Hz)
Audio --aid=3 (ac3 6ch 48000Hz)
Audio --aid=4 (ac3 2ch 48000Hz)
Subs --sid=1 (dvd_subtitle)
Subs --sid=2 (dvd_subtitle)
Subs --sid=3 (dvd_subtitle)
Subs --sid=4 (dvd_subtitle)
Subs --sid=5 (dvd_subtitle)
Subs --sid=6 (dvd_subtitle)
V: 00:00:04 / 00:00:00 (0%) Cache: 14s+73MB
Invalid video timestamp: 4.920000 -> -0.033367
V: 00:00:03 / 00:00:00 (0%) Cache: 11s+73MB
Track switched:
(+) Video --vid=1 (mpeg2video 720x576 25.000fps)
(+) Audio --aid=1 (ac3 6ch 48000Hz)
Audio --aid=2 (ac3 6ch 48000Hz)
Audio --aid=3 (ac3 6ch 48000Hz)
Audio --aid=4 (ac3 2ch 48000Hz)
Subs --sid=1 (dvd_subtitle)
Subs --sid=2 (dvd_subtitle)
Subs --sid=3 (dvd_subtitle)
Subs --sid=4 (dvd_subtitle)
Subs --sid=5 (dvd_subtitle)
Subs --sid=6 (dvd_subtitle)

These are the audio tracks, and I want to only keep audio0 and audio1:
Audio --aid=1 (ac3 6ch 48000Hz) ENG <- KEEP! map:0
Audio --aid=2 (ac3 6ch 48000Hz) DEU <- KEEP! map:1
Audio --aid=3 (ac3 6ch 48000Hz) jap
Audio --aid=4 (ac3 2ch 48000Hz) jap-Audio-Commentary
(I did add the info after the Hz entry, that was not part of the info by mpv)

I try to first cut off some stuff at the beginning ( "-ss 1:15.500" ), and create a 30 seconds test sample to see if ffmpeg gets it all right, especially in adding the two audio tracks. I first want a stream copy with includes the main video (video0) and the first two audio tracks (audio0 = ENG and audio1 = DEU). But I seem not to be able to get it right, I read the ffmpeg documentation ( http://ffmpeg.org//ffmpeg.html ), and also some posts about mapping on superuser.com and video.stackexchange.com, but so far to no prevail.

ffmpeg -y -v error -ss 1:15.500 -i P_V0.VOB -map 0:0 -map 0:1 -c:a ac3 -codec copy -acodec copy -t 30 P_V1_30s.mpg
[mpeg @ 0x2540de0] Invalid media type data for output stream #0
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument

$ ffmpeg -y -v error -ss 1:15.500 -i P_V0.VOB -map 0 -codec copy -acodec copy -t 30 P_V1_30s.mpg
[mpeg @ 0x1a71b20] Invalid media type data for output stream #0
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument

$ ffmpeg -y -v error -ss 1:15.500 -i P_V0.VOB -map 0:0 -map 0:1 -codec copy -t 30 P_V1_30s.mpg
[mpeg @ 0xe5fae0] Invalid media type data for output stream #0
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument

time ffmpeg -y -v error -ss 1:15.500 -i P_V0.VOB -codec copy -t 30 P_V1_30s.mpg

real 0m3.239s
user 0m0.915s
sys 0m0.815s

That seemed to have worked, but… there is no audio. Unlike the ffmpeg documentation which says, unless you use the -map options, one video and one audio track is used, the video with the largest resolution, and the audio with the most tracks, and if there are more audio tracks, the one with the lowest index. Which should be in my case: audio 0, aka ENG.

But for some reason (unknown to me reason, that is), the resulting test 30 seconds file has only video and lacks any audio:
$ mpv P_V1_30s.mpg
Playing: P_V1_30s.mpg
(+) Video --vid=1 (mpeg2video 720x576 25.000fps)
VO: [opengl] 720x576 => 1024x576 yuv420p
V: 00:00:06 / 00:00:30 (20%) Cache: 10s+11MB

Why is there no audio when using -codec copy ? Using -codec copy and -acodec copy has the same result: no audio, the resulting mpg only has video.

What do I do wrong trying to use -map to include the 1st and 2nd audio track (aka audio0 and audio1) ?

aidenn0
3rd April 2018, 05:24
Your stream specifiers are way off. It's best to specify stream specifiers with the type, as otherwise you end up with something unexpected.

The easiest way to map all audio streams, for example is to include

-map 0:a

so e.g.
ffmpeg -i P_V0.VOB -map 0:v:0 -map 0:a -codec copy foo.mkv

ravs
26th March 2020, 23:39
@all

(I know I reply to an old post, but it is my thread and I want to share the info with others who might lurk.)

What works in the above example would be e.g.
ffmpeg -i P_V0.VOB -map 0:v:0 -map 0:a:0 -map 0:a:1 -codec copy foo.mkv would work.
Since I need a larger -probesize and -analyzeduration or else I would get an error I had to use this:
ffmpeg -v error -y -probesize 100000000 -analyzeduration 100000000 -i P_V0.VO -q:v 10 -map 0:v -map 0:a:0 -map 0:a:1 -vf yadif,scale=w=iw/1.2:h=ih/1.2 P_V0.mkv

I first did a test that encoded only 4 minutes to see if everything works okay like so:
ffmpeg -v error -y -probesize 100000000 -analyzeduration 100000000 -i P_V0.VO -q:v 10 -map 0:v -map 0:a:0 -map 0:a:1 -vf yadif,scale=w=iw/1.2:h=ih/1.2 -t 240 P_V0.mkv

Cave! The above also makes the video smaller and could result in an error when the factor /1.2 results in an uneven number for either the height or the width.
I used " -v error " to only include severe errors after I eliminated all basic mistakes first.
A test run of only a few minutes is usually recommended since the main decode takes a long time, and then realizing something went wrong would be annoying, since you had to repeat it all. But a test decode takes only a few minutes.
Still ffmpeg reported some errors:
[mpeg2video @ 0xf3ff40] ac-tex damaged at 43 0
[mpeg2video @ 0xf3ff40] Warning MVs not available
[mpeg2video @ 0xf3ff40] ac-tex damaged at 24 32
[mpeg2video @ 0xf3ff40] Warning MVs not available
[ac3 @ 0xdd8c80] expacc 125 is out-of-range
[ac3 @ 0xdd8c80] error decoding the audio block
Error while decoding stream #0:2: Error number -16976906 occurred
[ac3 @ 0xae7940] exponent -2 is out-of-range
[ac3 @ 0xae7940] error decoding the audio block
Error while decoding stream #0:3: Error number -16976906 occurred
[ac3 @ 0xaaad00] exponent -1 is out-of-range
[ac3 @ 0xaaad00] error decoding the audio block
Error while decoding stream #0:4: Error number -16976906 occurred
[ac3 @ 0xdd8c80] exponent 25 is out-of-range
[ac3 @ 0xdd8c80] error decoding the audio block
Error while decoding stream #0:2: Error number -16976906 occurred
[ac3 @ 0xae7940] exponent 26 is out-of-range
[ac3 @ 0xae7940] error decoding the audio block
Error while decoding stream #0:3: Error number -16976906 occurred
[ac3 @ 0xaaad00] incomplete frame
What do these errors mean exactly?
Is e.g. [mpeg2video @ 0xf3ff40] ac-tex damaged at 43 0referring to an error at 0:43.0?
Or at 0:00:43.0 meaning 43 seconds frame 0?
But the later cannot be, since when I did the test run of 240 seconds there was no error mentioned.

Or is @ 0xf3ff40 the reference to the position where the error occurred?
If so, how does 0xf3ff40 translate into the human readable form of HH:MM:SS.f (f stands for frame) ?