Linux commercial detection

I’ve updated comcut with command line arguments for the following:

  • --ffmpeg=/path/to/ffmpeg allows ability to specify path to ffmpeg if needed
  • --comskip=/path/to/comskip allows ability to specity path to comskip if needed
  • --lockfile=/path/to/lockfile allows ability to specify a lockfile which makes the script wait until the file no longer exists
  • --keep-edl tells comcut to not delete the edl file when done (this is helpful for testing so you dont have to wait for comskip to complete every time when debugging)
  • --keep-meta tells comcut to not delete the ffmeta file when done. Not sure how this would be helpful, but what the hell

I’ve also changed the shebang to get bash, this should help when bash itself is located elsewhere.

comchap will have the same changes done. Probably later today.

@Bollar, I think these changes would make it so your branch is mostly no longer necessary. I know there are differences with mktemp. I think I’ll make another change so it doesn’t even call mktemp, just generate the temporary file names manually with some naming convention. Do you have any input/concerns?

@bjs1400 said:
@Bollar, I think these changes would make it so your branch is mostly no longer necessary. I know there are differences with mktemp. I think I’ll make another change so it doesn’t even call mktemp, just generate the temporary file names manually with some naming convention. Do you have any input/concerns?

Sure, if it works in FreeBSD with Plex, I’m pleased to deprecate mine. I think you need to add a command line argument to call a specific comskip.ini (because different channels get better results with different .ini files), so that would need need to be full path and filename.

Otherwise, I was thinking about adding transcoding as an option, so maybe that could be something to consider in the future.

