Plex DVR & Commercial Skipping with Comskip

Sonny Williams

Dabbler
Joined
Oct 19, 2015
Messages
35
So, I'm a noobler, and am not 100% awesome at running commands like some of y'all! Is anyone able to create an updated list of commands to run to get this installed into my jail? Plex is my primary DVR and I'd really love to get this going, but there have been some updates since the walk-through on page 1. I am running FreeNAS 11 and haven't installed any of the pre-reqs yet.
 

nojohnny101

Wizard
Joined
Dec 3, 2015
Messages
1,478
I'm interested in this as well. Anyone have an updated guide?
 

Tookerder

Dabbler
Joined
Jul 10, 2015
Messages
23
All,

Wanted to post my post processing script in case anyone would like to use. This seems to be working perfectly for me and the output is just the single mkv file. Thanks to everyone above for the examples! Could not have got this working otherwise!!
Code:

#!/bin/csh
set path = ($path /usr/local/bin)

# Sleep for a pseudorandom period (up to 10 seconds) to limit the number of instances that start at once
sleep `echo $%10 | bc`
set a =  ` echo "$1" | rev | cut -c 4- | rev `

while (1)
if (! `pgrep comskip` ) then
break
endif
echo "Comskip is already running. Will try again in a minute."
sleep 60
end


/comchap/comcut --ffmpeg=/usr/local/bin/ffmpeg --comskip=/comskiplinux/Comskip-master/comskip --lockfile=/tmp/comchap.lock --comskip-ini=/comskiplinux/Comskip-master/comskip.ini "$1"


while (1)
if (! `pgrep HandBrakeCLI` ) then
break
endif
echo "HandBrakeCLI is still running. Will try again in a minute."
sleep 60
end

HandBrakeCLI -i "$1" -o "$1".mkv --format mkv --encoder x264 --quality 18 --loose-anamorphic --decomb fast --x264-preset medium --h264-profile high --h264-level 4.1 --aencoder ac3 --mixdown 5point1

mv "$1".mkv "$a".mkv
rm "$1"
 
Joined
Nov 19, 2017
Messages
5
Now that Beta 3 has been released and the post-processing command-line option added to the GUI, I tried compiling Comskip and wound up at the following error when I ran out of time:
Code:
root@comskiptest:/Comskip # ./autogen.sh

Preparing the Comskip build system...please wait


Found GNU Autoconf version 2.69

Found GNU Automake version 1.15

Found GNU Libtool version 2.4.6


Automatically preparing build ... done


The Comskip build system is now prepared.  To build here, run:

  ./configure

  make

root@comskiptest:/Comskip #  ./configure

checking for a BSD-compatible install... /usr/bin/install -c

checking whether build environment is sane... yes

checking for a thread-safe mkdir -p... ./install-sh -c -d

checking for gawk... no

checking for mawk... no

checking for nawk... nawk

checking whether make sets $(MAKE)... yes

checking whether make supports nested variables... yes

checking for gcc... no

checking for cc... cc

checking whether the C compiler works... yes

checking for C compiler default output file name... a.out

checking for suffix of executables...

checking whether we are cross compiling... no

checking for suffix of object files... o

checking whether we are using the GNU C compiler... yes

checking whether cc accepts -g... yes

checking for cc option to accept ISO C89... none needed

checking whether cc understands -c and -o together... yes

checking for style of include used by make... GNU

checking dependency style of cc... gcc3

checking for fmax in -lm... yes

checking for sem_post in -lpthread... yes

checking build system type... amd64-unknown-freebsd10.3

checking host system type... amd64-unknown-freebsd10.3

checking whether host is win32... no

checking whether host is darwin... no

checking whether to enable donator features... yes

checking whether to build a statically linked binary... no

checking whether to build with debugging options enabled... no

checking for pkg-config... /usr/local/bin/pkg-config

checking pkg-config is at least version 0.9.0... yes

checking for argtable2... no

configure: error: Package requirements (argtable2 >= 2.12) were not met:


Package argtable2 was not found in the pkg-config search path.

