Giter VIP home page Giter VIP logo

comfy-channel's Introduction

Comfy Channel

Comfy Channel is a 24/7 live video broadcast with automatic content selection and overlays using FFMPEG and Python!

Comfy Channel

This repository comes with some example content and configurations that can be used to set up Comfy Channel.

How to run

Perform the steps outlined in Requirements first!!!

The main program is ComfyChannel.py. The following is an example command:

src/ComfyChannel.py -o "rtmp://localhost/live/stream"

The full list of arguments is as follows:

usage: ComfyChannel.py [-h] [-l] [-o OUTPUT] [-ua UPNEXT_AUDIO_FILE]
                       [-uv UPNEXT_VIDEO_FILE] [-uw UPNEXT_WISDOM_FILE]
                       [-f FONT_FILE] [-p PLAYOUT_FILE]

optional arguments:
  -h, --help            show this help message and exit
  -1, --once            run playout only once
  -o OUTPUT, --output OUTPUT
                        output location (stream url)
  -ua UPNEXT_AUDIO_FILE, --upnext_audio_file UPNEXT_AUDIO_FILE
                        folder for upnext audio files
  -uv UPNEXT_VIDEO_FILE, --upnext_video_file UPNEXT_VIDEO_FILE
                        folder for upnext video files
  -uw UPNEXT_WISDOM_FILE, --upnext_wisdom_file UPNEXT_WISDOM_FILE
                        file for wisdom text
  -f FONT_FILE, --font_file FONT_FILE
                        font file for overlay text
  -p PLAYOUT_FILE, --playout_file PLAYOUT_FILE
                        config file for playout

Docker images

To make things easier, I have created two Docker images for quickly setting up Comfy Channel. Visit the following repositories for instruction on setting up the images:

mvarhola/comfy-channel: https://github.com/mvarhola/comfy-channel-docker

mvarhola/nginx-rtmp: https://hub.docker.com/r/mvarhola/nginx-rtmp/

Requirements

Comfy Channel requires FFMPEG to be compiled with libfreetype and libfdk_aac, which are not included in most distributed ffmpeg packages.

For Mac OS Homebrew users, install homebrew-ffmpeg, which will have the required libraries. To install ffmpeg with all available libraries, run the following command:

brew options ffmpeg

brew install ffmpeg \
--with-chromaprint \
--with-fdk-aac \
--with-fontconfig \
--with-freetype \
--with-frei0r \
--with-game-music-emu \
--with-libass \
--with-libbluray \
--with-libbs2b \
--with-libcaca \
--with-libgsm \
--with-libmodplug \
--with-libsoxr \
--with-libssh \
--with-libvidstab \
--with-libvorbis \
--with-libvpx \
--with-opencore-amr \
--with-openh264 \
--with-openjpeg \
--with-openssl \
--with-opus \
--with-rtmpdump \
--with-rubberband \
--with-sdl2 \
--with-snappy \
--with-speex \
--with-tesseract \
--with-theora \
--with-tools \
--with-two-lame \
--with-wavpack \
--with-webp \
--with-x265 \
--with-xz \
--with-zeromq \
--with-zimg

There are also modules that need to be installed by Python. To do so, run the follwing command:

pip install -r src/requirements.txt

The pymediainfo requires you have the package mediainfo installed on your machine (which it is not by default on Ubuntu 18).

Adding your own files

playout.ini contains the order of blocks that will be played by Comfy Channel. A block is a section of content that will be played from a single folder.

[Block1]
name = "Test Block 1"
folder = videos
files = 2
bump_chance = 0.2

A Block contains the block name, the folder location for the files, the number of files to play, and the chance that a bump will be played after each file.

To add a new block, copy and paste one of the example sections and change the name, folder, files, and bump_chance.

Terminology

Playout: a sequence of blocks that Comfy Channel will play in order. The sequence is defined in playout.ini

Block: a section of content that will be played from a single folder.

Bump: a short video selected from the bumps folder that can include a brief announcement. For examples, check out [bumpworthy].

Upnext: a auto-generated video that gets played in between each block. Shows the upcoming videos, what time they will be played, and a short wisdom text. The video and audio files of the upnext can be different.

Wisdom: Comfy Channel will pick a random line from the wisdom file to insert into the upnext.

Inspiration

My main goal for Comfy Channel was to have the little clock in the top left corner like you see on Japanese TV

Included media

Videos: Various videos that I recorded

Font: HC Maru Gothic font

Upnext audio files from: Delroy Edwards - SLOWED DOWN FUNK

comfy-channel's People

Contributors

mvarhola avatar thederpysage avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

comfy-channel's Issues

Docker!

Is docker necessary to run the script?

Missing Dependancy

The pymediainfo requires you have the package mediainfo installed on your machine (which it is not by default on Ubuntu 18). I'd just real quick mark that down on your readme. Cool project tho, giving it a whirl.

Randomly Losing the Server Stream

Running on Ubuntu 18 VM, vendor ffmpeg.

I am for whatever reason losing the server stream within 15 minutes of running. I'm not sure if it's because I'm using a VM but randomly I will lose the server stream, and the HLS stream will die. It also starts to hang on trying to play the next video when this happens.

