PostProccessing: Usage Examples

I’ve got a question that really is unrelated to plex so sorry for throwing it in here, but an issue that I’m running into during post processing of things I’m recording. I’ve not used ffmpeg in the past so I’ll go ahead and admit that I’ve only gotten this far thanks to the great information in this thread.

Regardless - I set up PP following @hthighway 's original post, the exception being that I used his fork that includes encoding to h264 after the split.

When playing, every single video I’ve recorded will halt for a few seconds every so often - then resume looking like the screenshot below. I’ve tried playing the encoded videos in VLC natively and the audio cuts out and the halt isn’t as dramatic but it still happens so something is definitely wrong with the encoded file. I’ve played the original MPEG2 files that are in the .grab folder and they don’t exhibit this so it there isn’t a problem that is created during the recording itself.

Not really certain how to inspect this video for defects, whether its an audio or video track problem (or both).

Thanks in advance.

(/uploads/default/original/3X/5/8/58611eceef062883aa09db04f2303a230d617b1e.png “”)

@TheKreifi said:

@hthighway said:
For ffmpeg, this is the general syntax:
ffmpeg -i inputfile.mkv -crf 18 -map 0 -acodec copy -scodec copy -c:v libx264 -threads 0 -preset veryslow outputfile.mkv

Right now I am testing -preset medium and -crf 20

What did you settle on for your final ffmpeg output? I’m almost done with my linux/bash based version of a comstripping script, but the constant transcode errors have made me have to stop and redo things. If someone has already sorted out the best combo to go from TS to mkv, I’d rather credit/use their work than reinvent the wheel.

It’s likely dependent mostly on your system. You can exclude both options if you wish, depending on your space available and general visual preference of the output file.

veryslow is … very slow. I don’t use any preset when I encode a rip. This is how I run it, and it does a generally ok job. Nothing fancy, all it does is encode to H.264 and just copies the audio channel and any subtitles baked into the MKV container:

ffmpeg -i <input file> -acodec copy -vcodec libx264 -scodec copy <output file>

I have tinkered with some other settings like crf and the presets. I read somewhere that if you start mucking with crf that you should also use the qcomp flag to maintain some extra fidelity:

-vcodec libx265 -preset slower -crf 20.0 -qcomp 0.8

and went off of a doom9 post to use this nightmare of a combination, and while I noticed a slight difference in the final product, overall it wasn’t worth the effort to maintain. The settings might change from encode to encode. Note, the below was me tinkering with HEVC.

-vcodec libx265 -preset slower -ctu 32 -max-tu-size 16 -crf 20.0 -tu-intra-depth 2 -tu-inter-depth 2 -rdpenalty 2 -me 3 -subme 5 -merange 44 -b-intra -no-amp -ref 5 -weightb -keyint 360 -min-keyint 1 -bframes 8 -aq-mode 1 -aq-strength 1.0 -rd 5 -psy-rd 1.5 -psy-rdoq 5.0 -rdoq-level 1 -no-sao -no-open-gop -rc-lookahead 80 -scenecut 40 -max-merge 4 -qcomp 0.8 -no-strong-intra-smoothing -deblock -2:-2 -qg-size 16 -pbratio 1.2

My ffmpeg version, if you were curious:

ffmpeg -version
ffmpeg version 2.6.8 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-4)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-gnutls --enable-ladspa --enable-libass --enable-libcdio --enable-libdc1394 --enable-libfaac --enable-nonfree --enable-libfdk-aac --enable-nonfree --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libx264 --enable-libx265 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
libavutil      54. 20.100 / 54. 20.100
libavcodec     56. 26.100 / 56. 26.100
libavformat    56. 25.101 / 56. 25.101
libavdevice    56.  4.100 / 56.  4.100
libavfilter     5. 11.102 /  5. 11.102
libavresample   2.  1.  0 /  2.  1.  0
libswscale      3.  1.101 /  3.  1.101
libswresample   1.  1.100 /  1.  1.100
libpostproc    53.  3.100 / 53.  3.100

@jonh said:
I’ve got a question that really is unrelated to plex so sorry for throwing it in here, but an issue that I’m running into during post processing of things I’m recording. I’ve not used ffmpeg in the past so I’ll go ahead and admit that I’ve only gotten this far thanks to the great information in this thread.

Regardless - I set up PP following @hthighway 's original post, the exception being that I used his fork that includes encoding to h264 after the split.

