简体   繁体   English

使用C#将接收到的MJPEG数据保存到.mjpeg文件中

[英]Save the received MJPEG data in a .mjpeg file with C#

I have a project. 我有一个项目。 It is with Raspberry Pi Camera V2. 它与Raspberry Pi Camera V2一起提供。 One PC is used for encoding the captured video in MJPEG format and sending it with the serial port. 一台PC用于将捕获的视频编码为MJPEG格式,并通过串行端口发送。 My PC is used for receiving the data, saving it in a .mjpeg formatted file and playing it with an MJPEG to MP4 converter. 我的PC用于接收数据,将其保存为.mjpeg格式的文件,然后使用MJPEG到MP4转换器播放。 I am trying to save the data in these lines: 我正在尝试在以下行中保存数据:

byte[] data= new byte[100];
serialPort.Read(data,0,100);
BinaryWriter videoFile = new BinaryWriter(File.Open("video.mjpeg",FileMode.Create));

string dataAscii;
dataAscii = System.Text.Encoding.UTF8.GetString(data); //bytearray to string

videoFile.Write(dataAscii); // which is received

It works, it creates a .mjpeg file. 它可以正常工作,它会创建一个.mjpeg文件。 However, I couldn't make it play with the converter. 但是,我无法使其与转换器配合使用。 Maybe I should save the data frame by frame or try to save in a different way. 也许我应该逐帧保存数据,或者尝试以其他方式保存。 I have no idea about what I am doing wrong. 我不知道我在做什么错。

Any ideas, many thanks! 任何想法,非常感谢!

Kane 凯恩

Why are you converting the byte array into a string before writing it? 为什么在写入字节数组之前将其转换为字符串? That's your problem. 那是你的问题。 Just write the byte array directly to the file stream. 只需将字节数组直接写入文件流即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM