I am writing a Python application in which I want to record an MP4 video from a Raspberry Pi camera. I created a variable rec_stream
of type BufferedWriter and initialized video file creation:
rec_stream = open(f"rec.mp4", 'wb')
Later, another function is calling this line to write data to that video file:
rec_stream.write(data)
And finally, when the recording is done, this is called to close it:
rec_stream.close()
However, even though the video file is created, and runs, there is something wrong with it, because no media player application can see the length of that video, nor allows me to utilize the time bar to view specific moments in that video (no seeking). I think that BufferedWriter
doesn't fully close that file, or maybe fails to write some required metadata (headers or something).
Can anyone advise what I need to change here to format the resulting file as a true video file, with all the required metadata so it can be run without the issues I mentioned? I want to do this with BufferedWriter rather than OpenCV or other libraries.