When playing, every single video I’ve recorded will halt for a few seconds every so often - then resume looking like the screenshot below. I’ve tried playing the encoded videos in VLC natively and the audio cuts out and the halt isn’t as dramatic but it still happens so something is definitely wrong with the encoded file. I’ve played the original MPEG2 files that are in the .grab folder and they don’t exhibit this so it there isn’t a problem that is created during the recording itself.

Not really certain how to inspect this video for defects, whether its an audio or video track problem (or both).

Thanks in advance.

(/uploads/default/original/3X/5/8/58611eceef062883aa09db04f2303a230d617b1e.png “”)

By chance, is that VLC? I see it all the time in VLC, but my videos play fine on everything else.

@jasonmicron thanks for the info. Subtitles is the next thing I want to focus on. I am hoping for a Plex built in solution, but I’ve had lots of issues with the transcoding so far. I’m debating if it is worth going x264 for stuff that I plan to watch and delete. Or just have it quickly for speed. Granted, 20 minutes isn’t terrible, but for a 1 hour show, it could be a lot longer than that

@jasonmicron well it happens in plex. By using VLC I was just confirming that it wasn’t only Plex having the problem.

For anyone that’s running a headless Plex server without X.org installed and has MythTV installed (probably a super-limited group of folks), I was running into issues compiling comskip.

I adapted some code I wrote for a MythTV project that will invoke Myth’s own commercial flagger (mythcommflag) and crop out the commercials. If anyone’s more familiar with chapters, I’d prefer to flag those instead.

Is there a readme on how to install/compile all the necessary prereq’s for Linux noobs?

@IamSpartacus said:
Is there a readme on how to install/compile all the necessary prereq’s for Linux noobs?

For ffmpeg you will want to follow this guide as you will more than likely want all of the non-free encoders.
https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu
or here for the Centos types:
https://trac.ffmpeg.org/wiki/CompilationGuide/Centos

For Comskip, the instruction are here:

@hthighway said:

@IamSpartacus said:
Is there a readme on how to install/compile all the necessary prereq’s for Linux noobs?

For ffmpeg you will want to follow this guide as you will more than likely want all of the non-free encoders.
CompilationGuide/Ubuntu – FFmpeg
or here for the Centos types:
CompilationGuide/Centos – FFmpeg

For Comskip, the instruction are here:
GitHub - erikkaashoek/Comskip: A free commercial detector

Or - if you’re running CentOS / Fedora / RHEL / etc, look at my posts a page or so back. There are some yum repos that provide this stuff in pre-made RPM format for even easier installation. No compiling required. Specifically, the nux repo.

@hthighway said:

@IamSpartacus said:
Is there a readme on how to install/compile all the necessary prereq’s for Linux noobs?

For ffmpeg you will want to follow this guide as you will more than likely want all of the non-free encoders.
CompilationGuide/Ubuntu – FFmpeg
or here for the Centos types:
CompilationGuide/Centos – FFmpeg

For Comskip, the instruction are here:
GitHub - erikkaashoek/Comskip: A free commercial detector

Thanks!

@jasonmicron said:

@hthighway said:

@IamSpartacus said:
Is there a readme on how to install/compile all the necessary prereq’s for Linux noobs?

For ffmpeg you will want to follow this guide as you will more than likely want all of the non-free encoders.
CompilationGuide/Ubuntu – FFmpeg
or here for the Centos types:
CompilationGuide/Centos – FFmpeg

For Comskip, the instruction are here:
GitHub - erikkaashoek/Comskip: A free commercial detector

Or - if you’re running CentOS / Fedora / RHEL / etc, look at my posts a page or so back. There are some yum repos that provide this stuff in pre-made RPM format for even easier installation. No compiling required. Specifically, the nux repo.

I appreciate that, unfortunately I’m running Debian (Ubuntu Sever 16.04).

@IamSpartacus said:
I appreciate that, unfortunately I’m running Debian (Ubuntu Sever 16.04).

Note: FFmpeg has returned in Ubuntu 15.04 Vivid Vervet. You may still wish to compile if you experience a bug or want to customize your build (like including the non-free parts), and it will not interfere with the ffmpeg package in the repository.

If that is the case you can just do, sudo apt-get install ffmpeg

@hthighway said:

@IamSpartacus said:
I appreciate that, unfortunately I’m running Debian (Ubuntu Sever 16.04).

