[HowTo] Autoedit – Fully automated DVR with commercial detection


Pass library path and header paths in C/XXFLAGS


big log

just errors

so much more confusion FML

i thought this was for pi 3


Ok, going through this one at a time, let’s first try to solve the more severe problem.

Skipping libx265 and building ffmpeg without it (remove the flag --enable-libx265), you clone comskip from github and run:

./configure CFLAGS='-L/opt/vc/lib'

I manually renamed the directory for testing which gave me an additional error, that may or may not occur on the RPi3.

If you get an error starting with

/usr/bin/ld: warning: libvcos.so, needed by /opt/test/lib/libmmal_core.so, not found (try using -rpath or -rpath-link)

then you also have to run

sed -i -e 's/-lpng12 -lm -lz -pthread -lswresample -lm -lavutil -lm/-lpng12 -lm -lz -pthread -lswresample -lm -lavutil -lm -lvcos -lvchiq_arm -lvcsm/' Makefile

This manually adds the shared libraries “-lvcos -lvchiq_arm -lvcsm” to the libraries passed from ffmpeg.

Please report back if it works. Than we can get to compiling the x265 lib.


So I got it working, mostly.

I followed @fretzke and @sam_nazarko suggestion to directly point to the ffmeg libraries and headers using the following code before running ./configure

   export LDFLAGS="-L/opt/vc/lib -L/opt/vc/lib/pkgconfig -L/opt/vc/lib/plugins"
   export CPPFLAGS='-I/opt/vc/include'

I then finished the rest of the instructions without any problem.

Then, we actually executing the autoedit queue, I got the following output

Comskip 0.81.098, made using ffmpeg
Donator build
 0:33:19 - 59912 frames in 1211.40 sec(49.46 fps), 1.00 sec(53.00 fps), 99%
59932 frames decoded in 1211.80 seconds (49.46 fps)
ffmpeg version N-86556-ge639d09 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 4.9.2 (Debian 4.9.2-10)
  configuration: --pkg-config-flags=--static --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree --enable-mmal --enable-decoder=mpeg2_mmal --enable-decoder=mpeg4_mmal --enable-decoder=h264_mmal --enable-decoder=vc1_mmal --enable-omx-rpi --enable-encoder=h264_omx
  libavutil      55. 66.100 / 55. 66.100
  libavcodec     57. 99.100 / 57. 99.100
  libavformat    57. 73.100 / 57. 73.100
  libavdevice    57.  7.100 / 57.  7.100
  libavfilter     6. 94.100 /  6. 94.100
  libswscale      4.  7.101 /  4.  7.101
  libswresample   2.  8.100 /  2.  8.100
  libpostproc    54.  6.100 / 54.  6.100
[mpegts @ 0x17d5290] PES packet size mismatch
    Last message repeated 1 times
Input #0, mpegts, from '/home/osmc/recordings/temp.ts':
  Duration: 00:33:23.09, start: 16027.339211, bitrate: 15298 kb/s
  Program 3 
    Stream #0:0[0x31]: Video: mpeg2video ([2][0][0][0] / 0x0002), yuv420p(top first), 320x240, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x34](eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s
    Stream #0:2[0x35](spa): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, stereo, fltp, 192 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video (mpeg2_mmal) -> h264 (h264_omx))
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[mpeg2_mmal @ 0x17dbc90] Did not get output frame from MMAL.
Error while decoding stream #0:0: Unknown error occurred
[mpeg2_mmal @ 0x17dbc90] Did not get output frame from MMAL.
Error while decoding stream #0:0: Unknown error occurred
[mpeg2_mmal @ 0x17dbc90] Did not get output frame from MMAL.
Error while decoding stream #0:0: Unknown error occurred
[mpeg2_mmal @ 0x17dbc90] Changing output format.
[h264_omx @ 0x180d430] Using OMX.broadcom.video_encode
Output #0, mpegts, to '/home/osmc/recordings/temp_transcode.ts':
    encoder         : Lavf57.73.100
    Stream #0:0: Video: h264 (h264_omx), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 2000 kb/s, 29.97 fps, 90k tbn, 29.97 tbc
      encoder         : Lavc57.99.100 h264_omx
    Stream #0:1(eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s
