0

I'm working with ffmpeg to process an incoming MPEGTS stream from remote cameras, and deliver it to multiple clients using my app.

Technically, I'm using ffmpeg to convert the incoming stream to an MJPEG output, and piping the data chunks (from the ffmpeg process stdout) to a writeable stream on the client http response.

However, I'm facing a problem- not all data chunks represent a full 'whole' frame. thus, displaying them in a row in the browser, results in a flickering video, with half-complete frames, on a random basis. I know this because when printing each chunk length, results most of the time in a big value (X), but every now and then I get 2 consecutive chunks with length (2/5X) followed by (3/5X) for example.

So the question - is there a way to force the ffmpeg process to output only whole frames? if not, is there a way for me to check each data chunk 'manually' and look for headers/metadata/flags to indicate frame start/end?


my ffmpeg command for outputting MJPEG is:

ffmpeg -i - -c:v mjpeg -f mjpeg -

explained:

"-i -" : (input) is the stdin of the process (and not a static file)

"-c:v mjpeg" : using the mjpeg codec

"-f mjpeg" : output will be in the mjpeg format

"-" : output not specified (file or url) - will be the process stdout

4
  • Motion JPEG consists exclusively of full frames. Sending the data in chunks should also not cause a problem. That leaves only the receiving logic as the culprit. It simply must wait for the frame to be complete before showing it.
    – Daniel B
    Dec 24, 2019 at 14:50
  • and how can I achieve this on the receiving end? for each chunk of data received, how do I know to wait for the next one and add them together to show a full frame? does mjpeg contain any headers or metadata I can read to get a hint to that? Dec 24, 2019 at 14:55
  • Every frame is a JPEG image. Refer to this answer for a method to check for completeness.
    – Daniel B
    Dec 24, 2019 at 15:23
  • following your suggestions, here is what I implemented: stackoverflow.com/questions/59468403/… Dec 25, 2019 at 14:29

0

You must log in to answer this question.

Browse other questions tagged .