Reputation: 1
I get an exception when trying to write a raw image to ConvertLiveMedia
:
System.IO.IOException: "Канал был закрыт.
System.IO.IOException: "The channel has been closed."
var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
var frame = Bitmap.FromFile("source.jpg");
var bytes = ImageToByte(frame);
using (var fs = new FileStream("output.mp4", FileMode.Create))
{
var mediaTask = ffMpeg.ConvertLiveMedia(Format.raw_video, fs, Format.mp4, new ConvertSettings()
{
});
mediaTask.Start();
for (int f = 0; f < frames; f++)
{
mediaTask.Write(bytes, 0, bytes.Length); //exception here channel was closed
}
mediaTask.Stop();
}
Upvotes: 0
Views: 1337
Reputation: 9235
System.IO.IOException: "The channel has been closed."
This exception appears because ConvertLiveMedia redirects stdin/stdout but ffmpeg process was suddenly stopped, most likely because of incorrect options or input data.
In your case, the reason is "mp4": this output format cannot be used with live streams, ffmpeg can write it only to local file. You can use this ConvertMedia overload for this purpose (if you provide input with "Write" method you can pass null
for inputStream
argument.
Upvotes: 1