0

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.

VC.One
  • 14,790
  • 4
  • 25
  • 57
J R
  • 227
  • 3
  • 8
  • Without external libraries this requires a lot of knowledge about video encoding and a lot of work to implement it. – Michael Butscher Jun 11 '23 at 20:24
  • @MichaelButscher I see, thank you for the warning. If I do have to use other libraries, what can I use so that I don't have to modify the way I am calling 'rec_stream.write(data)'? I'm asking this because, for example, in OpenCV examples I saw that it's required to call functions to write stream frame-by-frame, but video streaming library I am using output that 'data' as a single variable. – J R Jun 11 '23 at 20:29

0 Answers0