• comskip for docker emby

    17 minutes ago 0 comments

    This is a description of how I have set up commercial skipping during playback of my emby recordings.

    I have a few ways of recording live/linear TV. I have both good antenna OTA reception for local channels and various (legal/paid) accesses to other channels. The two server applications I use most for playing or recording live TV are Channels DVR and emby. I run both of them in docker containers on the same Raspberry Pi 4.

    There is a popular application called comskip that analyzes video files and uses several tunable heuristics to detect commercial advertisement breaks. It can output the list of breaks in any of several standard or quasi-standard formats. Probably the most popular output format is EDL, edit decision list. Commercial skipping is a two-part process. First, the video file is analyzed (which to some extent can be done while it's being played or recorded). Second, when the video is played, the player understands the results of the analysis and provides for either manual or automatic skipping of commercial breaks.

    Channels DVR has support for comskip built in, both for the analysis and playback. It's easily configured via the web GUI. emby does not have comskip built in, but it can be added via the sophisticated Emby.Comskipper plugin. The plugin provides the playback skipping based on EDL files. (It also recognizes some specially designated advertising chapter markers sometimes present in video files, though that has nothing to do with comskip.) The author provides detailed and complete instructions for how to hook in the comskip analysis piece to the emby server.

    Although I run emby in a docker container, I wanted to run comskip either in its own container or on the host system. I didn't find a convenient comskip docker image, so I used the glue described below to run comskip on the host RPi 4. Running comskip with 3 threads, the CPU cores are loaded at about 75% each during actual analysis. For now, I only run a single comskip job at a time.

    comskip-inotify.sh

    This is a short shell script that manages the kick-off of comskip jobs. Jobs can be triggered in one of two ways.

    1. When the script starts, it looks for video files in the emby recording area that do not have a companion EDL file. This is a decent enough catch-up technique for crashes, reboots, etc.
    2. After that, it waits for the arrival of new video files from emby. That's done via the inotify-wait tool watching for creation events in the entire emby recording area.

    For either job type, a job is created using task spooler. It's a straightforward queuing tool available in most Linux package repositories.

    There are a couple of odds and ends to deal with in the script.

    • Creating of new directories is ignored.
    • Jobs created in the first step are marked with "FIND" in the queued job. Jobs created for new files are marked with "WAIT". This is mostly for the benefit of manual monitoring of the queue.
    • "WAIT" jobs are pushed to the head of the queue, ahead of all queued "FIND" jobs. That doesn't interrupt any already running job.
    • Task sppoler standard output files and "finished"  are deleted from time to time to get rid of clutter.

    Without further ado, here is comskip-inotify.sh:

    #!/bin/bash
    
    # Top level directory under which emby puts the Live TV recordings (default can be overridden on the command line)
    RECORDINGS=${1:-/shares/emby/programdata/data/livetv/recordings/}
    
    consider_one_file() {
        DIRECTORY=${1}
        FILE=${2}
        HOWCOME=${3}
        case ${HOWCOME} in
    	FIND)
    	    # only process files with a .ts extension where there is not already an EDL file
    	    if [ "${FILE}" != "${FILE%.ts}" -a ! -e "${DIRECTORY}${FILE%.ts}.edl" ]
    	    then
    		queue_one_comskip ${HOWCOME} "${DIRECTORY}" "${FILE}"
    	    fi
    	    ;;
    	WAIT)
    	    # only process files with a .ts-READY extension
    	    if [ "${FILE}" != "${FILE%.ts-READY}" ]
    	    then
    		rm -f "${DIRECTORY}${FILE}"
    		queue_one_comskip ${HOWCOME} "${DIRECTORY}" "${FILE%-READY}"
    	    fi
    	    ;;
        esac
    }
    
    queue_one_comskip() {
        HOWCOME=${1}
        DIRECTORY=${2}
        FILE=${3}
        FULLPATH="${DIRECTORY}...
    Read more »

  • Moving from Google Voice to Google Messages

    10/11/2023 at 20:45 0 comments

    ((I'm moving the content formerly on this page to Instructables to reach a wider audience. And here it is: https://www.instructables.com/HOWTO-Moving-From-Google-Voice-GV-to-Google-Messag/))

  • Lessons learned in duck streaming

    05/06/2023 at 23:04 0 comments

    In the Spring of 2023, a mallard duck hen made a nest in our yard. We knew that meant ducklings in a few weeks, so I scrambled to figure out how to stream it for the enjoyment of friends, neighbors, and strangers. Of course, I don't mean the kind of stream where you might expect to find a duck. I mean a video stream. It's all over now, and the ducks have gone. Here is my Youtube playlist of the highlights.

    I already had a few video cameras scattered about watching the outdoors. Even though we live in a suburb, and even though we have a fenced yard, we do get occasional visits from wildlife: cats, raccoons, cats, a possum, cats, squirrels, cats, and birds. None of those cameras cover the area where the duck nested (I'm pretty sure she didn't think about that when she picked the spot, but who knows). None of my current cameras were suitable for exposure to the amount of rain we're getting this Spring, and none of them have a big friendly button with a label liike "click here to stream to the universe".

    This is a write-up of the ultra-fast learning I did to get my live stream going. 

    I had to work fast because we didn't know how long the duck had already been nesting when we found out about it. A duck will lay eggs for about 10 days before starting incubation. Then all of the eggs incubate for about 28 days. All of the ducklings will hatch within a few hours of each other. Ducklings are "precocial". The mother duck does not actually feed them directly. Instead, within a day or so of hatching, she leads them to some place where they can feed themselves.

    The first thing I did was order an outdoor surveillance camera. My criteria were:

    • at least full HD (1080p) resolution
    • fast delivery
    • cheap, cheap, cheap
    • video stream accessible by 3rd party tools

    Fast delivery and cheap requirements funnelled me to the many, many no-name Chinese cameras on Amazon that could arrive next day or the day after. Without time to really study the matter, 3rd party access to me meant a camera supporting Real Time Streaming Protocol  (RTSP). I later discovered that ONVIF is a sort of profile of conventions and discovery that uses RTSP. I only know a little bit about video codecs, but I had a hunch that H.264 was a good thing to have, and that H.265 was OK but not great to have (for reasons not completely clear to me). Most of the no-name Chinese cameras don't say anything about any of that stuff in their descriptions, but a few do. Most are locked into some proprietary access scheme developed by a chipset maker and need a dedicated mobile app to view the videos.

    I'm not going to bother mentioning the particular model of camera that I got because they come and go anyhow, and it might not even be available by the time you read this. I'll just say that the Amazon description did explicitly mention RTSP support, and it met my other requirements. I'll also mention that the mobile app to configure it was Tuya Smart, which I was already using for other reasons.

    OK, now I had the camera, and I'm skipping the step about running a long orange extension cord and mounting the camera to my fence with an amazing variety of boards and clamps. I was able to get the camera configured in the Tuya Smart app so that I could access the video stream over WiFi. How to get from there to live streaming?

    One of the first things I did, after some Google searching, was install the Agent DVR application from ISpyConnect. This application is pretty cool and supports a huge variety of IP cameras. Since my camera supported ONVIF and RTSP, Agent DVR was able to work out the connection particulars with no trouble at all. Once that was working, it was also willing to tell me what it had discovered about RTSP streams. I found that my camera had a main stream of 1080p and a secondary stream of VGA (640x480). Agent DVR does have the ability to read an RTSP stream and relay it out to a server for live streaming, but that feature is not available in the free, unlicensed version. (That...

    Read more »