有馬総一郎のブログ

(彼氏の事情)

2024年02月18日 07:02:05 JST - 6 minute read - Comments - Linux

Linuxで、Blu-rayやDVDのチャプター情報を確認して、音声をflacに変換する

メイン機をLinuxにしたとはいえ、まだまだWindowsが必要なわけで、 Oracle VM VirtualBoxを使っている。とはいえ、所詮、CPUもメモリも大して積んでないので、起動するのはやはりしんどい。

DVD、Blu-rayの扱いなどはLinuxでは難しいと思い込んでいたけど、早合点していたようだ。プロテクトのかかってないBlu-rayやDVDのチャプター情報の表示ぐらいなら簡単にできるようだ。

Blu-rya

GitHub - zoffline/BDInfoCLI-ng: BDInfo (with UHD support) modified for command line usage.を使うだけ。

BDInfoCLI-ng can be built and run with Mono.

Using Docker is highly recommend (nobody should have to taint their OS with Mono).

最初、 Monoをインストールしてビルドしなきゃいけなくて、汚染されるのが嫌ならDocker使ってね、ということかと思ったら、 scripts/bdinfo をたたけば、実行可能な環境のDockerイメージを落してきてくれて、実行してくれる。

$ ./scripts/bdinfo
  -h, --help                 Print out the options.
  -l, --list                 Print the list of playlists.
  -m, --mpls=VALUE           Comma separated list of playlists to scan.
  -w, --whole                Scan whole disc - every playlist.
  -v, --version              Print the version.

ヘルプは上記のようにとなっている。第1引数にディスクのパス、第2引数にレポートの出力先パスを指定してあげれば良い。

すると、プレイリストを選択しろと出るので、選択して(今回1つだけだった)、qと終了すると選択したプレイリストでの解析がされて、結果が出力される。

$ ./scripts/bdinfo /mnt/iso /home/arimasou16/Documents
Please wait while we scan the disc...
#   Group  Playlist File  Length    Estimated Bytes Measured Bytes

1   1      00002.MPLS     03:03:38  48,562,544,640  -
Select (q when finished): 1

Added 1
Select (q when finished): q
Preparing to analyze the following:
00002.MPLS --> 00005.M2TS + 00006.M2TS

                File           Elapsed      Remaining
Scanning 100% - 00005.M2TS     00:06:42  |  00:00:00
Scan completed successfully.
Please wait while we generate the report...

出力されたファイルをみると、いつもの結果を確認できる。

~/Documents/BDINFO.iso.txt

Disc Label:     iso
Disc Size:      48,599,796,119 bytes
Protection:     AACS
BDInfo:         0.7.5.5

Notes:          

BDINFO HOME:
  Cinema Squid (old)
    http://www.cinemasquid.com/blu-ray/tools/bdinfo
  UniqProject GitHub (new)
   https://github.com/UniqProject/BDInfo

INCLUDES FORUMS REPORT FOR:
  AVS Forum Blu-ray Audio and Video Specifications Thread
    http://www.avsforum.com/avs-vb/showthread.php?t=1155731


********************
PLAYLIST: 00002.MPLS
********************
・・・省略・・・
Playlist: 00002.MPLS
Size: 48,562,544,640 bytes
Length: 3:03:38.540
Total Bitrate: 35.26 Mbps
Video: MPEG-4 AVC Video / 31359 kbps / 1080i / 29.970 fps / 16:9 / High Profile 4.1
Audio: Japanese / LPCM Audio / 2.0 / 48 kHz /  2304 kbps / 24-bit

フォーク元である GitHub - UniqProject/BDInfo: BDInfo from http://www.cinemasquid.com/blu-ray/tools/bdinfoが、2020年以降開発ない。また、このスクリプトやDockerは個人が作成したのを公開したものなので、ある日突然使えなくなる可能性はある。それまではありがたく使わせてもらおう。Blu-ray自体使わなくなる方が先になりそうな気もするが。

DVD (lsdvd 不正確?)

LinuxでDVDの情報を見るならlsdvdというコマンドがあるらしく、 GitHub - thierer/lsdvd見ると、何故か0.17のソースは sourceforgeから取得しなければならない。libdvdread-devをインストールしてせっせとビルドしたが、リポジトリにあった。

lsdvd/jammy,now 0.17-1build3 amd64 [インストール済み]
  DVD のコンテンツ情報を読み込み

ヘルプはこんな感じ。

$ lsdvd -h
lsdvd 0.17 - GPL Copyright (c) 2002-2005, 2014 "Written" by Chris Phillips <acid_kewpie@users.sf.net>
Usage: lsdvd [options] [-t track_number] [dvd path]

