Skip to content

Add save-chapters command for FFmetadata chapter export (#323) - #599

Open
Davidvisualstudio007 wants to merge 4 commits into
Breakthrough:mainfrom
Davidvisualstudio007:save-chapters
Open

Davidvisualstudio007 wants to merge 4 commits into
Breakthrough:mainfrom
Davidvisualstudio007:save-chapters

Conversation

@Davidvisualstudio007

Copy link
Copy Markdown

Closes #323

This adds a save-chapters command that saves the detected scenes as chapters in FFmetadata format. You can then add them to a video with ffmpeg without re-encoding:

scenedetect -i video.mp4 detect-content save-chapters
ffmpeg -i video.mp4 -i video-Chapters.txt -map_metadata 1 -codec copy output.mp4

What I changed:

  • Added write_scene_list_ffmetadata() to scenedetect.output. I based it on the EDL writer, so it works with a file path or an open file
  • Added the save-chapters command with -f, -t and -o options, and a [save-chapters] section in the config. -t lets you change chapter names using $SCENE_NUMBER
  • Special characters in titles get escaped so ffmpeg doesn't misread them
  • Updated the docs, changelog and features list

For the timing I used _frame_timecode_seconds(), so it stays accurate at 23.976 and 29.97 and doesn't drift like the EDL issue in #593.

I added 22 tests in test_output.py and 2 in test_cli.py, including one that actually runs ffmpeg to add the chapters to a video and checks they're there. Ruff passes and the output and CLI tests all pass on the latest main. I also tried it on goldeneye.mp4 and the chapters showed up in VLC.

I left YouTube style chapters out for now. YouTube needs the first chapter at 00:00, at least 3 chapters, and each one at least 10 seconds long, so I wasn't sure how you'd want short scenes handled.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export scenes in chapter format

1 participant