I am writing a transmuxer to turn MPEG-TS files from an HLS stream into MP4 files, which can then be played in a web browser.
I had expected to be able to just do a simple one-to-one mapping of TS files to MP4 files, but it turns out that some HLS streams are divided up such that the individual TS files do not always start on IDR frames; this results in frozen images and stuttering whenever you cross a segment boundary.
I figure I can fix this by concatenating the data from multiple TS files, ignoring the original file boundaries, identifying the IDR frames in the video stream myself, and starting each new MP4 segment on an IDR frame. If I do this, however, I'm worried about possible corruption at the ends of files; IDR frames guarantee that no later frame can reference any earlier data, but nothing indicates that earlier B frames can't look forward past an IDR frame.
So, how do I know where it is safe to make the cut, such that B frames before the cut won't try to look past it?