Project

General

Profile

ffmpeg/avconv pipes

Added by Anthony Thomas almost 8 years ago

I've had success in the past making an avconv pipe for mapping the video from one channel with the audio from another

example:

pipe:///usr/bin/avconv -loglevel fatal -i http://192.168.1.65:9981/stream/channelnumber/1 -i http://192.168.1.65:9981/stream/channelnumber/2 -c copy -map 0:a:0 -map 1:v:0 -metadata service_provider=AT -metadata service_name=AVMAP12 -f mpegts -tune zerolatency pipe:1

I'm trying to create a picture-in-picture avconv pipe. I've got it working at the command line to essentially record to file - example

ffmpeg -i http://192.168.1.65:9981/stream/channelnumber/1 -i http://192.168.1.65:9981/stream/channelnumber/2 -filter_complex "[1]scale=iw/2.5:ih/2.5 [pip]; [0][pip] overlay=main_w-overlay_w-1:main_h-overlay_h-1" -ar 48000 -vcodec mpeg2video -vb 5000000 -acodec mp2 piptest`date +%s`.mpg

When I try what I believe should be a working pipe for TVH it doesn't work, any ideas?

pipe:///usr/bin/avconv -loglevel fatal -i http://192.168.1.65:9981/stream/channelnumber/1 -i http://192.168.1.65:9981/stream/channelnumber/2 -filter_complex "[1]scale=iw/2.5:ih/2.5 [pip]; [0][pip] overlay=main_w-overlay_w-1:main_h-overlay_h-1" -ar 48000 -vcodec mpeg2video -vb 5000000 -acodec mp2 -metadata service_provider=AT -metadata service_name=AVMAP12pip -f mpegts -tune zerolatency pipe:1


Replies (10)

RE: ffmpeg/avconv pipes - Added by Anthony Thomas almost 8 years ago

Does TVH struggle with filter_complex in pipes?

Nov 26 09:07:19 serverk tvheadend[31101]: spawn: [AVFilterGraph @ 0x1c429c0] No such filter: '"'
Nov 26 09:07:19 serverk tvheadend[31101]: spawn: Error configuring filters.

I don't need to escape the double quote or something do I?

RE: ffmpeg/avconv pipes - Added by Anthony Thomas almost 8 years ago

Temporary workaround

Use ffmpeg to stream to udp and use kodi to watch udp stream.

Also done some mapping of the audio streams so I can switch audio.

/usr/bin/avconv -i http://192.168.1.65:9981/stream/channelnumber/421 -i http://192.168.1.65:9981/stream/channelnumber/416 -filter_complex "[1]scale=iw/2.5:ih/2.5 [pip]; [0][pip] overlay=main_w-overlay_w-0:main_h-overlay_h-0" -vf yadif -vcodec mpeg2video -r 25 -vb 8000000 -map 0:2 -map 1:2 -acodec copy -metadata service_provider=AT -metadata service_name=pip -f mpegts -tune zerolatency udp://192.168.1.18:9000

RE: ffmpeg/avconv pipes - Added by Dimitar Maznekov over 7 years ago

Did you find way to implement filter_complex in TVH mux ?
UDP stream works but it's not on demand and its one more service working on.

RE: ffmpeg/avconv pipes - Added by Anthony Thomas over 7 years ago

Unfortunately not.

The PIP was only something I want very occasionally so I just use the command line UDP version when I want some PIP.

RE: ffmpeg/avconv pipes - Added by Dimitar Maznekov over 7 years ago

What about pipe:///path/script.sh and in script that problem ffmpeg filter_complex ?
I've checked out but TVH returns me:

iptv: stdin pipe unexpectedly closed: No data

RE: ffmpeg/avconv pipes - Added by Robert Cameron over 7 years ago

I've noticed that Tvheadend has problems passing arguments to pre-/post-processing, as well as pipes. To make it easier, I always wrap them in shell scripts. It also makes it easier to string multiple commands to create complex strings, such as multiple UDP inputs.

RE: ffmpeg/avconv pipes - Added by Dimitar Maznekov over 7 years ago

Anthony Thomas wrote:

Temporary workaround

Use ffmpeg to stream to udp and use kodi to watch udp stream.

Also done some mapping of the audio streams so I can switch audio.

/usr/bin/avconv -i http://192.168.1.65:9981/stream/channelnumber/421 -i http://192.168.1.65:9981/stream/channelnumber/416 -filter_complex "[1]scale=iw/2.5:ih/2.5 [pip]; [0][pip] overlay=main_w-overlay_w-0:main_h-overlay_h-0" -vf yadif -vcodec mpeg2video -r 25 -vb 8000000 -map 0:2 -map 1:2 -acodec copy -metadata service_provider=AT -metadata service_name=pip -f mpegts -tune zerolatency udp://192.168.1.18:9000

I've made same with diff options but it's interesting - what do you mean by "switch audio".
That's my implement:

/usr/bin/ffmpeg -hide_banner -loglevel panic -thread_queue_size 512 -i http://127.0.0.1:9981/stream/channelnumber/103 -thread_queue_size 512 -i http://127.0.0.1:9981/stream/channelnumber/102 -filter_complex "[1]scale=iw/3:ih/3 [pip]; [0][pip] overlay=main_w-overlay_w-10:main_h-overlay_h-10[v]" -map "[v]" -map 0:1 -map 1:1 -metadata:s:a:0 language=bul -metadata:s:a:0 title="BTV" -metadata:s:a:1 language=eng -metadata:s:a:1 title="NOVA" -strict -2 -ac 2 -ar 44100 -vcodec libx264 -acodec aac -metadata service_provider=PiP -metadata service_name=BTV+NOVA -f mpegts udp://127.0.0.1:9000

Now I can see in VLC two audio tracks and switch it.
But can't in Kodi (tvh pvr client) ?

RE: ffmpeg/avconv pipes - Added by Ryan Gong over 7 years ago

Hey guys, i'm new here. Based on you guys's post, i have been looking to do this picture to picture without a udp server, so I used point to point. here is how I make it work:

on the sender side, i would have this command ready to go: (don't start until receiver starts)

/usr/local/ffmpeg/bin/ffmpeg -loglevel fatal -re -i input_1 -re -i link_2 -filter_complex "[1]scale=iw/3:ih/3 [pip]; [0][pip] overlay=main_w-overlay_w-10:main_h-overlay_h-10[v]" -map "[v]" -map 0:1 -map 1:1 -metadata:s:a:0 language=bul -metadata:s:a:0 title="BTV" -metadata:s:a:1 language=eng -metadata:s:a:1 title="NOVA" -strict -2 -ac 2 -ar 44100 -vcodec libx264 -preset ultrafast -acodec aac -metadata service_provider=PiP -metadata service_name=BTV+NOVA -f mpegts tcp://receiver_IP:receiver_Port

on the receiver side, in my case it's tvh's mux, use command list this, this will have both audio track to select:

pipe:///usr/local/ffmpeg/bin/ffmpeg -i tcp://receiver_IP:receiver_Port?listen -map 0:0 -map 0:1 -map 0:2 -c:v copy -c:a:0 copy -c:a:1 copy -f mpegts pipe:1

receiver_IP is simply tvh's local ip address.

now play this mux, wait a few second, then start the sender command. you'll be able to find service and create channel from there.

Once you have the channel, always start playing channel first, wait a few second, then start the sender command (otherwise, the command will quit itself because there's no receiver found I guess).

i don't know how to do it using udp.

hope this helps.

RE: ffmpeg/avconv pipes - Added by Dimitar Maznekov over 7 years ago

It's much better to use UDP stream because of stateless type of protocol. TCP is 3way handshake protocol and due to that is initial delay.
The main question at that moment is way can't use simple pipe as

/usr/bin/ffmpeg -thread_queue_size 512 -i http://127.0.0.1:9981/stream/channelnumber/103 -thread_queue_size 512 -i http://127.0.0.1:9981/stream/channelnumber/102 -filter_complex "[1]scale=iw/3:ih/3 [pip]; [0][pip] overlay=main_w-overlay_w-10:main_h-overlay_h-10[v]" -map "[v]" -map 0:1 -map 1:1 -metadata:s:a:0 language=bul -metadata:s:a:0 title="BTV" -metadata:s:a:1 language=eng -metadata:s:a:1 title="NOVA" -strict -2 -ac 2 -ar 44100 -vcodec libx264 -acodec aac -metadata service_provider=PiP -metadata service_name=BTV+NOVA -f mpegts -tune zerolatency pipe:1

the problem is -f mpegts -tune zerolatency pipe:1 at the end and that one-liner ONLY to be placed as service instead of one for UDP stream and second for pipe:/// in service.

Someone could advice why doesn't start ?

RE: ffmpeg/avconv pipes - Added by Dimitar Maznekov over 6 years ago

In matter of fact, resolution:

1. Create script:
cat>/home/hts/.hts/tvheadend/scripts/pip<<EOF

#!/bin/bash
ffmpeg -loglevel fatal -thread_queue_size 512 -i http://127.0.0.1:9981/stream/channelnumber/$1 -thread_queue_size 512 -i http://127.0.0.1:9981/stream/channelnumber/$2 -filter_complex "[1]scale=iw/3:ih/3 [pip]; [0][pip] overlay=main_w-overlay_w-10:main_h-overlay_h-10[v]" -map "[v]" -map 0:1 -map 1:1 -metadata:s:a:0 language=bul -metadata:s:a:1 language=eng -strict -2 -ac 2 -ar 44100 -vcodec libx264 -acodec aac -metadata service_provider=PiP -metadata service_name=PiP -tune zerolatency -f mpegts pipe:1
EOF

2. Create MUX:
pipe:///home/hts/.hts/tvheadend/scripts/pip 101 109
where 101 and 109 are channelnumbers
Warning: Mark Respawn(Pipe) option !

3. Map new MUX as service (you could create type based tag)

4. Optional, you could assign key L on remote to switch "languages" respectively sound from two channels:

<!-- PVR windows -->
<e>ActivateWindow(TVGuide)</e>
<h>ActivateWindow(TVChannels)</h>
<j>ActivateWindow(RadioChannels)</j>
<k>ActivateWindow(TVRecordings)</k>
<b>ActivateWindow(TVTimers)</b>
<l>AudioNextLanguage</l>

    (1-10/10)