Linux and Windows
vgtmpeg can be used to create a metadata file with chapter data from DVDs and BDs. This metadata file can then be used as an input file to ffmpeg to mark chapters. vgtmpeg is a fork of ffmpeg but, because it is not updated very often, we'll use it as a separate tool here.
Single title in VOB
If working with VOBs containing a single title ("program" in ffmpeg terms), you can export the metadata as follows.
For just the main global data:
vgtmpeg -i dvd://VIDEO_TS -f ffmetadata meta.txt
For all the metadata, including stream data (-t 0
is just for shortcutting the copy operation):
vgtmpeg -t 0 -i dvd://VIDEO_TS -c copy -map 0 -map_metadata 0 -f ffmetadata meta.txt
You can then use your preferred version of ffmpeg to work with the VOBs while also bringing in the chapter data and other metadata.
Windows form:
ffmpeg -i concat:"VTS_01_1.VOB|VTS_01_2.VOB" -i meta.txt -c copy -map_metadata 1 foo.mkv
Linux form:
ffmpeg -i "concat:VTS_01_1.VOB\|VTS_01_2.VOB" -i meta.txt -c copy -map_metadata 1 foo.mkv
Add -fflags +genpts
before the -i
if ffmpeg complains about timestamps missing in your VOBs.
Irregularities
-map_metadata 0
is needed to get all the global metadata (like creation_time
) for an unknown reason. Perhaps a bug. Perhaps this will change some day.
Similarly, it is not clear why -c copy
is needed for stream metadata export... but it is likely related to needing -map 0
to select all the streams in input 0 for metadata export. From there -map_metadata 0
is needed to force including stream metadata with the global metadata (again, unknown as to why this is only needed when working with just the metadata).
If you want to limit the streams in the metadata file, map only the streams you want (e.g. -map 0:v -map 0:a
). Use -map_metadata:?:? ?:?:?
only for very unusual cases where needing to map data from one place to another.
Multiple titles in VOB
If working with VOBs containing multiple titles, you can still export to text files like above but, then, slicing later with ffmpeg becomes a challenge. Thus, we use vgtmpeg to create an intermediate transport file instead. Note: TS files do not support metadata, so use your destination format instead for the intermediate file (or use MKV since it complains the least about VOB streams and metadata).
vgtmpeg -i dvd://VIDEO_TS?title=1 -c copy -map 0 -map -0:d title1.mkv
Add -fflags +genpts
before the -i
if ffmpeg complains about timestamps missing in your VOBs. The dvd_nav_packet
data stream will likely not be welcome in your output file, so we use -map -0:d
to ignore all data streams.
You can then use your preferred version of ffmpeg to work with the intermediate file.
ffmpeg -i title1.mkv -c copy -map 0 done1.mkv
Whether or not -map_metadata 0
is needed here seems to depend on the file formats in use. MKV, by default, does well without i.
Adding chapter titles
Unfortunately, there is no built-in way to add chapter title generation with vgtmpeg/ffmpeg. One could maybe process meta.txt with a sed script (Super-Sed for Windows) to add title=Chapter 1
lines... but that is a task for another day. Alternatively, scripting out a long ffmpeg command with -metadata:c:0 title="Chapter 1" ...
seems possible too.
Wish list
It would be nice if ffmpeg added IFO input support for program and chapter reading. Or, maybe, just absorb what vgtmpeg has done (but rename the title URL selector to "program" to help keep things straight.)
Windows only
Windows users can use Chapter-X-tractor with IFO files to generate a metadata file that ffmpeg can use to mark chapters. It's not a great solution for automation but, for one-off jobs, it works well enough. It also allows for very basic chapter title generation.
It doesn't come with a preset for ffmpeg (too old) so you need to add one with the following settings:
Header: ;FFMETADATA1\n
Format: \n[CHAPTER]\nTIMEBASE=1/1000\nSTART=%ams\nEND=%ams\ntitle=Chapter %c\n
Footer: [empty]
Like so:
Save the data to a file such as ch.txt. Then, you can use ffmpeg to write the chapter data like so:
ffmpeg -i concat:"VTS_01_1.VOB|VTS_01_2.VOB" -i ch.txt -c copy -map_chapters 1 foo.mkv
Add -fflags +genpts
before the -i
if ffmpeg complains about timestamps missing in your VOBs.
Caveats
This creates a metadata file that is not 100% correct according to ffmpeg standards. For some unknown reason, ffmpeg wants a chapter end time and Chapter-X-tractor cannot fill this need elegantly. Thus, this sets START
and END
to the same value. This works fine in VLC and, likely, most other players.
If you're a purist, you can edit the output metadata file and copy chapter start times to the previous chapters' end times. Then, using the Total Film Length found on the RAW Data tab (shown in hh:mm:ss:cc format [cc is hundredths of a seconds]), calculate the last chapter's end time in milliseconds (one zero beyond the cc value).
Irregularities
If you leave out the END=
line, ffmpeg will throw an error message but fills it in anyway with the next chapter's start time... which is good... except, on the last chapter where it sets start and end the same. This error also prevents reading the title=
data. Thus, this is a poor solution overall.
This tool calculates chapter times that can be a few tenths of a second different from vgtmpeg.
ffmpeg -i input.iso output.avi
. If it displays the info you need, then it means that it is in principle accessible using libav.ffmpeg -i input.iso output.avi
as well?