我可以使用ffmpeg将JPEG输出到内存流而不是文件中吗? [英] Can I use ffmpeg to output JPEGs to a memory stream instead of a file?
问题描述
我有一个C#应用程序。我有100个JPEG(例如)。
I have a C# app. I have 100 JPEGs (for an example).
我可以轻松地将其编码为视频文件。
I can easily encode this into a video file.
在客户端应用程序上完成编码后,我将FTP上传到我的服务器上。
When it has finished encoding on the client app I FTP upload to my server.
如果我无法将视频文件写入光盘,而是整洁将其写入内存流(或字节数组)并通过Web服务上传?
It would be 'neater' if I could not write the video file to a disc but instead write it to a memory stream (or array of bytes) and upload via web service perhaps?
我已经检查了ffmpeg文档,但作为C#开发人员,我找不到理解C示例很自然。
I have checked out the ffmpeg documentation but as a C# developer I do not find it natural to understand the C examples.
我想我的第一个问题是可能的,如果可以的话,有人可以在C#中发布示例代码吗?目前,我正在C#中使用流程类来执行ffmpeg。
I guess my first question is it possible, and if so can anyone post an example code in C#? At the moment I am using the process class in C# to execute ffmpeg.
推荐答案
您的流程方法已经不错,只需要进行调整:
Your process method is already good, just needs adjustments:
- 设置
StartupInfo.RedirectStandardOutput = true
和StartupInfo .UseShellExecute = false
。 - 而不是输出文件名,请使用
pipe:
调用ffmpeg。将其写入标准输出。另外,由于无法再通过文件名确定格式,因此请确保还使用-f< format>
开关。 - 开始该过程。
- 从
Process.StandardOutput.BaseStream
(.BaseStream
,因此StreamReader
即.StandardOutput
不会混乱 - 读取仍在
Process.StandardOutput.BaseStream
中保留的任何内容。 - / li>
- 利润。
- Set
StartupInfo.RedirectStandardOutput = true
andStartupInfo.UseShellExecute = false
. - Instead of an output file name, call ffmpeg with
pipe:
, which will make it write to the standard output. Also, since the format cannot be determined from the file name anymore, make sure you use the-f <format>
switch as well. - Start the process.
- Read from
Process.StandardOutput.BaseStream
(.BaseStream
, so theStreamReader
that is.StandardOutput
doesn't mess anything up) while the process is running into your memory stream. - Read anything still remaining buffered in
Process.StandardOutput.BaseStream
. - Profit.
I coded a thumbnailer a while back (BSD 2-clause), that has actual code that demonstrates this. Doesn't matter if it is an image or a video coming out of ffmpeg in the end.
这篇关于我可以使用ffmpeg将JPEG输出到内存流而不是文件中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!