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

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

问题描述

我有一个c#应用程序。我有100个jpegs(例如)。



我可以轻松地将其编码成视频文件。



当客户端应用程序完成编码时,我将FTP上传到我的服务器。



如果我无法将视频文件写入光盘,那将是更整洁的将其写入内存流(或字节数组),也可以通过网络服务上传?



我已经签出了ffmpeg文档,但是作为ac#开发人员,我找不到很自然地理解c示例。



我猜我的第一个问题是可能的,如果可以的话,任何人都可以在c#中发布示例代码?目前我正在使用c#中的进程类来执行ffmpeg。



我当然会发布这段代码,如果它有帮助?



感谢大家的时间。

解决方案

您的流程方法已经很好,只需要调整:设置 StartupInfo.RedirectStandardOutput = true StartupInfo.UseShellExecute =

  • 代替输出文件名称,使用 pipe调用ffmpeg:,这将使它写入标准输出。另外,由于不能从文件名中确定格式,请确保使用 -f< format> 开关。

  • 开始进程。

  • Read.StandardOutput.BaseStream中读取 .BaseStream ,所以 StreamReader .StandardOutput 不会乱任何东西),而进程正在运行到你的内存流中。

  • 读取任何仍然缓冲在$ code> Process.StandardOutput.BaseStream / li>
  • 利润

  • 我现在太懒/忙了,想出一个完整的不过,最小的例子,但是我编码了一个 thumbnailer a而返回(BSD 2-clause),它具有实际的代码来证明这一点。如果是最终的ffmpeg出现的图像或视频无关紧要。


    I have a c# app. I have 100 jpegs (for an example).

    I can easily encode this into a video file.

    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?

    I have checked out the ffmpeg documentation but as a c# developer I do not find it natural to understand the c examples.

    I guess my 1st question is it possible and if so can anyone post me an example code in c#? At the moment I am using the process class in c# to execute ffmpeg.

    I will of course post this code if it would help?

    Thanks for everyone's time.

    解决方案

    Your process method is already good, just needs adjustments:

    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.

    I'm too lazy/busy right now to come up with a full-blown, minimal example, but 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将jpegs输出到内存流而不是文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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