I've been trying to investigate this issue for a day and I'm coming up with nothing. Without being able to see some sort of feedback from ffmpeg about why it's stopping (and the fact that I'm very new to ffmpeg), I'm having trouble finding a reason or a way to fix it. It also still awkwardly waits the duration before moving on to attempting to push the next file to the client.

screenshot1

Unrelated observation; Processes that are killed by the script when they timeout aren't cleaned up properly and result in zombie processes. They are eventually cleaned up when the script exits, so I'm not sure if this is a problem or not.

screenshot2

Remove pix_fmt

In my fork I've removed this config option and the passing of it to ffmpeg entirely to no substantial loss. ffmpeg automatically chooses one that works given other settings, so I find it a bit unnecessary. I'd like to see this tested in alpine since I run my fork on a full Ubuntu installation, in order to ensure container compatibility.

Video not passing through

I've got this setup on Ubuntu 18.

Verified that the vendor ffmpeg works with a bit of tweaking on the config, and I'm getting audio alright but for whatever reason the video doesn't come through.

I've tried tweaking the config to be closer to a ffmpeg CLI setup I've verified works with the same files to no avail.

Any idea?

This is what I've got my config tweaked to.

# Auto-Channel configuration file

MAX_CONSECUTIVE_RETRIES = 3 # TODO: If several consecutive files fail, exit program
MAX_SAME_FILE_RETRIES   = 5 # Number of times to attempt playing a file before giving up

PLAYOUT_FILE    = 'playout.ini'
OUTPUT_LOCATION = 'rtmp://localhost/live/stream'

SCHEDULER_UPNEXT_VIDEO_FOLDER = 'upnext/video'
SCHEDULER_UPNEXT_AUDIO_FOLDER = 'upnext/audio'
SCHEDULER_UPNEXT_WISDOM_FILE  = 'upnext/wisdom.txt'

SERV_DRAWTEXT_X             = 25
SERV_DRAWTEXT_Y             = 25
SERV_DRAWTEXT_SHADOW_X      = 2
SERV_DRAWTEXT_SHADOW_Y      = 2
SERV_DRAWTEXT_SHADOW_COLOR  = 'black'
SERV_DRAWTEXT_FONT_FILE     = 'fonts/hc-too5.ttf'
SERV_DRAWTEXT_FONT_SIZE     = 52
SERV_DRAWTEXT_FONT_COLOR    = 'white'
SERV_OUTPUT_ACODEC          = 'aac'

SERV_OUTPUT_ASPECT  = "640:480"
SERV_OUTPUT_CRF     = 28
SERV_OUTPUT_PRESET  = 'veryfast'

CLIENT_VIDEO_SCALE = '640x480'

CLIENT_DRAWTEXT_X = 25
CLIENT_DRAWTEXT_Y = 113
CLIENT_DRAWTEXT_SHADOW_X = 2
CLIENT_DRAWTEXT_SHADOW_Y = 2
CLIENT_DRAWTEXT_SHADOW_COLOR = 'black'
CLIENT_DRAWTEXT_FONT_FILE = 'fonts/hc-too5.ttf'
CLIENT_DRAWTEXT_FONT_SIZE = 32
CLIENT_DRAWTEXT_FONT_COLOR = 'white'

CLIENT_VCODEC                   = 'libx264'
CLIENT_ASPECT                   = '640:480'
CLIENT_FLAGS                    = '+cgop'
CLIENT_G                                = 12
CLIENT_ACODEC                   = 'aac'
CLIENT_STRICT                   = 1
CLIENT_AUDIO_BITRATE    = '168k'
CLIENT_AUDIO_RATE               = 44100
CLIENT_PRESET                   = 'veryfast'
CLIENT_HLS_ALLOW_CACHE  = 0
CLIENT_HLS_LIST_SIZE    = 5
CLIENT_HLS_TIME                 = 0.1
CLIENT_FORMAT                   = 'hls'
CLIENT_PIX_FMT                  = 'yuv420p'

CLIENT_FLEX             = 1

And this is the example command that I've verified works.

ffmpeg -hide_banner -re -i shows/bites_the_dust.mp4 /
-c:v libx264 -preset veryfast -maxrate 3000k -bufsize 6000k -pix_fmt yuv420p -g 50 /
-c:a aac -b:a 160k -ac 2 -ar 44100 -f flv rtmp://127.0.0.1/encoder/index

I have a feeling it's the text encoding, but I can't be sure.

Question: Do the blocks refresh?

I'm interested in being able to add/remove blocks in the config file without restarting the entire service. Is this supported?

Thanks!

Subtitle Support?

I am working on Subtitle Support on the unicorn branch of my fork, and was wondering if it was something you were interested in.

I have some working logic in my fork that can either select the subtitle track from an mkv, or does its best to select a subtitle file in the same dir with the same root name as the video file, and applies them to the stream.

I would like to work more on the logic for the latter (scanning for and selecting external files) before applying it to master, but here are a few examples below

img1

img2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.