I’m working on a problem where I need to encode a video and send it to a web server.
I’m using VideoIO.jl to encode the video, as shown here:
The link above shows two ways to encode the video: i) single-step encoding and ii) iterative encoding. In both cases, the examples show how to write the video to a file.
So, right now, what I’m doing is to encode the video to a file and, after that, I open the saved video, read its contents into an
UInt8 array using the
readbytes!() function, encode the array using the
base64encode() function, serialize the encoded data using the
JSON.json() function and then send the serialized data over to the server using the package HTTP.jl.
Since this procedure can happen quite frequently at times, I wonder if it’s possible to encode the video straight into an
UInt8 array without having to save it to a file on disk first. If that’s not possible, maybe there’s a way to at least avoid flushing the contents of the “video file” to disk, maybe using something like tmpfs on Linux? Does anybody know?
Thanks a lot!
If the VideoIO package have methods for writing to an
IO you can write it directly to a HTTP stream. Why do you need to encode and make it into JSON?
I took a look at the VideoIO source code and, as far as I can tell, all writing methods expect a string with the name of the file to be written to.
The output video file will have to be opened for writing somewhere in the code, at which point I think I could intercept the call and provide it an IO object. However, I’d rather avoid messing with the internals of VideoIO this way.
On Linux, it looks like the directory
/run/user/ is mounted on RAM (using tmpfs). So I guess I can use Julia’s
mktemp() functions to create the output video files in this directory and hopefully that will involve no disk activity at all. I’m going to give that a try.
As to why I need to encode the video contents to base64 and serialize it into JSON, I’m not sure. This is how it’s done in the original Python code I’m converting from. I thought serialization was necessary before sending data over HTTP, but I’m not sure, as I don’t know much about web servers
Thanks a lot!