1

I am using Live555/openRTSP based code to stream an H.264 video source to an mp4 file, and would like to concurrently read the earlier parts of the file (from a different application). Changing the fopen to be fid = _fsopen(fileName, "wb", _SH_DENYWR) (from OutputFile.cpp) clearly isn't enough, because it makes no difference and the media players still won't open it (is that the write line for the mp4 output?)

On a related note if I simulate an unclean shutdown of the software (e.g. power failure) the unfinished files are not readable by any media players. I assume that what is written to the file on file-close is what allows a media player to understand the file. This is also a situation I'd like to code for, if possible, and is quite likely the really the same problem as above?

Any pointers/answers/thoughts greatly received :-)

Abhineet
  • 5,320
  • 1
  • 25
  • 43
noelicus
  • 14,468
  • 3
  • 92
  • 111

2 Answers2

0

You normally don't read from MP4 (the same is valid for many other formats) files using fopen-like API, and you use libraries instead. Which, in turn, expect a completed file and don't attempt to recover a broken file, or read the file still being written.

So while technically it is possible to read while it is still being written, you are unlikely to succeed in this with regular libraries, applications and players. You need to complete write first to make the file valid, readable and playable - because the completion step writes indices required for playback.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
0

In case anybody ever needs the same, this is how I did it, and it was easier than I imagined:

  • Change fopen in OutputFile.cpp to the file-sharing call _fsopen (share read access)
  • Every 10 seconds in the QuickTimeFileSink::continuePlaying() function I call completeOutputFile(), thus keeping the header up to date (with video length, etc).

Windows Media Player didn't like it (probably tried to get exclusive file access), but VLC was quite happy to read the file whilst I was still streaming into it.

noelicus
  • 14,468
  • 3
  • 92
  • 111