mpv icon indicating copy to clipboard operation
mpv copied to clipboard

Support Human Readable Chapter Files (The Ones You See Everyday on YouTube)

Open thatfatblackcat opened this issue 3 years ago • 7 comments

Expected behavior of the wanted feature

Start supporting human readable chapter files and actively look them on the same directory with extension .chp or .chap. Human readable chapter files are somewhat of an implicit Internet standard that everybody understands on the fly.

The format would be [[hh:]mm:]ss[.ms] Chapter Title like usual (no HTML or weird formatting).

00:05:00 Chapter 01
00:10:00 Chapter 02
00:15:00 Chapter 03
00:20:00 Chapter 04

Alternative behavior of the wanted feature

I was thinking about creating a shell script that converts timestamps into subtitle files that I can use as chapter files. The problem with this approach is that I can't use subtitles for the same audio/video.

1
00:00:00.000 --> 00:05:00.000
Chapter 01

2
00:05:00.000 --> 00:10:00.000
Chapter 02

I also happen to know of scripts that let you take as input timestamps and insert chapters into the video. I'm not particularly fond of this approach either since metadata can be quite messy to work with on a daily basis. Same argument for metadata formats such as .ffmetadata using --chapters-file option in mpv.

Log file

mpv 0.32.0 Copyright © 2000-2020 mpv/MPlayer/mplayer2 projects built on UNKNOWN ffmpeg library versions: libavutil 56.51.100 libavcodec 58.91.100 libavformat 58.45.100 libswscale 5.7.100 libavfilter 7.85.100 libswresample 3.7.100 ffmpeg version: 4.3.2-0+deb11u1ubuntu1

thatfatblackcat avatar Dec 15 '21 10:12 thatfatblackcat

Can I reopen it?

It's not closed, and you can edit it.

avih avatar Dec 15 '21 10:12 avih

Ok, I think I got it to look I wanted it to look. Hopefully it'll get some attention.

ghost avatar Dec 15 '21 11:12 ghost

mpv already supports setting the chapter-list (here's ytdl_hook parsing ytdl output and applying the chapters), so I'm against explicit support for a non-standard chapter file - it's much more preferable to write a Lua script to check for a .chp or whatever file next to the current video during on_load or on_preloaded, and then parse and apply it. Immediately supported and backwards compatible!

TheAMM avatar Dec 15 '21 11:12 TheAMM

The ytdl_hook you mentioned is called only when streaming, and it does it's job correctly since I understand videos on the Internet are served as they are.

I'm talking about managing your personal archive locally, and one thing I learned is that having simple text files outside your video container grants you much more flexibility. You can check my subtitle to html script.

For example, one advantage of human readable chapter files could be that you can merge audio tracks and manage timestamps with a script. (This is actually an idea that I've pinned in my todo)

If this doesn't make it into mpv, a Lua script still wouldn't be a bad idea. I've never touched Lua so I can't help, but I hope someone will find this inspiring enough to give it a draft.

ghost avatar Dec 15 '21 16:12 ghost

Would be nice to have support for OGM chapters instead, which are already human readable and supported by other software. https://mkvtoolnix.download/doc/mkvmerge.html#mkvmerge.chapters.simple

vevv avatar Dec 19 '21 00:12 vevv

Please also consider VDR's marks file witch has the same 'chapters'. Here it is used to mak advertising.

MegaV0lt avatar Apr 22 '22 13:04 MegaV0lt

I created a lua script to implement similar functions: chapter-make-read.lua

The script can mplementation read and automatically load the namesake external chapter file from file extension of .chp. Example: video.mp4.chp to video.mp4.

  • The external chapter file is read from the subdirectory of chapters first. If the file does not exist, it will next be read from the same directory as the playing file.

The script supports external chapter files in all of the following formats:

00:00:00.000 A part
00:00:40.312 OP
00:02:00.873 B part
00:10:44.269 C part
00:22:40.146 ED
00:00:00.000
00:00:40.312
00:02:00.873
00:10:44.269
00:22:40.146
0:00:00 A part
0:00:40 OP
0:02:00 B part
0:10:44 C part
0:22:40 ED
0:00:00.000,Title1
0:17:02.148,Title2
0:28:10.114,Title3

OGM format (ogm)

CHAPTER01=00:00:00.000
CHAPTER01NAME=Intro
CHAPTER02=00:02:30.000
CHAPTER02NAME=Baby prepares to rock
CHAPTER03=00:02:42.300
CHAPTER03NAME=Baby rocks the house

MediaInfo format (mediainfo)

Menu
00:00:00.000                : en:Contours
00:02:49.624                : en:From the Sea
00:08:41.374                : en:Bread and Wine
00:12:18.041                : en:Faceless

The script also can temporarily mark the current playback position as a chapter so you can seek to it later. And allows writing current chapters as CHP or XML. Note: It can also be used to export the existing chapter information of the playing file.

dyphire avatar Jun 19 '22 12:06 dyphire