我可以使用 ffmpeg 将 JPEG 输出到内存流而不是文件吗? [英] Can I use ffmpeg to output JPEGs to a memory stream instead of a file?

查看:24
本文介绍了我可以使用 ffmpeg 将 JPEG 输出到内存流而不是文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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.

如果我不能将视频文件写入光盘而是将其写入内存流(或字节数组)并通过网络服务上传,那会更整洁"吗?

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:

  1. 设置 StartupInfo.RedirectStandardOutput = trueStartupInfo.UseShellExecute = false.
  2. 使用 pipe: 调用 ffmpeg,而不是输出文件名,这将使其写入标准输出.此外,由于无法再根据文件名确定格式,请确保您也使用 -f 开关.
  3. 开始这个过程.
  4. Process.StandardOutput.BaseStream 读取(.BaseStream,所以 .StandardOutputStreamReader 不会不要搞砸任何事情),而进程正在运行到您的内存流中.
  5. 读取 Process.StandardOutput.BaseStream 中仍处于缓冲状态的任何内容.
  6. 利润.
  1. Set StartupInfo.RedirectStandardOutput = true and StartupInfo.UseShellExecute = false.
  2. 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.
  3. Start the process.
  4. Read from Process.StandardOutput.BaseStream (.BaseStream, so the StreamReader that is .StandardOutput doesn't mess anything up) while the process is running into your memory stream.
  5. Read anything still remaining buffered in Process.StandardOutput.BaseStream.
  6. Profit.

我编写了一个 while althumbnail back2-clause),它有实际的代码来证明这一点.不管最后是从ffmpeg出来的图片还是视频.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