Search code examples
linuxffmpegrtsplive555

Add movflags to top of mp4 file without using ffmpeg for a live RTSP stream


Update: I have a video player in browser which plays mp4 videos though websocket. The player only supports mp4 file. When i checked normal mp4 fiels does not play in the player, a mp4 file with a "moovflags faststart " will only play on that player. For a allready stored file , this will work properly. But In case of an livestream(RTSP), using ffmpeg will only work once the RTSP connection has terminated since the "moovflags faststart " flags will work once a connection has terminated properly. Hope the above statements makes more sense. Due to this behavior, am checking if there is any way to get the moovflasg at first or something

I am having RTSP live source and i need it to convert the RTSP to a mp4 file which has moov flags in the begining of the file. I have checked with openrtsp to take a mp4 dump of the rtsp, but it only adds moov flags and other info on the footer of the mp4(onlky when openrtsp has closes the rtsp stream). Ffmpeg has " -movflags faststart" to move the footer info to the header of the mp4 container. Since i am having a RTSP live source, the video data will be comming back to back and there wont be any termination. The above ffmpeg command only works once the rtsp stream has terminated.

Is there any way we can make a mp4 container which contains the mp4 footer info present in the header itself so that i can use it for a live source?

EDIT #1 I have video player which plays mp4 video files , it only support playback of a recorded mp4 file which is createtd using "-movflags faststart" , normal mp4 files does not play in that. This is the player https://github.com/sonysuqin/WasmVideoPlayer. Since i am tryng to stream live video to the player, its not possible to use movflags faststart.


Solution

  • The mp4 header can not be added to the file before it is complete. It’s not possible because of how mp4 files are structured. The header needs to know the frame type, timestamp, size, and file offset of every frame in the file. That can’t be known until the file is complete. You can not stream an mp4 while it is being created. You need to use a protocol such as HLS or DASH to accomplish this.