How to obtain titles and chapters information in DVD?

19,846

Solution 1

I'm not sure about what 1-frame accuracy means in this context. However, I've been using a tool called lsdvd, which is a basic CLI tool that takes as it's only parameter, the block device of your DVD drive. (Without that parameter, it will guess /dev/dvd, which is lacking on modern Linux, and is usually /dev/sr0.) It will then give you a nice listing of the chapters on the disc, like so:

$ lsdvd /dev/sr0
Disc Title: METAL_DISC_2
Title: 01, Length: 00:00:00.433 Chapters: 01, Cells: 01, Audio streams: 01, Subpictures: 01
Title: 02, Length: 00:00:11.500 Chapters: 01, Cells: 01, Audio streams: 01, Subpictures: 00
Title: 03, Length: 00:00:00.433 Chapters: 01, Cells: 01, Audio streams: 01, Subpictures: 01
Title: 04, Length: 00:00:00.433 Chapters: 01, Cells: 01, Audio streams: 01, Subpictures: 01
Title: 05, Length: 00:00:09.000 Chapters: 01, Cells: 01, Audio streams: 01, Subpictures: 00
Title: 06, Length: 00:00:10.000 Chapters: 01, Cells: 01, Audio streams: 01, Subpictures: 00
Title: 07, Length: 00:00:00.433 Chapters: 01, Cells: 01, Audio streams: 01, Subpictures: 01
Title: 08, Length: 00:25:02.333 Chapters: 06, Cells: 06, Audio streams: 01, Subpictures: 00
Title: 09, Length: 00:00:00.433 Chapters: 01, Cells: 01, Audio streams: 01, Subpictures: 00
Title: 10, Length: 00:07:48.700 Chapters: 16, Cells: 16, Audio streams: 01, Subpictures: 00
Title: 11, Length: 00:00:00.433 Chapters: 01, Cells: 01, Audio streams: 01, Subpictures: 00
Title: 12, Length: 00:16:43.066 Chapters: 08, Cells: 08, Audio streams: 01, Subpictures: 00
...snip...
Longest track: 20

If you wish to write your own code, I imagine looking at the source for lsdvd will be instructive. The only library it links against in Fedora 25 (other than standard stuff) is libdvdread.so.4, which is part of the dvdnav project.

HTH.

Solution 2

Mplayer can do this. I am not familiar with their library, but this could get you started

mplayer dvd:// -identify

Result

CHAPTERS: 00:00:00.000,00:03:40.200,00:07:29.500,00:12:04.033,00:16:17.199,
00:27:36.499,00:34:26.166,00:43:37.199,00:49:29.533,00:59:46.500,01:12:47.667,
01:17:09.000,01:26:13.700,01:47:15.833,01:50:06.200,01:55:25.500,02:06:42.500,
02:13:03.666,02:20:37.499,02:28:20.832,02:33:26.832,02:37:47.532,02:43:58.665,
02:51:00.165,02:56:36.165,03:01:21.998,03:05:09.331,03:07:14.665,03:11:49.665,
03:16:35.165,

Solution 3

I use a combination of both of the above to create a DVD chapter file which I can later add with mkvmerge to an encoded mkv file:

