How do I use piping with ffmpeg?

2019-02-11 22:45发布

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?

标签: ffmpeg
4条回答
何必那么认真
2楼-- · 2019-02-11 23:00

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

查看更多
啃猪蹄的小仙女
3楼-- · 2019-02-11 23:01

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
查看更多
仙女界的扛把子
4楼-- · 2019-02-11 23:05

"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.

查看更多
ら.Afraid
5楼-- · 2019-02-11 23:07

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

查看更多
登录 后发表回答