# Creating a video "file" and sending it to a web server without saving it to disk

**URL:** <https://discourse.julialang.org/t/creating-a-video-file-and-sending-it-to-a-web-server-without-saving-it-to-disk/70074>\
**Category:** General Usage\
**Tags:** filesystem, videoio\
**Created:** [October 19, 2021, 11:03pm UTC](https://discourse.julialang.org/t/creating-a-video-file-and-sending-it-to-a-web-server-without-saving-it-to-disk/70074 "2021-10-19T23:03:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adriano.vilela](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adriano.vilela/32/7596_2.png) [@adriano.vilela](https://discourse.julialang.org/u/adriano.vilela)\
**Post date:** [October 19, 2021, 11:03pm UTC](https://discourse.julialang.org/t/creating-a-video-file-and-sending-it-to-a-web-server-without-saving-it-to-disk/70074/1 "2021-10-19T23:03:30Z")

</div>

Hi,

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:

[https://juliaio.github.io/VideoIO.jl/stable/writing/](https://juliaio.github.io/VideoIO.jl/stable/writing/)

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!

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [October 20, 2021, 8:04am UTC](https://discourse.julialang.org/t/creating-a-video-file-and-sending-it-to-a-web-server-without-saving-it-to-disk/70074/2 "2021-10-20T08:04:01Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![adriano.vilela](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adriano.vilela/32/7596_2.png) [@adriano.vilela](https://discourse.julialang.org/u/adriano.vilela)\
**Post date:** [October 21, 2021, 3:08pm UTC](https://discourse.julialang.org/t/creating-a-video-file-and-sending-it-to-a-web-server-without-saving-it-to-disk/70074/3 "2021-10-21T15:08:17Z")

</div>

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](https://www.kernel.org/doc/html/latest/filesystems/tmpfs.html)). So I guess I can use Julia’s `tempname()` and `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!