frame=    1 fps=0.0 q=-0.0 size=       1kB time=00:00:01.56 bitrate=   3.8kbits/frame=    7 fps=6.5 q=-0.0 size=     104kB time=00:00:01.76 bitrate= 483.7kbits/frame=   19 fps= 12 q=-0.0 size=     228kB time=00:00:02.20 bitrate= 845.3kbits/frame=   27 fps= 13 q=-0.0 size=     339kB time=00:00:02.40 bitrate=1158.1kbits/frame=   37 fps= 14 q=-0.0 size=     433kB time=00:00:02.68 bitrate=1319.4kbits/frame=   48 fps= 15 q=-0.0 size=     564kB time=00:00:03.16 bitrate=1457.9kbits/frame=   58 fps= 16 q=-0.0 size=     675kB time=00:00:03.52 bitrate=1570.7kbits/frame=   71 fps= 17 q=-0.0 size=     819kB time=00:00:03.96 bitrate=1690.5kbits/frame=   81 fps= 17 q=-0.0 size=     920kB time=00:00:04.28 bitrate=1758.3kbits/frame=   92 fps= 18 q=-0.0 size=    1037kB time=00:00:04.60 bitrate=1844.4kbits/frame=  104 fps= 18 q=-0.0 size=    1167kB time=00:00:04.92 bitrate=1940.1kbits/frame=  116 fps= 18 q=-0.0 size=    1297kB time=00:00:05.24 bitrate=2024.7kbits/frame=  127 fps= 18 q=-0.0 size=    1440kB time=00:00:05.72 bitrate=2058.8kbits/frame=  137 fps= 18 q=-0.0 size=    1567kB time=00:00:06.04 bitrate=2122.7kbits/frame=  149 fps= 19 q=-0.0 size=    1791kB time=00:00:06.52 bitrate=2247.0kbits/frame=  159 fps= 19 q=-0.0 size=    1904kB time=00:00:06.88 bitrate=2266.7kbits/frame=  170 fps= 19 q=-0.0 size=    1959kB time=00:00:07.32 bitrate=2190.3kbits/frame=  179 fps= 19 q=-0.0 size=    2023kB

So, I’m not totally sure why it changed output format to OMX.broadcom.video_encode, and why it gave me these errors erratically throughout the process:

[mpegts @ 0x17d5290] PES packet size mismatch

The final output video file played mostly alright, but sometimes the video frame froze and the audio continued. Also, the commercials were skipped while playing the video, but the actual frames containing the commercials were not cut/deleted from the video file.

Thanks all for your continued help.


Hi Taylor,

thanks for your feedback!

Did you also compile libx265 on the RPi3? If so, please report what adjustments you made, so I can change the instructions above.

Regarding your error a few things leap to the eye:

Comskip 0.81.098, made using ffmpeg
Donator build
 0:33:19 - 59912 frames in 1211.40 sec(49.46 fps), 1.00 sec(53.00 fps), 99%

Comskip did not finish on the file. It should report 100% progress at the end.

[mpegts @ 0x17d5290] PES packet size mismatch
[mpeg2_mmal @ 0x17dbc90] Did not get output frame from MMAL.
seem not to be directly related, but occur very closely to one another in the original stream (note the stamp).

I suspect at that point in the recording the connection was interrupted, resulting in a broken video file. Depending on what type of connection you use and the signal strength, this can happen more or less frequently, just like the frames sometimes can freeze or show artifacts when watching live TV on a bad connection.

Changing output format.
is not neccessarily an error, but actually a specialty in .ts files. Throughout the stream the video format can change (e.g. the aspect ratio of an old movie differs from the one in the commercials). This is not possible in normal video formats and hence reported as a warning.

[h264_omx @ 0x180d430] Using OMX.broadcom.video_encode
is no error, but the notification about the encoder you specified. This is actually good, as long as it only appears once.

That is exactly the intended behaviour. It would actually not be very difficult to cut out the breaks with ffmpeg, BUT Comskip is not always 100% right. The .ini I included marks commercials in a way that simply let’s you rewind to the beginning of the automatic skip for the case where the marker was not correct. Just use „Chapter back“ on your remote for that.

To check your recorded files for errors you can temporarily disable the transcoding option and then run this on your video files:
ffmpeg -v error -i "your_video_file" -map 0:1 -f null - 2>"video_file.log"
It will log all errors to a corresponding text file and help you determine your connections quality.


So after about a month of continuous use (recorded about 100 shows), I am very pleased with my PiDVR. Thank you all for your help and instructions to get me to this point!

I do have a few last questions/suggestions that might help this PiDVR setup become even more automated and robust.

  1. All of my recorded shows’ (American Ninja Warrior, Seinfeld, The Big Bang Theory, The X-Files, Shark Tank, etc) episode and season information are incorrectly renamed by filebot. The first recorded episode for each TV series is incorrectly renamed, but it is at least renamed in a format that the TV Database understands and can scrape all the associated (albeit incorrect) metadata. Each subsequent recorded episode for the same series cannot be renamed by filebot using the TV Database convention because it always thinks it is the identical episode as the first recorded episode, and therefore it renames the episode like so Seinfeld-.ts, Seinfeld-1.ts, etc.. Presumably whatever metadata is present in the original recorded video file that filebot is using to map each episode to info from the TV Database is erroneous. But, my electronic program guide does contain all the correct information, and I even save my recorded files with the correct metadata in the filename itself (ex. The-Big-Bang-Theory.2017-07-26.19-00.E191.ts, here I didn’t include the subtitle, which is essentially the episode name, but it can be renamed with that info too as seen in the screenshot below).Is there anyway to better inform/pass episode info parameters to filebot to make the renaming more accurate/automated?

  2. I live in a suburban apartment with a rather weak indoor antenna (HOA doesn’t allow outdoor antennas). Some channels that I like to record shows on do not have perfect reception all the time (weather, etc). Therefore, the recorded video files sometimes have dropped frames or other data errors. In fact, TVHeadend keeps track of these errors as shown in the screenshot below.

    A few errors don’t significantly affect the performance of comskip and the encoding process, but when there are too many errors, it oftentimes fails and leaves an unfinished video file (temp.ts), along with an unfinished autoeditQueue. Most of the time I can restart the process and force the process to completion, but it is time consuming and frustrating to have to be looking for this all the time. Is there anyway that I can pass the information about the number of recording errors onto autoedit and then use some type of error count threshold to decide if the file is to troublesome to process and just skip over it if needed?

