I have been breaking my head for the pass 2 weeks, and I still can't figure it out. I'm trying to build a Server-Client based streaming player on Python (Ironpython for the wpf GUI) that streams video files. My problem is when the client requests to seek on a part that he did not load yet. When I try to send him just the middle of the .mp4 file, he cant seem to be able to play it.
Now I know such thing exists because every online player has it, and it uses the HTTP 206 Partial Content request, where the client just requests the byte range that he desires and the server sends it to him.
My question is - how is the client able to play the video with a gap in bytes in his .mp4 file - how can he start watching for the middle of the file? When i seem to try it the player just wont open the file.
And more importantly: how can I implement this on my Server-Client program to enable free seeking?
I really tried to look for a simple explanation for this all over the internet... Please explain it thoroughly and in simple terms for a novice such as me, I would highly appreciate it.
Thanks in advance.
Before playing an MP4 file the client (e.g. browser) needs to read the header part of the file. An MP4 is broken into 'Atoms' and the Moov atom is the header or index atom for the file.
For MP4 files that will be streamed, a common optimisation is to move this Moov atom to the front of the file.
This allows the client to get the moov at the start and it will then have the information it needs to allow you jump to the offset you want in your case.
If you don't have the moov atom at the start the client needs to either download the whole file, or if it is a bit more sophisticated, jump around the file with range requests until it finds it.