Options:
	Extra information:
	  -a audio streams
	  -d cells
	  -n angles
	  -c chapters
	  -s subpictures
	  -P palette
	  -v video
	  -x all information

	Formatting:
	  -Oh output as human readable (default)
	  -Op output as Perl
	  -Oy output as Python
	  -Or output as Ruby
	  -Ox output as XML

	Other options:
	  -q quiet - no summary totals
	  -h this message
	  -V version information

オプションなしでDVDのパスを指定すれば、チャプター時間などが分かる。

$ lsdvd ~/Videos/DVD.iso
Disc Title: SAMPLE_DVD
Title: 01, Length: 00:00:00.467 Chapters: 01, Cells: 01, Audio streams: 00, Subpictures: 00
Title: 02, Length: 01:15:28.900 Chapters: 17, Cells: 17, Audio streams: 01, Subpictures: 00
Title: 03, Length: 01:15:28.900 Chapters: 17, Cells: 17, Audio streams: 01, Subpictures: 00
・・・省略・・・
Title: 19, Length: 00:05:20.900 Chapters: 01, Cells: 01, Audio streams: 01, Subpictures: 00
Longest track: 02
$

-a-cなどつけると、より詳細が分かる。

$ lsdvd -ac /mnt/iso
Disc Title: SAMPLE_DVD
Title: 01, Length: 00:00:00.467 Chapters: 01, Cells: 01, Audio streams: 00, Subpictures: 00
	Chapter: 01, Length: 00:00:00.467, Start Cell: 01
Title: 02, Length: 01:15:28.900 Chapters: 17, Cells: 17, Audio streams: 01, Subpictures: 00
	Audio: 1, Language: xx - Unknown, Format: lpcm , Frequency: 48000, Quantization: 16bit, Channels: 2, AP: 0, Content: Undefined, Stream id: 0xa0
	Chapter: 01, Length: 00:05:20.900, Start Cell: 01
	Chapter: 02, Length: 00:03:21.000, Start Cell: 02
	Chapter: 03, Length: 00:04:10.000, Start Cell: 03
・・・後略・・・

ただ、自分が試したDVDがたまたまなのか、WindowsのDVD Decrypterと、時間が違っていて10秒ぐらいズレていた1。正しかったのはDVD Decrypterの方だった。ということで、他のDVD解析ツールを試してみた。

DVD (ffprobe)

ffmpegに同梱されているffprobeを試してみた。

ffprobe -i "DVDのパス" -show_chapters

自分はチャプター毎の時間が見たかったのだけど、表示されない。更にオプションを付ければ、表示されるのか知れないけど、オプションが多すぎて諦めた。

$ ffprobe -i "~/Videos/DVD.iso" -show_chapters
ffprobe version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2007-2021 the FFmpeg developers
・・・省略・・・
Input #0, mpeg, from '~/Videos/DVD.iso':
  Duration: 01:15:33.50, start: 0.233567, bitrate: 7679 kb/s
  Stream #0:0[0x1bf]: Data: dvd_nav_packet
  Stream #0:1[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, top first), 720x480 [SAR 8:9 DAR 4:3], 2000 kb/s, 30.57 fps, 59.94 tbr, 90k tbn, 59.94 tbc
    Side data:
      cpb: bitrate max/min/avg: 2000000/0/0 buffer size: 1425408 vbv_delay: N/A
  Stream #0:2[0x20]: Subtitle: dvd_subtitle
  Stream #0:3[0x21]: Subtitle: dvd_subtitle
  Stream #0:4[0x22]: Subtitle: dvd_subtitle
  Stream #0:5[0xa0]: Audio: pcm_dvd, 48000 Hz, 2 channels, s16, 1536 kb/s
  Stream #0:6[0x1d7]: Audio: mp2, 0 channels
Unsupported codec with id 100357 for input stream 0
$

DVD (dvdxchap)

次にogmtoolsに同梱されているdvdxchapを試してみた。sudo apt install ogmtoolsすれば、使えるようになる。

オプションなし。

$ dvdxchap ~/Videos/DVD.iso
CHAPTER01=00:00:00.000
CHAPTER01NAME=Chapter 01

これは駄目だと思ったが、ヘルプを確認する。

$ dvdxchap -h
ogmtools v1.5
Usage: dvdxchap [options] DVD-SOURCE

 options:
   -t, --title num            Use title 'num'. Default is 1.
   -c, --chapter start[-end]  Chapter to start at (to end at). Default 1.
   -v, --verbose              Increase verbosity
   -V, --version              Show version information
   -h, --help                 Show this help

