VideoHelp Forum
+ Reply to Thread
Results 1 to 1 of 1
Thread
  1. So, I had a project that necessitated this, and found it wasn't directly possible. However, I came up with a workaround using FFMPEG, Python, and a batch script. This will only work on windows, but if you know a bit of coding, a macOS version shouldn't be too hard to figure out.

    Scripts are at the bottom of this post, here's the steps for how to make it happen:

    First is to properly set up your markers. Note that this only works with sequence markers (ones made on a timeline while no clips were selected), not markers on individual clips. If you want your marker names to be visible in VLC as chapter names when you play the file back (e.g. "Start of Concert"), you need to put the chapter names in the "description" area of the marker, not the title. I don't know why this is, but Premiere only exports descriptions, not the titles. If your markers don't have descriptions, they will simply be named "Chapter 1, Chapter 2, etc." in the end result

    Second step is to go to your sequence and select "Show Audio Time Units" inside your sequence's hamburger menu within the timeline panel.

    Image demonstration here

    Next, right click the time code, and chose "milliseconds" instead of "audio samples"



    Then go to File > Export > Markers, and choose Text File (.txt), and the same output destination as where your video file is. Make sure your .txt file is the same name as your video file (e.g., Video1.mp4, Video1.txt)

    Now, onto the script itself, which requires Python3 and FFmpeg to be installed. If you haven't already registered FFmpeg on the command line globally and don't want to bother figuring that out, simply put FFmpeg.exe in the same folder as your video and text files.

    Once those things are installed and everything's in the same folder, just drag/drop all the video files onto the .bat file. This will iterate through all of them, and make new files called something like Video1-chapters.mp4 Note that if you uncomment the last two lines of the batch script (removing "REM"), it will replace the original file instead of creating a new one.

    And that's it!

    Note that this is designed for .mp4 files, but may also work with other containers like .mov that allow chapters. Haven't tested, so I don't know.

    ~~~~~~~

    Copy/paste these scripts into new files along with the file names I specified. Specifically, the python script needs to be named prpro_ffmpeg_chap.py or the batch script won't work.

    Drop Video Files Here To Add Chapters.bat
    Code:
    @echo off
    
    FOR %%A IN (%*) DO (
    echo %%~nxA
    ffmpeg -i "%%~nxA" -f ffmetadata FFMETADATAFILE -loglevel warning -stats
    python3 "prpro_ffmpeg_chap.py" "%%~nA"
    echo If Python gave you an error message, remember to change
    echo Premiere Pro's time units to Milliseconds, not frames or samples
    echo before you export your markers.
    ffmpeg -i "%%~nxA" -i FFMETADATAFILE -map_metadata 1 -codec copy "%%~nA-chapters%%~xA" -loglevel warning -stats
    del FFMETADATAFILE
    REM del %%~nxA
    REM ren %%~nA-chapters.mp4 %%~nxA
    )
    
    pause
    prpro_ffmpeg_chap.py
    Code:
    import re
    import math
    import sys
    
    chapters = list()
    loopnum = int(0)
    with open(sys.argv[1]+'.txt', 'r', encoding='utf=16') as f:
       next(f)
       for line in f:
          x = re.search(r".*?\t\t\t(\d{2}):(\d{2}):(\d{2}).(\d{3})\t{3}(.*?)\t", line)
          hrs = int(x.group(1))
          mins = int(x.group(2))
          secs = int(x.group(3))
          ms = int(x.group(4))
          desc = str(x.group(5))
          loopnum += 1
          if len(desc) > 0:
             title = x.group(5)
          else:
             title = "Chapter " + str(loopnum)
            
          minutes = (hrs * 60) + mins
          seconds = secs + (minutes * 60)
          timestamp = ms + (seconds * 1000)
          chap = {
             "title": title,
             "startTime": timestamp
          }
          chapters.append(chap)
    
    text = ""
    
    for i in range(len(chapters)-1):
       chap = chapters[i]
       title = chap['title']
       start = chap['startTime']
       end = chapters[i+1]['startTime']-1
       text += f"""
    [CHAPTER]
    TIMEBASE=1/1000
    START={start}
    END={end}
    title={title}
    """
    
    
    with open("FFMETADATAFILE", "a") as myfile:
        myfile.write(text)
    Credit to iKyle at his blog for his original script, which I modified to work specifically with the way Premiere exports markers. Check out that blog post for a more in-depth explanation of how this works.

    EDIT: Changed the code, as the original would not allow spaces in file names. Fixed!
    Last edited by seanmcnally; 16th Nov 2021 at 19:49.
    Quote Quote  



Similar Threads

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