Can I use ffmpeg to output JPEGs to a memory stream instead of a file?

前端 未结 1 1550
耶瑟儿~
耶瑟儿~ 2020-12-10 18:28

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

1条回答
  •  独厮守ぢ
    2020-12-10 18:57

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

    0 讨论(0)
提交回复
热议问题