I have a number of MP4 files. They have chapters. However, there's no chapter at the start of the file, because whoever created them evidently felt that having a chapter marker there was redundant.
FFMPEG believes otherwise, because this:
results in an MKV file that shifts the first chapter point from wherever it originally was, and puts it at the start. Which basically means that it's deleting that chapter point. All other chapter points seem to be in the correct spot.Code:for %F in (*.mp4) do (ffmpeg -i "%F" -acodec copy -vcodec copy -map_chapters 0 "%~nF.mkv")
Is there a way to add a chapter point to the start of the mp4 file as part of this batch process, so it all comes out correctly?
+ Reply to Thread
Results 1 to 24 of 24
-
-
So I have to do it manually? For all of them? I have over 200 files here...
-
Then write a script which exports the chapters adds a chapter at 0 and then add the chapters on remuxing back. (or use a program which already does it, my guess is most guis that can use ffmpeg will do it,..)
users currently on my ignore list: deadrats, Stears555, marcorocchini -
If I knew how to write a script that would do that, I wouldn't be on here asking how to do it...
-
Probably not really something one would want to do with in a Windows batch script, but should be possible.
The general steps would be:
a. extract chapters into a readable file
b. add chapter at zero if non exists
c. remux
May be someone with enough knowledge and motivation will show up (most encoding guis like MeGui, StaxRip, etc. which support batch processing and output to mp4 should do this in the background)
Cu Selur
Ps.: Did you try using mkvmerge instead of ffmpeg, iirc. mkvmerge also has no problem with this and it's a command line tool.users currently on my ignore list: deadrats, Stears555, marcorocchini -
try using the ffmetadata format - https://stackoverflow.com/questions/47415660/how-to-add-chapters-into-mp4-mkv-file-using-ffmpeg
-
Again, that doesn't help with automating the process.
I tried creating a one-second black video, giving it a chapter right at the start, then using mkvmerge to mux it onto one of the problem mp4 files. It kind of works, the first chapter from the mp4 stays in the correct spot and it adds the chapter from the blank video, but a) they're in separate editions instead of just the one edition and b) when I try to play the output file in VLC it just stays with a black screen and the yellow loading bar trying to load the file. -
What do you mean by "they're in separate editions instead of just the one edition" ?
Got a small sample file which allows to reproduce the problem?users currently on my ignore list: deadrats, Stears555, marcorocchini -
When you view them in the MKVToolnix chapter editor, there are two editions in the file. I don't know what an edition is or how it works, though.
-
okay.
-> "Got a small sample file which allows to reproduce the problem?"users currently on my ignore list: deadrats, Stears555, marcorocchini -
Wait, got it. I was adding rather than appending. If I append the one-second, one-chapter black screen video to the existing problem video, I get a perfectly functional and correctly-chaptered MKV file. Woot.
-
Have you trief just remuxing with mkvtoolnix and not appending anything? (I think mkvmerge should be able to do this without issues and you could use it in a bash script if you want to.)
users currently on my ignore list: deadrats, Stears555, marcorocchini -
Well that does work inasmuch as it retains the existing chapter points, but there's still no chapter point at the start of the file, which screws things up.
-
I thought the issue was that the chapter points were moved,.. "results in an MKV file that shifts the first chapter point from wherever it originally was" -> confused, but it appending worked fine for you okay,...
users currently on my ignore list: deadrats, Stears555, marcorocchini -
Not sure if it will help but MKVToolNix has an option called “One chapter for each appended file” in the “Output” tab ; perhaps it would add a chapter point at the beginning of a single input MP4 file, making the rather dirty trick of adding a 1s blank clip unnecessary, although I don't know how it would interact with existing chapters. When you play with MKVTookNix GUI and find an option that works as intended, you can then display the corresponding mkvmerge command line with “Multiplexer” > “Show command line”{*}, and then use that command line directly in a script to batch-process dozens of files in the same way. I tested with a single MP4 file as input, enabling the aforementioned option added this to the command line :
Code:--chapter-language und --generate-chapters-name-template ^"Chapitre ^<NUM:2^>^" --generate-chapters when-appending
{*} Disclaimer : I'm using a version from 2019 and it has a rather hectic development rate so it could have changed in the mean (really mean) time. -
It adds the chapter point at 00:00:00.000, but when you view it in the Toolnix Chapter Editor that's the last chapter on the list. As such, when played back in VLC it shows up as the "last" chapter, which means the entire video is now "Chapter 01" and all the original chapter points are inaccessible.
-
It's possible as a three-step process though:
mkvmerge -o "%~nF.mkv" --generate-chapters when-appending "%F.mp4"
mkvextract "%~nF.mkv" chapters --simple "chapters.txt"
mkvpropedit "%~nF.mkv" --chapters "chapters.txt"
Now I just need to figure out what to replace ~nF with so it puts things in the correct subfolder, otherwise I'll still have to run it a couple dozen times. -
It adds the chapter point at 00:00:00.000, but when you view it in the Toolnix Chapter Editor that's the last chapter on the list. As such, when played back in VLC it shows up as the "last" chapter, which means the entire video is now "Chapter 01" and all the original chapter points are inaccessible.
Now I just need to figure out what to replace ~nF with so it puts things in the correct subfolder, otherwise I'll still have to run it a couple dozen times.
Code:FOR %%F in (*.mp4) do ( mkvmerge -o ".\MKV\%%~nF.mkv" --generate-chapters when-appending "%%F.mp4" mkvextract ".\MKV\%%~nF.mkv" chapters --simple "%%~nF - chapters.txt" mkvpropedit ".\MKV\%%~nF.mkv" --chapters "%%~nF - chapters.txt" )
(The “.” in the example above means “the current folder”, the one where the script file is located and executed from.) -
I mean I have the video files in subfolders, so if I want to run it once, I need to save them as %~dpnF.mkv not just %~nF.mkv.
Last edited by koberulz; 2nd Nov 2021 at 06:49.
-
Yes, I know, but my point is if I do that, and save them as %~nF.mkv, they all get saved into whatever folder the command line is running from, rather than the folder the original file was in. They need to be saved as %~dpnF.mkv to end up next to the originals.
Similar Threads
-
how to remove breaks in a video file not adverts 14 seconds breaks
By elm in forum EditingReplies: 3Last Post: 5th Mar 2020, 23:24 -
ffmpeg vs Handbrake for MKV to MP4 conversion
By Snoopy329 in forum EditingReplies: 3Last Post: 15th Feb 2020, 14:14 -
[question] DVD - Merge Multiple Titles with Chapter Breaks
By framers in forum MacReplies: 2Last Post: 28th Jan 2020, 21:35 -
FFMPEG Conversion from MKV to MP4 returns a empty MP4 file?
By lolmaisine in forum Video ConversionReplies: 4Last Post: 6th Mar 2019, 07:45 -
ffmpeg video conversion to mp4
By dabomb_gent in forum Video ConversionReplies: 4Last Post: 7th Dec 2016, 06:30