Reputation: 5773
Using FFmpeg I converted a video (mpeg2) into jpgs, redirecting the output into the standard output.
StringBuilder str = new StringBuilder();
//Input file path
str.Append(string.Format(" -i {0}", myinputFile));
//Set the frame rate
str.Append(string.Format(" -r {0}", myframeRate);
//Indicate the output format
str.Append(" -f image2pipe");
//Connect the output to the standard output
str.Append(" pipe:1");
return str.ToString();
I'm able to receive the callback from the process with the data:
_ffmpegProc.OutputDataReceived += new DataReceivedEventHandler(_ffmpegProc_OutputDataReceived);
But how can I save that back into jpg files?, I'd need to know the size of each jpg, but I cant figure out how.
Thanks.
Upvotes: 1
Views: 1647
Reputation: 32953
You can't without reading and at least partially understanding the stream structure because JPEG files don't contain e.g. an explicit length indication somewhere at file start.
I see two possibilities that don't involve transcoding:
SOI
marker (hex FF D8) and ends with an EOI
marker (hex FF D9). With a relatively simple state machine you could try splitting the stream of JPG's into separate frames this way. Now, for robustness sake it's probably better to read the segments individually (see the JPEG file format for more info). You can also study the ffmpeg mjpeg decoder's source implementation, it looks quite robust.Upvotes: 3