简体   繁体   中英

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

I have a project. It is with Raspberry Pi Camera V2. One PC is used for encoding the captured video in MJPEG format and sending it with the serial port. My PC is used for receiving the data, saving it in a .mjpeg formatted file and playing it with an MJPEG to MP4 converter. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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