开发者

Is it possible to have nginx stream a file for download that is currently being written to?

开发者 https://www.devze.com 2023-03-25 10:05 出处:网络
So I have 2 services running, one transcodes a file in realtime (ffmpeg), and another exposes it through http (nginx). The problem I currently have is that when ffmpeg begins transcoding, and I access

So I have 2 services running, one transcodes a file in realtime (ffmpeg), and another exposes it through http (nginx). The problem I currently have is that when ffmpeg begins transcoding, and I access the file throu开发者_Go百科gh nginx, only a portion of the written bytes are downloaded.

Question, is it possible to config nginx in such a way as to stream the file currently being written to until writing finishes and I now have the complete file on my local computer?

Thank you


I don't believe Nginx by itself can do this. You would need an application (php, perl, python, whatever) that can monitor the transcoding progress and serve the request with chunked transfer encoding Essentially it would keeping the connection open to the client and deliver more data as it becomes available.


I had a very similar issue. I don't know how to begin streaming while ffmpeg is still transcoding the file, but here was my fix:

I had a php script that made the system calls (though you could write this in pretty much any language). The script had ffmpeg write to a temporary file. Before calling ffmpeg, it checked whether the temporary file existed to eliminate concurrency issues. If so, it waited until the real file existed.

Once the file was done converting, it renamed the temporary file to the real file and redirected the http request to the transcoded file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号