VideoHelp Forum
+ Reply to Thread
Results 1 to 5 of 5
Thread
  1. Ret. Hippie Guitar Player Axel Slingerland's Avatar
    Join Date
    Jul 2020
    Location
    The Lost Coast
    Search Comp PM
    My DVD player is getting old and fast forward for MP4 files on a USB drive doesn't always work very well. Could someone tell me how to write a DOS batch file to add chapters every 10 minutes to MP4 files with ffmpeg?

    It would be very much appreciated...
    Quote Quote  
  2. Member
    Join Date
    Apr 2007
    Location
    Australia
    Search Comp PM
    Hello. The batch file just got edited. I missed a % character. If it fails for you, grab it again.

    I've found over the years the simplest way is by doing a 2 step tango.
    The following batch file creates a new MKV file in the New\ folder.
    Changes to that folder.
    Creates a new MP4 next to the MKV.
    The process is almost a direct stream copy for all tracks and is quick.
    There are no chapter titles, etc. In fact nothing but chapter markers. TWICE.
    Yeah, you end up with 2 lots of chapter markers. It doesn't seem to hurt anything. Check it with MediaInfo.
    There's probably a fix for that, but I'm not bothered.
    It is quick and easy.

    Code:
    @echo off
    :: MP4 - MKV with chapters.
    if not exist New\*.* md New
    for %%a in ("*.mp4") do "C:\Program Files\MKVToolNix\mkvmerge.exe" --ui-language en "%%a" --output "New\%%~na.mkv" --generate-chapters interval:00:10:00.000 --track-order 0:0,0:1
    cd New
    for %%a in ("*.mkv") do ffmpeg -i "%%a" -codec copy -threads 0 -y "%%~na.mp4"
    pause
    Now you have both an MKV and an MP4 with chapter markers in the New\ folder.
    Every video I have these days plays wirelessly through a laptop under my TV. All MKV.

    Cheers
    Last edited by pcspeak; 15th Jan 2022 at 20:39. Reason: Left a % character off.
    Quote Quote  
  3. Ret. Hippie Guitar Player Axel Slingerland's Avatar
    Join Date
    Jul 2020
    Location
    The Lost Coast
    Search Comp PM
    Thanks, Mate!

    Any chance you could edit it and remove the MKV stuff? I pretty much do the same thing as you, I bought a laptop specifically to use as a movie player. (Fortunately, right before the pandemic hit and the price for the same laptop went up by nearly 50%!) But nearly all of my videos are MP4 files. The only MKV files I have are MakeMKV copies of some of my DVDs.

    I have been using Drax and that method works ok, but it's one file at a time and that can be a bit time consuming. Based on what little I know about using ffmpeg in batch files, your batch appears to me to be able to do multiple videos at a time without changing the batch file, which is exactly what I was hoping to find. However, I freely admit that I probably know considerably less than I think I do about all sorts of things. So I could be way off base on that. Which is why I don't assume that I know what I don't and I am always eager to learn more. Even if the ol' sponge in my head isn't as absorbent as it used to be...
    Quote Quote  
  4. Member
    Join Date
    Apr 2007
    Location
    Australia
    Search Comp PM
    The batch file is to work with MP4 videos.
    MKV is only an interim step and any MKV videos can be deleted.
    It's the easiest way I know of to add chapters.
    Grab a copy of mkvmerge.exe and put it with ffmpeg.exe.
    The following changes wil clean up all MKV videos in the New\ folder.

    Code:
    @echo off
    :: MP4 -> MKV -> MP4 with chapters.
    if not exist New\*.* md New
    for %%a in ("*.mp4") do mkvmerge.exe --ui-language en "%%a" --output "New\%%~na.mkv" --generate-chapters interval:00:10:00.000 --track-order 0:0,0:1
    cd New
    for %%a in ("*.mkv") do ffmpeg -i "%%a" -codec copy -threads 0 -y "%%~na.mp4"
    del *.mkv
    pause
    Quote Quote  
  5. Ret. Hippie Guitar Player Axel Slingerland's Avatar
    Join Date
    Jul 2020
    Location
    The Lost Coast
    Search Comp PM
    Cool, thanks. 10 or 15 years ago I would have thought of that myself... I guess I am getting old.


    Edit: Works like a charm. Very fast, and does do multiple files. Which will really speed things up. Thanks again, Mate!
    Last edited by Axel Slingerland; 22nd Jan 2022 at 00:47.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!