Thanks for your attention and help. I hazard a guess that others may have experienced similar problems and may either have a good solution, or can also be benefited by a good solution.



Hi Taylor,

very glad to hear that! :grinning:

Yes, there is a rather simple solution: The .ts containers do not store any metadata at all. If you change your recording profile to „matroska“, TVH will generate .mkv files including all metadata. Then renaming works as long as the networks did not fxxx up the title.
Alternatively you can pass the title and episode info via the command line --title "%t" --episode "%s". BUT even though documented on the TVH homepage in TVH 4.0.9 as found in OSMC the %s parameter does not work. Maybe in future releases it will…

Currently not, but this is the next thing on my to do list. I am not aware of a possibility to pull the amount of data errors from TVH, only the error message itself (e.g. “Time misssed”), so the video has to be analyzed with ffmpeg like described above. If an error occurs, the file will be logged and just left as it is. Since I’m creating the process at the moment I’m open for suggestions.


Thanks muchly for this script and the followups.
I was having the same problems compiling Comskip as others here (/usr/bin/ld: cannot find…) and after going through all this a couple of times (there went my Sunday) it finally dawned on me that the files were actually somewhere else.
What I finally did to fix it was

export CPPFLAGS=’-I/opt/vc/include -I/home/osmc/ffmpeg_build/include’

and of course, I had to sudo a couple of the make commands as well.

Also (this is probably obvious, but just in case it helps somebody) the cd userland-master line should actually be cd userland.


Thanks for the feedback! :slight_smile:
I updated the instructions accordingly.


Have you considered writing a similar tutorial, but with a 64-bit build in mind? I’m not running TVH from a raspberry, so there are several areas that won’t work in my case.

Furthermore, a few months ago I was running TVH from an ARM device, but, again, not a raspberry, so I don’t know if this tutorial would have worked in that environment (an odroid xu4) either.


Yes, but for making it publicly available, I’d need some volunteers to test it.
I’m currently playing with an Odroid C2 to replace the good ole Raspi, and so far I can say that Comskip works with only minimal tweaks. Filebot is a no brainer, but compiling ffmpeg with h/w decoding seems to be impossible and h/w encoding is not even supported.
So in the end 2/3 of the functions (and the more important ones to me) will work and the script itself is architecture independent. The transcoding part has to be dropped.
If you are willing to test, I’ll gladly send you what I have.


Alright time to give this another go. Will edit w my experience

Thanks again Fretzke your willingness to come back and help so many times (even when ppl like me rage quit & give up for 3 months) is commendable

and also big thanks to Taylor for having the patience to figure this all out. U are a beacon of hope


Always welcome! :grinning:

Please report if you encounter any problems.


Does this setup delete the adverts from the saved file when transcoding or mark them so they are skipped on replay?


The video is transcoded, and not edited or cut in any way. So the ads are technically still there but will be skipped with the corresponding .edl file.

This way you always have the chance to get back a part that was falsely marked as ad.



Thank you for your How to.
Will you update this how to now that osmc is on stretch.

I think it’s much more simple now. Comskip can be installed straight away from github by just installing ffmpeg.


It is indeed much simpler with Stretch. Instructions have been updated.

Since I moved on from the good 'ole RPi as a media center I cannot test it in depth. Please report if the packaged ffmpeg uses hardware decoding.


m it works but i am not sure about the performance. I get 10 fps when using comskip for HD.264 channels. I had old formats channel SD and there i get 90 fps is what you were observing?


Then the standard ffmpeg is clearly decoding in software. HD h.264 videos exactly equal the RPi’s VPU capability and should run with at least 30 fps.


Updated to version 1.1

To get the latest changes, ssh into the directory, make a backup copy of your settings and then type git pull.

Changes and new features:

  • Duplicate handling: You can now safely remove seen videos directly from within Kodi. The .edl files will remain and autoedit will recognize rerecorded episodes. Duplicates are stored in a seperate folder until deleted and not readded to Kodi.
  • Error handling for the online database: If a movie or episode cannot be found, it will safely be moved to a separate folder and a note written to the log.
  • Command line functions to set title and episode: You can now record in the default .ts format and still use filebot.
  • External transcoding supported: Instead of transcoding in low quality on the RPi you can now add the processed videos to a file for batch processing in higher quality on another computer.
  • Support to remotely update one or more Kodi libraries