Does the shebang change work on your FreeBSD box? (#!/usr/bin/env bash)

I’ll also add a --comskip-ini=/path/to/comskip.ini option.

Personally I feel that transcoding should be done in a separate script. I dislike mega-scripts. This should lead to simple Plex post-processing scripts for specific use cases.

On a separate note, you may be interested in my plex-scripts GitHub repo. (https://github.com/BrettSheleski/plex-scripts). In my post-processing script on my Plex-box I’m using these scripts to send me an email which will include a screenshot of the episode recorded, a series image from fanart.tv, as well as plot synopsis of the episode from TheTVDB. It’s still a work in progress though.

@bjs1400 said:
Does the shebang change work on your FreeBSD box? (#!/usr/bin/env bash)
It worked from the command line, but not from Plex. The log shows:

Oct 19, 2016 15:23:00.798 [0x80bc54800] DEBUG - MediaGrabber: Freed a tuner (now 3 available)
Oct 19, 2016 15:23:00.798 [0x80bc54800] DEBUG - Job running: '/comskiplinux/Comskip-master/comcut.sh' '/media/dvr/.grab/de44b0d62e990980bbecb3eb3028876614d521c3/Three\'s Company (1977) - S06E17 - Urban Plowboy.ts'
Oct 19, 2016 15:23:00.856 [0x809814800] ERROR - JobManager: child process returned: 127 (Unknown error: 127)
Oct 19, 2016 15:23:00.856 [0x80bc54800] DEBUG - Jobs: '/comskiplinux/Comskip-master/comcut.sh' exit code is 127
Oct 19, 2016 15:23:00.856 [0x80bc54800] ERROR - MediaRecorder: Postprocessing script '/comskiplinux/Comskip-master/comcut.sh' exited with error code 127.
Oct 19, 2016 15:23:00.856 [0x80bc54800] DEBUG - Activity: Ended activity a8cdbb84-dc7d-4aa7-9131-d89511ce28fe.
Oct 19, 2016 15:23:00.856 [0x80bc54800] DEBUG - MediaGrabber: Operation for Three's Company - S6 E17 - Urban Plowboy completed with status 5 (An error occurred while postprocessing the recording.)
Oct 19, 2016 15:23:00.997 [0x80bc54800] DEBUG - MediaGrabber: Scheduling 'Three's Company - S6 E17 - Urban Plowboy' for post-processing.
Oct 19, 2016 15:23:00.997 [0x809814400] WARN - MediaGrabber: Final status was 5, not going to postprocess.

Hmmmm… My guess would be an environment variable difference. Perhaps you could make a wrapper-script which modifies the PATH environment variable including wherever your bash lives then call comcut. I assume you’d have to write a wrapper-script anyway specifying ffmpeg and comskip paths, so it shouldn’t be a big deal.

Since we’re going to need a script to call comcut.sh anyway, I wonder if this in the script would work?

/usr/local/bin/bash /path/to/comcut.sh (command line args)

Ha, there you go. Even better.

@Bollar said:

@bjs1400 said:
Does the shebang change work on your FreeBSD box? (#!/usr/bin/env bash)
It worked from the command line, but not from Plex. The log shows:

Oct 19, 2016 15:23:00.798 [0x80bc54800] DEBUG - MediaGrabber: Freed a tuner (now 3 available)
Oct 19, 2016 15:23:00.798 [0x80bc54800] DEBUG - Job running: '/comskiplinux/Comskip-master/comcut.sh' '/media/dvr/.grab/de44b0d62e990980bbecb3eb3028876614d521c3/Three\'s Company (1977) - S06E17 - Urban Plowboy.ts'
Oct 19, 2016 15:23:00.856 [0x809814800] ERROR - JobManager: child process returned: 127 (Unknown error: 127)
Oct 19, 2016 15:23:00.856 [0x80bc54800] DEBUG - Jobs: '/comskiplinux/Comskip-master/comcut.sh' exit code is 127
Oct 19, 2016 15:23:00.856 [0x80bc54800] ERROR - MediaRecorder: Postprocessing script '/comskiplinux/Comskip-master/comcut.sh' exited with error code 127.
Oct 19, 2016 15:23:00.856 [0x80bc54800] DEBUG - Activity: Ended activity a8cdbb84-dc7d-4aa7-9131-d89511ce28fe.
Oct 19, 2016 15:23:00.856 [0x80bc54800] DEBUG - MediaGrabber: Operation for Three's Company - S6 E17 - Urban Plowboy completed with status 5 (An error occurred while postprocessing the recording.)
Oct 19, 2016 15:23:00.997 [0x80bc54800] DEBUG - MediaGrabber: Scheduling 'Three's Company - S6 E17 - Urban Plowboy' for post-processing.
Oct 19, 2016 15:23:00.997 [0x809814400] WARN - MediaGrabber: Final status was 5, not going to postprocess.

I’d be remiss if I didn’t…

Urban Plowboy… chuckle

Both comcut and comchap have been updated. Now both can specify paths to ffmpeg, comskip and comskip ini file.

use --fmpeg=/path/to/ffmpeg, --comskip=/path/to/comskip and --comskip-ini=/path/to/comskip.ini command line arguments to set the values.

I just made another change to comcut so it no longer uses mktemp for making temp files for each part.

@Bollar, this, and the --comskip-ini command line argument were done just for you :wink:

Edit: I should add that I have not tested the mktemp change as I don’t have any test files with commercials anymore. But it shouldn’t be an issue.

@bjs1400 said:
I just made another change to comcut so it no longer uses mktemp for making temp files for each part.

@Bollar, this, and the --comskip-ini command line argument were done just for you :wink:

Edit: I should add that I have not tested the mktemp change as I don’t have any test files with commercials anymore. But it shouldn’t be an issue.

It’s true, I do feel special… :wink:

Now I just need to figure out how to get a csh script to successfully call your bash script…

No luck so far.

This works from the command line, but not through Plex:

    #!/bin/csh
echo Processing: "$1" >> /tmp/comchap.log
    /usr/local/bin/bash /comchap/comcut --ffmpeg=/usr/local/bin/ffmpeg --comskip=/comskiplinux/Comskip-master/comskip --lockfile=/tmp/comchap.lock --comskip-ini=/comskiplinux/Comskip-master/comskip.ini "$1"
    echo Completed: "$1" >> /tmp/comchap.log
    
Oct 19, 2016 23:30:01.969 [0x80c515000] DEBUG - Job running: '/postprocessing.sh' '/media/dvr/.grab/119f0f7387866a00d037ea6e4fd84bc874bc625d/2 Broke Girls (2011) - S01E05 - And the \'90s Horse Party.ts'
Oct 19, 2016 23:30:02.037 [0x809814800] ERROR - JobManager: child process returned: 1 (Operation not permitted)
Oct 19, 2016 23:30:02.037 [0x80c515000] DEBUG - Jobs: '/postprocessing.sh' exit code is 1

I assume you’ve run your script as the plex-user and no issues. I had a similar issue when testing comchap/comcut and turned out to be an environment variable issue.

How about modifying your script as the following:

#!/bin/csh

# write the environment variables to file for comparison
env >> /tmp/comchap.env

echo Processing: "$1" >> /tmp/comchap.log

#redirect stdout and stderr to the log file
/usr/local/bin/bash /comchap/comcut --ffmpeg=/usr/local/bin/ffmpeg --comskip=/comskiplinux/Comskip-master/comskip --lockfile=/tmp/comchap.lock --comskip-ini=/comskiplinux/Comskip-master/comskip.ini "$1"  >> /tmp/comchap.log 2>&1
    echo Completed: "$1" >> /tmp/comchap.log

Thanks. There are several idiosyncrasies with FreeBSD jails and permissions, but this script appears to work. I’ll test it today.

#!/bin/csh
# Add bash path to Plex path.
set path = ($path /usr/local/bin)
# Sleep for a pseudorandom period (up to 10 seconds) to limit the number of instances that sta$
sleep `echo $$%10 | bc`
echo Processing: "$1" >> /tmp/comchap.log
/comchap/comcut --ffmpeg=/usr/local/bin/ffmpeg --comskip=/comskiplinux/Comskip-master/comskip $

Had to add the random sleep line to keep all of the jobs hitting the processing script all at once.

See also this thread I started. I wonder if Plex is overly sensitive to work files in the .grab directories?

Yeah, based on my tests, it would be prudent to also allow the --output option e.g.:

/comskiplinux/Comskip-master/comskip --ini=/comskiplinux/Comskip-master/comskip.ini --output=/tmp "$1"

The cleanup routines would need to be changed to delete the work files from the output directory.

I can add a --output option for this which would be used to pass to comskip as well as where the ffmeta file is written to. The variables that hold onto the work-file names will just be modified to also look at the --output option.

@bjs1400 said:
I can add a --output option for this which would be used to pass to comskip as well as where the ffmeta file is written to. The variables that hold onto the work-file names will just be modified to also look at the --output option.

Sounds good.

@Bollar said:
See also this thread I started. I wonder if Plex is overly sensitive to work files in the .grab directories?

https://forums.plex.tv/discussion/241688/post-processing-successful-but-plex-doesnt-move-file-into-library/p1?new=1

Yes based on my experience anything left in work could affect the video file making its way to your library destination.

It sounds like he’s talking about Plex sometimes not moving the file even though it is the only file in the grab dir.

I’ve had Plex lose metadata for files when manually doing post-processing on files already in the library. This is why I was happy they exposed a way of post-processing DVR recordings assuming that the metadata loss would not occur. I’ve had this happen when I manually call comchap/comcut on a file already in the library which results in the original file being modified. Seems like Plex is “watching” all files and if the file is modified in any way it triggers a rescan and re-grab metadata for the file and sometimes failing or the file being matched to something else completely. I’ve noticed this happen when comchap/comcut-ing NFL recordings.

It seems like Plex is also “watching” files in the grab directory too for some reason. I’m not so sure this is a bug with Plex or not, but the two symptoms may be related.

However, since removing the work-files I have not experienced any problems with recordings being moved as they should.