Project

General

Profile

Best way to publish a tvheadend stream to Youtube

Added by Peter Wislander over 7 years ago

I know I can use ffmpeg, but that seems to take additional cpu power. Preferably, i'd like to somehow send the raw stream that tvheadend normally sends to ffmpeg directly to Youtube live stream url.

Unfortunately, I can not get youtube to make the request, otherwise it would have been perfect. I need tvheadend to publish it against youtube,.

This command did work but was cpu costly:

#!bin/bash

VBR="2500k" # Bitrate de la vidéo en sortie
FPS="30" # FPS de la vidéo en sortie
QUAL="medium" # Preset de qualité FFMPEG
YOUTUBE_URL="rtmp://a.rtmp.youtube.com/live2" # URL de base RTMP youtube

SOURCE="http://192.168.0.3:9981/play/stream/service/0a8db2014b55829d37dba43798eff7b5"
KEY="t0p5-CODE-9211-fz23"

ffmpeg \
-i "$SOURCE" -deinterlace \
-vcodec libx264 -pix_fmt yuv420p -preset $QUAL -r $FPS -g $(($FPS * 2)) -b:v $VBR \
-acodec libmp3lame -ar 44100 -threads 6 -qscale 3 -b:a 712000 -bufsize 512k \
-f flv "$YOUTUBE_URL/$KEY"


Replies (3)

RE: Best way to publish a tvheadend stream to Youtube - Added by Robert Cameron over 7 years ago

If all you want is the raw stream, then just pass that to ffmpeg, changing your container (format, -f option), but keeping the codecs the same (-c copy). Transcoding both audio and video, including deinterlacing is going to be CPU costly on any system unless you're using hw acceleration.

RE: Best way to publish a tvheadend stream to Youtube - Added by Peter Wislander over 7 years ago

Thanks Cameron,

Do you have an example command I could try? Not so familiar and there's risk I get it wrong.

RE: Best way to publish a tvheadend stream to Youtube - Added by Robert Cameron over 7 years ago

Peter Wislander wrote:

Thanks Cameron,

Do you have an example command I could try? Not so familiar and there's risk I get it wrong.

I suppose it depends upon what formats that YT will accept. Something like:

$ ffmpeg -i "${SOURCE}" -map 0 -c copy out.mkv

That will take your MPEG-TS, or whatever format you have TVH saving your files in, and simply repackage it in a Matroska container. (You don't want to use .mp4, as ffmpeg sticks to the standard and MP4 containers can only hold MPEG codecs, so you're basically stuck with H.264 and AAC if you go that route.) The "-map 0" option is only necessary if you care about additional streams (such as secondary audio tracks), because ffmpeg by default only selects the first stream of each type to pass through to output. If you want more than one stream of a type, you have to specify them with the '-map' option.

Another option to alleviate your high CPU usage is to use some form of hardware acceleration for the transcoding. If you have an nVidia card you can use nvenc, and Intel and AMD graphics can make use of VA-API, but there are drawbacks. The quality of hardware encoding is actually less than using x264, but it saves your CPU those precious cycles.

    (1-3/3)