I have been converting some video files with ffmpeg for a friend to use on their ps3, but I have noticed the output mp4 files do not have chapter markers for faster skipping through them, is there a simple tool to add chapter markers every XX minutes into the files?
+ Reply to Thread
Results 1 to 7 of 7
-
-
Code:
if NOT [%1]==[-CALLED] goto :REDO @Echo OFF set /a ChapterDuration=1000*60*5 SHIFT for /F "tokens=1,4,5,6,7 delims=^ ^:^-^.^ " %%g in ('MP4Box -info "%~1" 2^>^&1') do ( if /I "%%~g"=="Timescale" ( set "Hours=%%~h" set "Minutes=%%~i" set "Seconds=%%~j" set "Milli=%%~k" goto :NEXT ) ) :NEXT echo %Hours%:%Minutes%:%Seconds%:%Milli% Set /a Duration=(Hours*60*60*1000) + (Minutes*60*1000) + (Seconds*1000) + Milli echo %Duration% echo.>"Chapters.txt" Set "Count=0" for /L %%y in (0, %ChapterDuration%, %Duration%) Do ( CALL :ADDCHAPTER "%%~y" ) MP4Box -chap "Chapters.txt" "%~1" goto :eof :REDO CMD /F:OFF /K "%~f0" -CALLED %* goto :eof :ADDCHAPTER Set "ChapterMarker=%~1" echo CM: %ChapterMarker% Set /a Work=((%ChapterMarker%/1000)/60)/60 CALL :Truncate CALL :MakeLen2 Set Hours=%Work% echo Hours: %Hours% Set /a ChapterMarker=ChapterMarker-(Hours*60*60*1000) Set /a Work=(%ChapterMarker%/1000)/60 CALL :Truncate CALL :MakeLen2 Set Minutes=%Work% echo Minutes: %Minutes% Set /a ChapterMarker=ChapterMarker-(Minutes*60*1000) Set /a Work=%ChapterMarker%/1000 CALL :Truncate CALL :MakeLen2 Set Seconds=%Work% echo Seconds: %Seconds% Set /a ChapterMarker=ChapterMarker-(Seconds*1000) Set Work=%ChapterMarker% CALL :Truncate CALL :MakeLen3 Set Milli=%Work% echo Milli: %Milli% Set /a ChapterMarker=ChapterMarker-Milli echo Chapter At: %Hours%:%Minutes%:%Seconds%.%Milli% Set "Work=%Count%" CALL :MakeLen2 echo CHAPTER%Work%=%Hours%:%Minutes%:%Seconds%.%Milli%>>"Chapters.txt" echo CHAPTER%Work%NAME=%Work%>>"Chapters.txt" Set /a count+=1 goto :eof :Truncate for /L %%b in (0, 1, 4) Do ( CALL :TruncateLoop "%%~b" ) goto :eof :TruncateLoop CALL Set CheckChar=%%Work:~%~1,1%% if "%CheckChar%"=="." ( CALL Set "Work=%%Work:~0,%~1%%" ) goto :eof :MakeLen2 if "%Work:~1,1%"=="" ( Set "Work=0%Work%" goto :MakeLen2 ) goto :eof :MakeLen3 if "%Work:~2,1%"=="" ( Set "Work=%Work%0" goto :MakeLen3 ) goto :eof
-
There's a Linux version of MP4Box, but although Bash is similar to Batch my script won't work.
You'll have to write your own:
http://ss64.com/bash/
Failing that you could just write a template chapter file containing chapters every 5 minutes, I'm not sure what will happen if you try to add a chapter that begins after the file has ended, but if that doesn't work, just figure out how long each file is and delete all the unnecessary chapters each time.
This thread:
https://forum.videohelp.com/threads/362141-Chapters-in-Windows-Compatible-Video-File
shows the two types of chapters you can have in MP4's, Apple/TTXT and Nero/Ogg, they're incompatible and if you want to play the files on an iPhone or such you need apple chapters. You'll need to know the total play length for apple chapters though.
Maybe you can port my script, it's not finished, and it's more complicated then you really need, although it's easily adaptable if you want to maybe add a certain amount of chapters for each file at even intervals or such instead of a chapter every five minutes. Since you're on Linux I can't be of much help beyond that. -
In Linux, chapter markers can be added either to MP4 by MP4Box (which is usually available under package name GPAC or GPAC Framework from official distro repo.) and to MKV, it can be added with MKVToolnix. MP4Box and MKVToolnix both accept chapter markers in pre-formatted text input.
More likely, MP4Box -chap <chapter-text-input-file>.
Refer original distro documentation and documentation for relevant tools.