Can ffmpeg write comskip info into the video file?

I took the logic from this thread and translated it into a Windows Batch File (below). From my experience, the chapter idea presented in the thread works. However, while getting this to work I endured a lot of pain:

  • I am finding if I stop a current recording in beta 2 of Plex DVR, no matter what the recording becomes corrupted and can only be played it back in VLC (even without post-processing). This didn’t happen in beta 1. This was annoying when trying to test post-processing.
  • On my machine it takes about as much time to comskip as it does to record. So for a 3 hour football game, the game isn’t available in Plex until 6 hours from the start of the recording. I would much prefer a solution that I can post-process after publishing such that when the file isn’t locked I can move my post-processed file into place. Or better yet, how about we just support EDL files already?
  • It appears that while Plex is doing the post-processing, the ‘tuner slot’ within Plex is taken up (basically, it shows 100% in the server status until post-processing is done). I didn’t do a lot of testing around this, this was just a mental note. Of course the concern is that if both tuners are blocked on post-processing, will it block a scheduled recording?
  • I found on the XBox One, the chapter symbols in the time bar don’t paint until I actually skip to that chapter. It would be nice to get a view of all the chapters without having to skip to them…
  • Of course, unlike something like this NextPVR setup, you cannot get Plex to do this while the content is being recorded.

In any case, here is the current version of my batch script:

@echo off
setlocal enabledelayedexpansion

set comskip=S:\Plex\DvrPostProcessing\comskip81_092\comskip.exe
set mkvpropedit=S:\Plex\DvrPostProcessing\mkvtoolnix\mkvpropedit.exe

set comskiptemp=%~dp1comskip.tmp
set inputmkv=%~f1
set comskipchp=%comskiptemp%\%~n1.chp
set mkvpropchp=%comskipchp%.tmp

if exist "%comskiptemp%" rmdir /s /q "%comskiptemp%"
mkdir "%comskiptemp%"
"%comskip%" -n --output="%comskiptemp%" -v1 --zpchapter "%inputmkv%"

set chapternum=0
for /f "usebackq tokens=1,2,3 delims=(,)" %%a in (`type "%comskipchp%"`) do (
    set offset=
    if /i "%%a"=="AddChapter" if /i "%%c"=="Show Segment" set offset=%%b
    if /i "%%a"=="AddChapterBySecond" if /i "%%c"=="Show Segment" set offset=%%b
    if /i not "!offset!"=="" (
        set /a chapternum=!chapternum! + 1
        set chapterlbl=0!chapternum!
        set chapterlbl=!chapterlbl:~-2!

        set /a hours=!offset! / 3600
        set /a mins=!offset! %% 3600 / 60
        set /a secs=!offset! %% 60
        set hours=0!hours!
        set hours=!hours:~-2!
        set secs=0!secs!
        set secs=!secs:~-2!
        set mins=0!mins!
        set mins=!mins:~-2!

        echo CHAPTER!chapterlbl!=!hours!:!mins!:!secs!.000>>"%mkvpropchp%"
        echo CHAPTER!chapterlbl!NAME=Segment !chapternum!>>"%mkvpropchp%"
    )
)

if %chapternum% GTR 0 (
    "%mkvpropedit%" "%inputmkv%" --edit track:a1 --set language=eng --edit track:v1 --set language=eng --chapters "%mkvpropchp%"
)

rmdir /s /q "%comskiptemp%"
endlocal