Continuous streaming from an empty pipe, then adding data to the pipe on demand

5,046

The way I got around this was using my own RTMP server to stream the video to the host.

I pipe my video to the local RTMP server using

mkfifo x
ytdl http://youtube.com/watch?v=12345 > x
ffmpeg -re -i x -c copy -f flv rtmp://mylocalRTMPserver/stream

Then create a stream from that to the host using

ffmpeg -re -i rtmp://mylocalRTMPserver/stream -c copy -f flv rtmp://mystream.com/key

If the above stream receives no input it stays open for around 30 seconds, allowing me to close the youtube pipe and open it again.

Whilst this works, there's extra overhead of having to run two instances of ffmpeg.

Share:
5,046

Related videos on Youtube

Ben Fortune
Author by

Ben Fortune

I identify as null.

Updated on September 18, 2022

Comments

  • Ben Fortune
    Ben Fortune over 1 year

    Essentially, what I'd like to do is to have ffmpeg continuously stream to an RTMP server using an empty pipe, then when I want to stream something, add data to the pipe.

    My reasons for doing this are, I'm piping videos from an external source. Whenever the video has finished, ffmpeg crashes because it's receiving no data and I have to open it again.

    Is this possible? If not, is there another way around this?

    My current command is:

    ffmpeg -i pipe:0 -re -c copy -f flv rtmp://mystream.com/key
    

    pipe:0 is an instance of ytdl.

    • harrymc
      harrymc about 9 years
      Which operating system? Does the source close the pipe when the video has finished or can it be set to continuous operation?
    • Ben Fortune
      Ben Fortune about 9 years
      @harrymc Ubuntu 14.10. The source closes the pipe when it's finished.
    • Blacklight Shining
      Blacklight Shining about 9 years
      Would it be possible to use ffserver for this?
    • Ben Fortune
      Ben Fortune about 9 years
      @BlacklightShining Probably, since it can act as an RTMP server. It just made more sense to use nginx since I already use it.
  • Elisa Cha Cha
    Elisa Cha Cha about 9 years
    -re should not be used with live input streams.
  • Ben Fortune
    Ben Fortune about 9 years
    @LordNeckbeard Why not? Seemed to work fine with my streams.
  • Elisa Cha Cha
    Elisa Cha Cha about 9 years
    The documentation states that it could cause packet loss.
  • pileofrocks
    pileofrocks over 6 years
    Documentation says: "Should not be used with actual grab devices or live input streams (where it can cause packet loss)", but at least if the input is an existing HLS stream and you don't use -re Youtube will say "Bad - Video output low" (on Youtube's live control room page) and stream won't even start or will be unwatchable.
  • Jonathan
    Jonathan almost 4 years
    @BenFortune couldn't it be done with cat and pipe argument of ffmpeg? I am also struggling with this and creating a rtmp server just to proxy it is not a good option for now
  • Jonathan
    Jonathan almost 4 years
    @BenFortune I was able to achieve this using pipe of ffmpeg and writing to stdin