Perhaps you should add the directory containing `argtable2.pc'

to the PKG_CONFIG_PATH environment variable

Package 'argtable2', required by 'world', not found


Consider adjusting the PKG_CONFIG_PATH environment variable if you

installed software in a non-standard prefix.


Alternatively, you may set the environment variables argtable2_CFLAGS

and argtable2_LIBS to avoid the need to call pkg-config.

See the pkg-config man page for more details.

root@comskiptest:/Comskip # pkg-config --variable pc_path pkg-config

/usr/local/libdata/pkgconfig:/usr/libdata/pkgconfig

root@comskiptest:/Comskip # pkg-config --define-variable=pc_path=/usr/local/libdata/pkgconfig:/usr/libdata/pkgconfig:/argtable/argtable2-13 pkg-config

root@comskiptest:/Comskip # pkg-config --variable pc_path pkg-config

/usr/local/libdata/pkgconfig:/usr/libdata/pkgconfig

root@comskiptest:/Comskip #



I know there are issues with using pkg-config with FreeBSD, so maybe that's the source of the problem? I won't have time to mess with it again before the weekend.

Also, FYI, I did try installing Ubuntu in a VirtualBox. This installed okay, but wound up throwing a kernel panic while Comskip was running.
I'm stuck at the configure step with this same problem, how did you fix it?
 

bpl294

Cadet
Joined
May 29, 2018
Messages
3
Has anyone had an issue running handbrake? i installed it and added the line to the script, but it doesn't convert the file due to it missing the libmp3lame plugin. I have tried to install it but comes back that it's not supported on my system anymore.

please help....
 

julianjb777

Cadet
Joined
May 31, 2018
Messages
1
Hey folks i want to say thanks for this forum and thank you for this guide.

I have the postproccessing script working when I run the script manually as root on a file >> ./post.sh /path/to/file
The script im using uses comskip to cut commercials, ccextrator to rip the cc to srt, then FFMPEg to encode to mkv...

But when Plex records, script runs, cuts the commercials but does not rip the cc or encode not sure why.

Here is the post script i run:

Code:
#!/bin/csh

set path = ($path /usr/local/bin)
set lockFile = '/tmp/dvrProcessing.lock'
set origFile = "$1"
set tmpEncode = "$1.mkv"
set dvrPostLog = '/mnt/media/dvrProcessing.log'
set tmpSrt = "English.srt"
set NAME = `echo $tmpEncode | cut -f 1,3 -d'.'`


#Wait if post processing is already running
while ( -f $lockFile )
	echo "`date '+%Y-%m-%d %H:%M:%S'` - '$lockFile' exists, sleeping processing of '$origFile'" | tee $dvrPostLog
	sleep 10
end

#Create lock file to prevent other post-processing from running simultaneously
echo "`date '+%Y-%m-%d %H:%M:%S'` - Creating lock file for processing '$origFile'" | tee -a $dvrPostLog
touch $lockFile

#Mark and cut commercials ; be sure to spcify each directory below
echo "`date '+%Y-%m-%d %H:%M:%S'` - Mark and cut commercials from '$origFile'" | tee -a $dvrPostLog
/comchap/comcut --ffmpeg=/usr/local/bin/ffmpeg --lockfile=/tmp/comchap.lock --comskip-ini=/comskiplinux/Comskip-master/comskip.ini --comskip=/comskiplinux/Comskip-master/comskip "$origFile"

#Pull CC from file to SRT file
echo "`date '+%Y-%m-%d %H:%M:%S'` - Pulling Closed captions from '$origFile' to SRT file" | tee -a $dvrPostLog
/ccextractor/build/ccextractor "$origFile" -o "$tmpSrt"

#Encode file to H.265 with mkv container using ffmpeg
echo "`date '+%Y-%m-%d %H:%M:%S'` - Re-encoding '$origFile' to MKV file while adding cc data" | tee -a $dvrPostLog
/usr/local/bin/ffmpeg -i "$origFile" -i "$tmpSrt" -map 0 -map 1 -acodec copy -scodec copy -c:v libx264 -preset veryfast -crf 18 -profile:v high -level 4.2 -vf yadif "$tmpEncode"

#Remove SRT file
echo "`date '+%Y-%m-%d %H:%M:%S'` - Remove SRT file" | tee -a $dvrPostLog
rm -f "$tmpSrt"

#Remove the .ts from file name
echo "`date '+%Y-%m-%d %H:%M:%S'` - Removing .ts from file name" | tee -a $dvrPostLog
mv -f "$tmpEncode" "$NAME"

#Remove original ts file
echo "`date '+%Y-%m-%d %H:%M:%S'` - Deleting '$origFile'" | tee -a $dvrPostLog
mv -f "$origFile" /tmp/videos/

#Remove lock file
echo "`date '+%Y-%m-%d %H:%M:%S'` - Done processing '$origFile' removing lock" | tee -a $dvrPostLog
rm $lockFile   

exit 0


Thanks to the members here and in the emby forums I was able to edit the script to make it more to my linking i had no clue what i was doing so the scripts here and google helped me put this together.

I added the timestamp to the log file so I can see how long it would take to encode etc. I used
Code:
set NAME = `echo $tmpEncode | cut -f 1,3 -d'.'`
to rename the filename.ts.mkv to filename.mkv it works not sure if it the right way but it worked for me.

I think it may be permissions that is why the script only runs up to commercial cut. I never had to do anything to give plex user permissions to run comskip, comcut etc. So not really sure what is going on.

Any help is appreciated thank you.
 

NasKar

Guru
Joined
Jan 8, 2016
Messages
739
Has anyone had an issue running handbrake? i installed it and added the line to the script, but it doesn't convert the file due to it missing the libmp3lame plugin. I have tried to install it but comes back that it's not supported on my system any more.

I think you have to install ffmpeg from ports and select the lame option. Then handbrake will work.
 
Last edited:

bpl294

Cadet
Joined
May 29, 2018
Messages
3
I think you have to install ffmpeg from ports and select the lame option. Then handbrake will work.

Thanks i was able to in stall the ports using the allow unsupported switch.

another question, is there anyway to limit the number of cores that handbrake uses for a conversion? or delay them to a later time? i find that it's using all my cores and affecting transcoding playbacks on my plex.
 

Architct

Cadet
Joined
Feb 10, 2016
Messages
9
Hey folks i want to say thanks for this forum and thank you for this guide.

I have the postproccessing script working when I run the script manually as root on a file >> ./post.sh /path/to/file
The script im using uses comskip to cut commercials, ccextrator to rip the cc to srt, then FFMPEg to encode to mkv...

But when Plex records, script runs, cuts the commercials but does not rip the cc or encode not sure why.

Here is the post script i run:

Code:
#!/bin/csh

set path = ($path /usr/local/bin)
set lockFile = '/tmp/dvrProcessing.lock'
set origFile = "$1"
set tmpEncode = "$1.mkv"
set dvrPostLog = '/mnt/media/dvrProcessing.log'
set tmpSrt = "English.srt"
set NAME = `echo $tmpEncode | cut -f 1,3 -d'.'`


#Wait if post processing is already running
while ( -f $lockFile )
	echo "`date '+%Y-%m-%d %H:%M:%S'` - '$lockFile' exists, sleeping processing of '$origFile'" | tee $dvrPostLog
	sleep 10
end

#Create lock file to prevent other post-processing from running simultaneously
echo "`date '+%Y-%m-%d %H:%M:%S'` - Creating lock file for processing '$origFile'" | tee -a $dvrPostLog
touch $lockFile

#Mark and cut commercials ; be sure to spcify each directory below
echo "`date '+%Y-%m-%d %H:%M:%S'` - Mark and cut commercials from '$origFile'" | tee -a $dvrPostLog
/comchap/comcut --ffmpeg=/usr/local/bin/ffmpeg --lockfile=/tmp/comchap.lock --comskip-ini=/comskiplinux/Comskip-master/comskip.ini --comskip=/comskiplinux/Comskip-master/comskip "$origFile"

#Pull CC from file to SRT file
echo "`date '+%Y-%m-%d %H:%M:%S'` - Pulling Closed captions from '$origFile' to SRT file" | tee -a $dvrPostLog
/ccextractor/build/ccextractor "$origFile" -o "$tmpSrt"

#Encode file to H.265 with mkv container using ffmpeg
echo "`date '+%Y-%m-%d %H:%M:%S'` - Re-encoding '$origFile' to MKV file while adding cc data" | tee -a $dvrPostLog
/usr/local/bin/ffmpeg -i "$origFile" -i "$tmpSrt" -map 0 -map 1 -acodec copy -scodec copy -c:v libx264 -preset veryfast -crf 18 -profile:v high -level 4.2 -vf yadif "$tmpEncode"

#Remove SRT file
echo "`date '+%Y-%m-%d %H:%M:%S'` - Remove SRT file" | tee -a $dvrPostLog
rm -f "$tmpSrt"

#Remove the .ts from file name
echo "`date '+%Y-%m-%d %H:%M:%S'` - Removing .ts from file name" | tee -a $dvrPostLog
mv -f "$tmpEncode" "$NAME"

#Remove original ts file
echo "`date '+%Y-%m-%d %H:%M:%S'` - Deleting '$origFile'" | tee -a $dvrPostLog
mv -f "$origFile" /tmp/videos/

#Remove lock file
echo "`date '+%Y-%m-%d %H:%M:%S'` - Done processing '$origFile' removing lock" | tee -a $dvrPostLog
rm $lockFile  

exit 0


Thanks to the members here and in the emby forums I was able to edit the script to make it more to my linking i had no clue what i was doing so the scripts here and google helped me put this together.

I added the timestamp to the log file so I can see how long it would take to encode etc. I used
Code:
set NAME = `echo $tmpEncode | cut -f 1,3 -d'.'`
to rename the filename.ts.mkv to filename.mkv it works not sure if it the right way but it worked for me.

I think it may be permissions that is why the script only runs up to commercial cut. I never had to do anything to give plex user permissions to run comskip, comcut etc. So not really sure what is going on.

Any help is appreciated thank you.

Not sure if you solved this problem or not, but for the sake of others reading this in the future and the information being all in one place - Plex expects the file to be named the same once processing has occurred.

Once you "Remove original .ts from file name" Plex will not continue with the file after your post script ends. This is expected behavior as once the file is different than $1, how would Plex know what the file became.

To solve the problem, keep the .ts file extension and sed/awk (whatever) out the mkv from the .ts.mkv extension and Plex will continue as expected - move it to the proper media destination. Understand that it will be named with the extension of .ts (assuming your sed/awk/whatever was correct) and you will need to write a cron job (skip .grab directory), or other method (manual?) to replace the .ts with .mkv.

Hope this helps.
 

algreen82

Cadet
Joined
Apr 9, 2019
Messages
4
I've searched high and low across this forum and the web, I can't seem to fix the issue with the missing package "argtable", all others (except nano) install. How do i fix?! This is driving me crazy hope someone can help.
 
D

dlavigne

Guest
@algreen82 if this is still an issue for you, please start a new thread with your details (FreeNAS version, which pkg command is failing, exact error message, etc.).
 

hagak

Cadet
Joined
Apr 6, 2019
Messages
6
I have been trying to set this up. I have comcut working just fine, however when I replace comcut with comchap I get an error:
Unable to find a suitable output format for ''
 

hagak

Cadet
Joined
Apr 6, 2019
Messages
6
I have been trying to set this up. I have comcut working just fine, however when I replace comcut with comchap I get an error:
Unable to find a suitable output format for ''
Figured out the issue. The comchap script was using mktemp --suffix however the version of mktemp I had did not have --suffix option, so I modified the script to just add the suffix manually.

Also note for others who may find this. My TV shows are in .ts format. .ts files do not support chapters so I had to further modify the comchap script to have the FFmpeg copy the stream to an mkv file instead of inlace as .ts.
 

hechacker1

Cadet
Joined
Jun 28, 2019
Messages
1
Here's what I did to get comskip installed on top of FreeNAS 11.2

Download prerequisite packages:

Code:
pkg update
pkg install wget
pkg install unzip
pkg install autoconf
pkg install automake
pkg install libtool
pkg install ffmpeg
pkg install bash
pkg install gcc8
pkg install git

Run bash

bash [enter]

Change pkg-config references to pkgconf and install pkgconf

Code:
pkg set -o devel/pkg-config:devel/pkgconf
pkg install -f devel/pkgconf

Use Clang:

setenv CC clang

Get the packages:

cd (to home directory)

fetch http://prdownloads.sourceforge.net/argtable/argtable2-13.tar.gz

tar -xf argtable2-13.tar.gz

cd argtable2-13

export PKG_CONFIG_PATH=/usr/local/lib:/usr/local/lib/pkgconfig

./configure
make
make install

cd (back to home directory)

git clone https://github.com/erikkaashoek/Comskip

cd Comskip

./autogen.sh
./configure
make install
 
Last edited:

Rudi Pittman

Contributor
Joined
Dec 22, 2015
Messages
161
Here's what I did to get comskip installed on top of FreeNAS 11.2

Download prerequisite packages:

Code:
pkg update
pkg install wget
pkg install unzip
pkg install autoconf
pkg install automake
pkg install libtool
pkg install ffmpeg
pkg install bash
pkg install gcc8
pkg install git

Run bash

bash [enter]

Change pkg-config references to pkgconf and install pkgconf

Code:
pkg set -o devel/pkg-config:devel/pkgconf
pkg install -f devel/pkgconf

Use Clang:

setenv CC clang

Get the packages:

cd (to home directory)

fetch http://prdownloads.sourceforge.net/argtable/argtable2-13.tar.gz

tar -xf argtable2-13.tar.gz

cd argtable2-13

export PKG_CONFIG_PATH=/usr/local/lib:/usr/local/lib/pkgconfig

./configure
make
make install

cd (back to home directory)

git clone https://github.com/erikkaashoek/Comskip

cd Comskip

./autogen.sh
./configure
make install


I really appreciate this post. I used this in combination with the post here: https://emby.media/community/index....removal-from-tv-recordings/page-5#entry740099 to get my comskip/transcode working on freenas 11.3. They have a script that automates many of these steps but it does not handle the issue with argtable2 or pkg config. I then used the post3.sh in that forum post without issue. I do wish they would do some error checking (it looks to me like it would delete the ts even if the comskip or transcode failed) but will continue to see about enhancing the script. First willl be backing up all the .ts files to an archive so the job can be re-ran upon errors. For whatever reason nano and wget both seem unavailable to be installed so I grabbed the source for nano and compiled it myself.
 
Last edited:
Top