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