#!/bin/bash
if [ $# -lt 1 ]; then
    echo "Usage: $0 filename title_no"
    exit 
fi

i=1
j2=01
filename=$1
echo "Using lsdvd to load chapter info:"
lsdvd -c ./
if [ -z "$2" ]; then
    echo -ne "What title number do you want to create chapter info for: "
    read title
else
    title=$2
fi
IFS=',' read -r -a CHAPTERS <<< `mplayer -identify -frames 0 "./VTS_0"$title"_0.IFO" 2>/dev/null | grep CHAPTERS: | sed 's/CHAPTERS: //'`

for chapter in "${CHAPTERS[@]}"
do
    echo "Chapter $i: $chapter"
    let i++
done

echo -ne "Creating chapter data file...."
sleep 3
for chapter in "${CHAPTERS[@]}"
do
    echo "CHAPTER$j2=$chapter" >> $filename.txt
    echo "CHAPTER"$j2"NAME=Chapter $j2" >> $filename.txt
    j2=$(printf %02d $((10#$j2 + 1 )))

done
echo "DONE."
echo "Chapter data file: $filename.txt"

Example output:

$ read_chapters.sh whiteglasses_chapters
Using lsdvd to load chapter info: 
libdvdread: Couldn't find device name.
Couldn't read enough bytes for title.
Disc Title: unknown
Title: 01, Length: 00:00:21.000 Chapters: 01, Cells: 01, Audio streams: 00, Subpictures: 00
    Chapter: 01, Length: 00:00:21.000, Start Cell: 01
Title: 02, Length: 01:52:32.166 Chapters: 11, Cells: 12, Audio streams: 02, Subpictures: 01
    Chapter: 01, Length: 00:10:23.200, Start Cell: 01
    Chapter: 02, Length: 00:11:53.200, Start Cell: 02
    Chapter: 03, Length: 00:08:02.367, Start Cell: 03
    Chapter: 04, Length: 00:11:28.533, Start Cell: 04
    Chapter: 05, Length: 00:12:55.834, Start Cell: 05
    Chapter: 06, Length: 00:12:26.600, Start Cell: 06
    Chapter: 07, Length: 00:16:20.766, Start Cell: 07
    Chapter: 08, Length: 00:10:31.934, Start Cell: 09
    Chapter: 09, Length: 00:09:24.033, Start Cell: 10
    Chapter: 10, Length: 00:09:04.767, Start Cell: 11
    Chapter: 11, Length: 00:00:00.800, Start Cell: 12
    Longest track: 02
    What title number do you want to create chapter info for: 2 
    Chapter 1: 00:00:00.000
    Chapter 2: 00:10:23.200
    Chapter 3: 00:22:16.400
    Chapter 4: 00:30:18.767
    Chapter 5: 00:41:47.300
    Chapter 6: 00:54:43.134
    Chapter 7: 01:07:09.734
    Chapter 8: 01:23:30.500
    Chapter 9: 01:34:02.434
    Chapter 10: 01:43:26.467
    Chapter 11: 01:52:31.234 
    Creating chapter data file....DONE.
    Chapter data file: whiteglasses_chapters.txt

Then I simply run:

mkvmerge --chapters chapters.txt -o output.mkv input-file.mkv

Solution 4

Basically you can’t tell, but you can look for the longest title.

one option: use handbrakecli -scan e: (part of handbrake)

another: use mplayer -identify dvd:// -dvd-device e: (mplayer standard)

From: http://betterlogic.com/roger/2011/07/dvd-determine-main-title-from-command-line/

This helped me, as VLC lists the titles and chapters in it's GUI Menu's

Basically, install VLC Media Player, then play your DVD in it. Navigate through till it “is playing the real title”

then go to Playback [menu] -> title and see which one it is currently highlighting.

Now you know which title is the “main” title track.

Source: http://betterlogic.com/roger/2010/11/how-to-use-vlc-to-tell-how-many-titles-and-chapters-and-which-is-the-main/

Share:
19,846
Tarhan
Author by

Tarhan

Updated on June 14, 2022

Comments

  • Tarhan
    Tarhan almost 2 years

    I found many question about creating DVD menu using ffmpeg but i did not find any one about programmically access to DVD structure information. When i using libav (or FFmpeg) library i can open DVD image (iso file) and access to video, audio and subtitle streams. But i could not find any API.

    I can play video and found information using VLC player (and so libvlc library). But I need to do some processing on audio and subtitle stream programmically. I don't want to split VOBs using tools like SmartRipper, and only then do processing.

    Does libav(ffmpeg) contain any API for dealing with DVD menus? If not can you recommend any other library which can be used to obtain information about title(chapter) start and end time with one frame(sample, AVPacket) accuracy?

    I heard about libdvdnav library but i don't know if it right for me. I'm new to libav and DVD format internals.

    • sashoalm
      sashoalm over 11 years
      Try using the ffmpeg command line utility on your iso file, and see the kinds of information it displays on the screen. The command is something like ffmpeg -i input.iso output.avi. If it displays the info you need, then it means that it is in principle accessible using libav.
    • Tarhan
      Tarhan over 11 years
      I already tried to use ffprobe (avprobe) it displays only streams count and its type.
    • sashoalm
      sashoalm over 11 years
      I'm not sure if ffprobe gives the same info as ffmpeg. I've never used ffprobe. Did you try using ffmpeg -i input.iso output.avi as well?
    • Tarhan
      Tarhan over 11 years
      Yes, i tried to convert to avi. It also displays only information about streams count and type. By the way, both type of tools ffmpeg and ffprobe display length of first video. But when i encode iso image into avi format and ending of first video it continues to next without any message.
  • mivk
    mivk over 10 years
    I added the -frames 0 option to prevent actually playing the video. Example: mplayer -identify -frames 0 '/path/to/VIDEO_TS.IFO 2>/dev/null | grep CHAPTERS:
  • Falk
    Falk almost 8 years
    alternatively you can filter with grep TITLE titles seem to come one per line
  • a3nm
    a3nm over 5 years
    Also note that you can use lsdvd -c to show detailed information about chapters.