Custom MPEG-TS Input » History » Version 28
Jaroslav Kysela, 2017-08-25 16:06
| 1 | 1 | Jaroslav Kysela | h1. Custom MPEG-TS Input |
|---|---|---|---|
| 2 | |||
| 3 | h2. Requirement |
||
| 4 | |||
| 5 | 2 | Jaroslav Kysela | The TVHeadend 3.9.2100 and up for the pipe:// URL support. Note that TVHeadend expects the input in the raw MPEG-TS format with correct PAT/PMT tables. |
| 6 | 1 | Jaroslav Kysela | |
| 7 | h2. IPTV URLs |
||
| 8 | |||
| 9 | 18 | Jaroslav Kysela | **Note: Always try the command without pipe:// prefix on standard command line, if it works with a stdout redirection to a file!!** |
| 10 | 5 | Jaroslav Kysela | |
| 11 | 11 | Jaroslav Kysela | h3. Streaming from a file |
| 12 | |||
| 13 | 15 | Jaroslav Kysela | Use option -re for the input specification to stream the file at native frame rate. |
| 14 | 11 | Jaroslav Kysela | |
| 15 | <pre> |
||
| 16 | -re (input) |
||
| 17 | |||
| 18 | Read input at native frame rate. Mainly used to simulate a grab |
||
| 19 | device. or live input stream (e.g. when reading from a file). |
||
| 20 | Should not be used with actual grab devices or live input streams |
||
| 21 | (where it can cause packet loss). By default ffmpeg attempts to |
||
| 22 | read the input(s) as fast as possible. This option will slow down |
||
| 23 | the reading of the input(s) to the native frame rate of the |
||
| 24 | input(s). It is useful for real-time output (e.g. live streaming). |
||
| 25 | </pre> |
||
| 26 | |||
| 27 | 10 | Nicolas C | h3. Internet Radios |
| 28 | 1 | Jaroslav Kysela | |
| 29 | 23 | dhead 666 | **Note: FFmpeg flag '-tune zerolatency' depends on the x264 encoder (libx264), remove the flag if x264 encoder isn't available on your system (e.g. OpenELEC).** |
| 30 | 22 | dhead 666 | |
| 31 | 21 | dhead 666 | From ffmpeg v2.6 and on one can set the service type of the mpegts stream as radio. |
| 32 | <pre> |
||
| 33 | pipe:///usr/bin/ffmpeg -loglevel fatal -i INPUTLINK -vn -acodec copy -metadata service_provider=RADIOPROVIDER |
||
| 34 | -metadata service_name=RADIONAME -tune zerolatency -f mpegts -mpegts_service_type digital_radio pipe:1 |
||
| 35 | </pre> |
||
| 36 | 1 | Jaroslav Kysela | |
| 37 | 21 | dhead 666 | With older ffmpeg releases the mpegts service type cannot be set correctly so the audio stream will be listed as a TV channel, you can use a static image that will be shown with the audio stream (the Radio Logo maybe?). |
| 38 | |||
| 39 | 11 | Jaroslav Kysela | <pre> |
| 40 | pipe:///usr/bin/ffmpeg -loglevel fatal -loop 1 -y -i /path/to/image.png -re -i INPUTLINK |
||
| 41 | 1 | Jaroslav Kysela | -vcodec libx264 -acodec copy -mbd rd -copyinkf -flags +ilme+ildct -fflags +genpts |
| 42 | 10 | Nicolas C | -metadata service_provider=RADIOPROVIDER -metadata service_name=RADIONAME -tune zerolatency -f mpegts pipe:1 |
| 43 | 20 | Jaroslav Kysela | </pre> |
| 44 | 19 | Jaroslav Kysela | |
| 45 | 25 | Jaroslav Kysela | h4. For H264/HEVC video, the mp4toannexb filter must be used for MP4 video streams |
| 46 | 24 | Jaroslav Kysela | |
| 47 | <pre> |
||
| 48 | 1 | Jaroslav Kysela | -bsf:v h264_mp4toannexb,dump_extra |
| 49 | 25 | Jaroslav Kysela | -bsf:v hevc_mp4toannexb,dump_extra |
| 50 | 1 | Jaroslav Kysela | |
| 51 | 28 | Jaroslav Kysela | pipe:///usr/bin/ffmpeg -loglevel fatal -user-agent Kodi/14.1 -i http://INPUTLINK -codec copy -bsf:v h264_mp4toannexb,dump_extra |
| 52 | 27 | Jaroslav Kysela | -metadata service_provider=PROVIDER -metadata service_name=SERVICE -tune zerolatency -f mpegts pipe:1 |
| 53 | 26 | Jaroslav Kysela | </pre> |
| 54 | 24 | Jaroslav Kysela | |
| 55 | 11 | Jaroslav Kysela | h3. Transcoding |
| 56 | 10 | Nicolas C | |
| 57 | 1 | Jaroslav Kysela | YMMV with different ffmpeg/libav versions. In Red Hat's (Fedora/Centos) build of ffmpeg, aac transcoding is experimental, so you have to enable -strict -2 |
| 58 | |||
| 59 | 10 | Nicolas C | <pre> |
| 60 | 13 | Jaroslav Kysela | pipe:///usr/bin/ffmpeg -loglevel fatal -i INPUTLINK -vcodec libx264 -acodec aac -strict -2 -mbd rd -copyinkf -flags +ilme+ildct -fflags +genpts |
| 61 | 11 | Jaroslav Kysela | -metadata service_provider=STRING -metadata service_name=STRING -f mpegts -tune zerolatency pipe:1 |
| 62 | 10 | Nicolas C | </pre> |
| 63 | |||
| 64 | Try to transcode as little as possible, since it will impact your cpu usage. And if you're using tvheadend to re-transcode... well.. |
||
| 65 | |||
| 66 | So if your channel already has aac audio, maybe you only need to transcode the video stream. |
||
| 67 | |||
| 68 | <pre> |
||
| 69 | 13 | Jaroslav Kysela | pipe:///usr/bin/ffmpeg -loglevel fatal -i INPUTLINK -vcodec libx264 -acodec copy -mbd rd -copyinkf -flags +ilme+ildct -fflags +genpts |
| 70 | 6 | Jaroslav Kysela | -metadata service_provider=STRING -metadata service_name=STRING -f mpegts -tune zerolatency pipe:1 |
| 71 | 7 | Jaroslav Kysela | </pre> |
| 72 | 6 | Jaroslav Kysela | |
| 73 | 14 | Jaroslav Kysela | h3. Direct copy (container only change) |
| 74 | 8 | Jaroslav Kysela | |
| 75 | 6 | Jaroslav Kysela | <pre> |
| 76 | 1 | Jaroslav Kysela | pipe:///usr/bin/ffmpeg -loglevel fatal -i INPUTLINK -vcodec copy -acodec copy -metadata service_provider=STRING |
| 77 | -metadata service_name=STRING -f mpegts -tune zerolatency pipe:1 |
||
| 78 | </pre> |
||
| 79 | |||
| 80 | 16 | Nicolas C | h3. Cookie-protected HLS Streams |
| 81 | ffmpeg is not the smartest cookie in the jar handling cookies (pun intended). So while you can insert cookies using the -cookie option, and alternative option is using Squid with request_add_header option |
||
| 82 | |||
| 83 | <pre> |
||
| 84 | request_header_add Cookie 'YOUR COOKIE CONTENT' all |
||
| 85 | </pre> |
||
| 86 | |||
| 87 | The trailing all refers to the ACL it applies to. Please read the full documentation on how to implement this on the Squid Website (http://www.squid-cache.org/Doc/config/request_header_add/) |
||
| 88 | 17 | Nicolas C | |
| 89 | 1 | Jaroslav Kysela | h2. Other solutions (HTTP proxy) |
| 90 | |||
| 91 | 10 | Nicolas C | |
| 92 | 11 | Jaroslav Kysela | "A simple ffmpeg HTTP proxy using nodejs":https://github.com/Jalle19/node-ffmpeg-mpegts-proxy |