Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Base64 video encoding - good\bad idea? [closed]

People also ask

Is Base64 encoding safe?

No, absolutely not. base64 is not encryption. People in the sector readily recognise base64-encoded data. In many places where base64 is used, metadata announces this explicitly.

Can you Base64 encode a video?

Base64 is a perfectly acceptable method of retrieving a video. In fact, it works amazing for a private messaging system.

Why is Base64 encoding a good choice?

The advantages of Base64 encode, like somebody said, are available to transmit data from binary, into (most commonly) ASCII characters. Due to the likeliness that the receiving end can handle ASCII, it makes it a nice way to transfer binary data, via a text stream.

What is the purpose of Base64 encoding Why not just use binary?

Base64 encoding schemes are commonly used when there is a need to encode binary data that needs to be stored and transferred over media that are designed to deal with ASCII. This is to ensure that the data remain intact without modification during transport.


[...] the backend developer [...] insists that the media files (images/videos) should be transferred as base64 encoded in json files.

This is a very bad (and silly) idea up-front. You do not want to transfer large amount of binary data as strings. Especially not Unicode strings.

Here you need to arm up and convince your backend dev rebel to change his mind with what-ever it takes, play some Biber or Nickelback, or even change his background image to something Hello Kitty, or take a snapshot of his screen, set it as background and hide all the icons and the bar. This should help you changing his mind. If not, place a webasto in his office at max and lock all doors and windows.

Is base64 encoding a popular way of transferring media in mobile development?

It is popular and has a relative long history and became very common on Usenet and so forth. In those days however, the data amount was very low compared to today as all data where transferred over modems.

However, just because it is popular doesn't mean it is the right tool for everything. It is not very efficient as it require an encoding process which convert three octets into four bytes, causing an addition of 33% to the size.

On top of that: in JavaScript each string char is stored as two bytes due to Unicode char-set so your data is doubled and extended 33%. Your 300 mb data is now 300 x 2 x 1.33 = 798 mb (show that to your backdev! :) as it's a real factor if the servers cannot handle large amount of traffic).

This works fine for smaller files but for larger file as in your example this can cause a significant overhead in both time and memory usage, and of course bandwidth. And of course, on server side you would need to reverse the process with its own overhead.

And if not, what alternative way would you recommend using to transfer/present these videos?

I would recommend:

  • Separate meta-data out as JSON with a reference to the data. No binary data in the JSON.
  • Transfer the media data itself separately in native bytes (ArrayBuffer).
  • Send both at the same time to server.

The server then only need to parse the JSON data into edible for the backend, the binary data can go straight to disk.

Update I forgot to mention, as Pablo does in his answer, that you can look into streaming the data.

However, streaming is pretty much a synonym with buffering so the bandwidth will be about the same, just provided in a more brute-force way (usually UDP versus TCP, ie. loss of packets doesn't break the transfer). Streaming with limit your options more than buffering in the client though.

My 2 cents...


Not sure why "33% overhead" is always mentioned, when that's complete nonsense. Yes, it does initially roughly add that amount, however there's a little thing called gzip (ever heard of it?). I've done tons of tests and the difference is typically negligible. In fact, sometimes the gzipped base64 string is actually smaller than the binary file. Check out this guy's tests. So please, can we stop spreading absolute fiction.

Base64 is a perfectly acceptable method of retrieving a video. In fact, it works amazing for a private messaging system. For instance, if you were using AWS S3, you could store the files privately so there is no URL.

However, the main disadvantage (imho) of using a gzipped base64 video is that you need to wait for the whole video to load, so pseudo-streaming is out of the question.


Base64 is a convenient (but not efficient) way of transferring binary data. It's inefficient because transfer size will be 33% bigger than what you're originally transferring. Si it's not a popular way of transmitting video. If you are planning to stream that video, you should be looking for a established protocol for doing just that.

I would recommend a streaming protocol (there are a lot where you can chose from).