Note: FFmpeg has returned in Ubuntu 15.04 Vivid Vervet. You may still wish to compile if you experience a bug or want to customize your build (like including the non-free parts), and it will not interfere with the ffmpeg package in the repository.

If that is the case you can just do, sudo apt-get install ffmpeg

Thanks. What about MKVToolNix…needed?

@IamSpartacus said:
Thanks. What about MKVToolNix…needed?

$ wget -q -O - https://mkvtoolnix.download/gpg-pub-moritzbunkus.txt | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install mkvtoolnix

REF: MKVToolNix Downloads – Matroska tools for Linux/Unix and Windows

…and it’s only needed it you want to make sure the media you record show the correct language inside of plex, using mkvpropedit

@hthighway said:

@IamSpartacus said:
Thanks. What about MKVToolNix…needed?

$ wget -q -O - https://mkvtoolnix.download/gpg-pub-moritzbunkus.txt | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install mkvtoolnix

REF: MKVToolNix Downloads – Matroska tools for Linux/Unix and Windows

…and it’s only needed it you want to make sure the media you record show the correct language inside of plex, using mkvpropedit

Got it thanks.

@hthighway said:
**Prerequisites: **
MKVToolNix: https://mkvtoolnix.download/
FFMPEG & Comskip: GitHub - erikkaashoek/Comskip: A free commercial detector
(Note: if you are on Windows you can also install from : http://www.comskip.org/)
PlexComskip.py: Clone the PlexComskip repo: GitHub - ekim1337/PlexComskip
Copy PlexComskip.conf.example to PlexComskip.conf and edit as necessary (defaults should be pretty good)

Ok now I’ve got all of the above done, just unsure what to do with regard to the script below. Where does this get placed and how to I set it to run via the postprocessing field in DVR Settings?

#!/bin/sh
/usr/bin/mkvpropedit "$1" --edit track:a1 --set language=eng --edit track:v1 --set language=eng
sleep 5
/usr/bin/python /path/to/PlexComskip.py "$1" 

@IamSpartacus said:
Ok now I’ve got all of the above done, just unsure what to do with regard to the script below. Where does this get placed and how to I set it to run via the postprocessing field in DVR Settings?

#!/bin/sh
/usr/bin/mkvpropedit "$1" --edit track:a1 --set language=eng --edit track:v1 --set language=eng
sleep 5
/usr/bin/python /path/to/PlexComskip.py "$1" 

You paste that into a file plexdvr.sh, for example

$ mkdir plexscripts
$ cd plexscripts
$ touch plexdvr.sh
$ chmod +x plexdvr.sh
$ nano plexdvr.sh
    past content from above into here
    then exit nana (or whatever your prefered text editor may be)
$ cd ~

Then go to Settings -> Server -> DVR (beta) and select DVR Settings
Scroll to the bottom of the popup screen and enter the path & file name of the above script into the field for POSTPROCESSING SCRIPT

@hthighway said:
You paste that into a file plexdvr.sh, for example

$ mkdir plexscripts
$ cd plexscripts
$ touch plexdvr.sh
$ chmod +x plexdvr.sh
$ nano plexdvr.sh
    past content from above into here
    then exit nana (or whatever your prefered text editor may be)
$ cd ~

Then go to Settings -> Server -> DVR (beta) and select DVR Settings
Scroll to the bottom of the popup screen and enter the path & file name of the above script into the field for POSTPROCESSING SCRIPT

Got it. So I pasted the following in. Any way to confirm it was taken properly by Plex?

curl --header "X-Plex-Token:MYPLEXTOKEN" -X PUT "https://MYIP:32400/livetv/dvrs/MYDVRID/prefs?postprocessingScript=/data/plexdata/Scripts/plexdvr.sh"

Btw I replaced the following variables:

X
MYPLEXTOKEN
MYIP
MYDVRID

@IamSpartacus said:
Any way to confirm it was taken properly by Plex?

curl --header "X-Plex-Token:MYPLEXTOKEN" -X PUT "https://MYIP:32400/livetv/dvrs/MYDVRID/prefs?postprocessingScript=/data/plexdata/Scripts/plexdvr.sh"

Btw I replaced the following variables:

You don’t have to do that curl command anymore if you are on the beta3.
It is in the DVR settings screen now

So all I need is to paste the following path?

/data/plexdata/Scripts/plexdvr.sh

@IamSpartacus said:
So all I need is to paste the following path?

/data/plexdata/Scripts/plexdvr.sh

yes

(I need to update the 1st post now that DVR Beta 3 is out)