タイトルの指定を正しくすれば見れるのかと思い、タイトルを2と、指定すると、見たい情報が表示された。しかも、時間もDVD Decrypterと同じだ。

$ dvdxchap -t 2 ~/Videos/DVD.iso
CHAPTER01=00:00:00.000
CHAPTER01NAME=Chapter 01
CHAPTER02=00:05:30.000
CHAPTER02NAME=Chapter 02
CHAPTER03=00:08:51.000
CHAPTER03NAME=Chapter 03
・・・省略・・・

チャプター(時間を)を指定してflacに変換する

Blu-rayの場合は Blu-rayの動画(m2ts)をFFmpegを使って分秒(チャプター)で分割するのようにffmpegでやれば良いと思うが、DVDって入力パスどうするんだろう?って思ったら、-i "~/Videos/DVD.iso"と、ディスクを指定すれば良いらしい。

しかし、 pcm_dvd なるものが wav に上手く変換できない。

ffmpeg -i "~/Videos/DVD.iso" -ss 0:00:00.000 -t 0:05:30.000 -c:a copy /home/arimasou16/Videos/01.wav

[wav @ 0x56f22ac153c0] Codec pcm_dvd not supported in WAVE format
Could not write header for output file #0 (incorrect codec parameters ?): Function not implemented
Error initializing output stream 0:0 --

と駄目。 Can ffmpeg convert audio from raw PCM to WAV? - Stack Overflowを見て、フォーマット、サンプルレート、チャンネル数を指定する。

ffmpeg -i "~/Vidoes/DVD.iso" -ss 0:00:00.000 -t 0:05:30.000 -c:a -f s16le -ar 48.0k -ac 2 /home/arimasou16/Videos/01.wavとやる。

[NULL @ 0x58c2b2581140] Unable to find a suitable output format for 's16le'
s16le: Invalid argument

駄目。マッピングさせればと、 ffmpegのmapを解説する #ffmpeg - Qiitaを見てみる。

ffmpeg -i "~/Vidoes/DVD.iso" -ss 0:00:00.000 -t 0:05:30.000 -map 0:a -f s16le -ar 48.0k -ac 2 /home/arimasou16/Videos/01.wavとやる。

  Stream #0:5[0xa0]: Audio: pcm_dvd, 48000 Hz, stereo, s16, 1536 kb/s
  Stream #0:6[0x1d7]: Audio: mp2, 0 channels
File '/home/arimasou16/Videos/01.wav' already exists. Overwrite? [y/N] y
Stream mapping:
  Stream #0:5 -> #0:0 (pcm_dvd (native) -> pcm_s16le (native))
  Stream #0:6 -> #0:1 (mp2 (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
[mpeg @ 0x577b2f6c3440] Packet corrupt (stream = 6, dts = NOPTS).
Error while decoding stream #0:6: Invalid data found when processing input
Cannot determine format of input stream 0:6 after EOF
Error marking filters as finished
Conversion failed!

音声ストリームがが複数あるようで失敗。なので、-map 0:aではなく、-map 0:5と指定する。

ffmpeg -i "~/Vidoes/DVD.iso" -ss 0:00:00.000 -t 0:05:30.000 -map 0:5 -f s16le -ar 48.0k -ac 2 /home/arimasou16/Videos/01.wavとやる。

成功したかに見えたが、出来たものを再生しても再生シーケンスが動かず、音も出ず、駄目。

ならば、ffmpeg -i "~/Videos/DVD.iso" -ss 0:00:00.000 -t 0:05:30.000 -map 0:5 /home/arimasou16/Videos/01.mp3と出力を mp3 としてしまう。

成功、音が出る。もう wav に拘るのをやめる。

ffmpeg -i "~/Videos/DVD.iso" -ss 0:00:00.000 -t 0:05:30.000 -map 0:5 -compression_level 8 /home/arimasou16/Videos/01.flacflac で出力させる。

Stream mapping:
  Stream #0:5 -> #0:0 (pcm_dvd (native) -> flac (native))
Press [q] to stop, [?] for help
Output #0, flac, to '/home/arimasou16/Videos/01.flac':
  Metadata:
    encoder         : Lavf58.76.100
  Stream #0:0: Audio: flac, 48000 Hz, stereo, s16, 128 kb/s
    Metadata:
      encoder         : Lavc58.134.100 flac
size=   37862kB time=00:05:30.00 bitrate= 966.6kbits/s speed= 180x
video:0kB audio:37854kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.021381

成功した…何か気にいらなければ FFmpeg Codecs Documentationを見て調節しよう。


  1. 00:05:20.90000:05:30.000と異なる。また、チャプター番号順に出力されないのも分かりにくい。 ↩︎