How do I use piping with ffmpeg?

48,422

Solution 1

I haven't tested this but should be like this or very close.

wget [URL] | ffmpeg -i pipe:0 -vcodec mpeg4 -s qcif -f m4v -y output.flv

Solution 2

A potentially better option to piping from a separate HTTP client is to use ffmpeg's built-in one. At least newer versions can take a URL as an input file argument. This way FFmpeg can pull the file down itself, and for formats that have container data near the end of the file, it can (if the server supports it) grab that portion of the file first, unlike piping from curl or wget, which fetch the file sequentially. See http://ffmpeg.org/ffmpeg-all.html#http

Solution 3

Part of the problem you're going to encounter is that some file formats have important file container information at the end of the file. Thus, piping a wget call directly to ffmpeg is a potential file breaker as ffmpeg may choke before the file is fully downloaded.

You're better off looking at a series of commands: wget'ing the file then running ffmpeg on it. It ignores the pipe capabilities, but that's the problem you get working with certain files.

Also, I would take a look at this FAQ answer from FFMPEG's site regarding one set of methods when piping videos using mkfifo and concatenating FLV's: http://www.ffmpeg.org/faq.html#TOC27

Solution 4

"ffmpeg can only do piping on raw video" <-- It isn't.

You can pipe in/out any format ffmpeg supports.

And in your command line example, you extract raw video from the FLV and encode to MP3. It can never be done like this.

Share:
48,422
DiglettPotato
Author by

DiglettPotato

nothin

Updated on August 05, 2022

Comments

  • DiglettPotato
    DiglettPotato almost 2 years

    My goal is to use wget to download an flv file, and pipe the output to ffmpeg to convert it to an MP3. This way the user can download the MP3 without waiting for the FLV to download to my server first. I've been playing around with it, and it seems that ffmpeg can only do piping on raw video. So I was working with something like this:

    wget -O - 'videoinput.flv' | ffmpeg -y -i - -vcodec rawvideo -f yuv4mpegpipe - |  ffmpeg -y -i - -ab 128k audiooutput.mp3
    

    Anybody have experience with this type of on-the-fly ffmpeg encoding process?

  • Andre Soares
    Andre Soares about 7 years
    Sometimes you just don't have the link, i.e. when downloading a video using youtub-dl.
  • user371366
    user371366 about 7 years
    huh, TIL that youtube-dl can dump the video to STDOUT
  • Andre Soares
    Andre Soares about 7 years
    Yes, using the option -o - it will output to stdout
  • Shevach Riabtsev
    Shevach Riabtsev over 4 years
    ' - | ' pipelining of output. ' -i pipe:0' pipelining of input. Example [first ffmpeg transcodes the input stream with adding padding, the output is elementary stream, the second ffmpeg gets elementary stream and encapsulates it into mp4-container]: ffmpeg -i test.h264 -vcodec libx264 -vf pad="width=iw+16:height=ih+16:color=white" -f h264 -y -an - | ffmpeg -i pipe:0 -vcodec copy -y test.mp4