Is possible to create and download a video file via JavaScript, only on the client side?

Is possible to create and download a video file only on the client side?

Suppose that we have an animated canvas like in this JSFIDDLE. Please see this snippet:

...
var stop = false;
setTimeout(function () {
    stop = true;
}, 1860);
...
if (!stop) { requestAnimationFrame( draw, 10 ); }

So, my animation duration is 1860ms.

We can generate text files for download, I know that we can generate images from canvas, but is possible to render and download a video file?

Would adding sound possible?

2

Disclaimer: I haven’t done this myself so all the information I am providing is only what I have found by researching

In theory, yes it is possible but not easy or practical.

Overview

So basically you are looking at having more-or-less a video encoder in-browser which can take the images you get form the canvas and convert it to video.

I had a few concerns first whether it was possible to actually do this, mainly:

  • Is there a limit on Blob size? According to the W3C Blob spec, there doesn’t seem to be.
  • How the browser will handle the amount of memory required to do encoding?

In your circumstance, the animation duration is short enough that I do not believe that memory will be an issue (at least in terms of storing the images and video).

Let’s get encoding!

I mentioned that you are basically having a video encoder. There are really two options for this, either build your own encoder or hope that someone has built some sort of encoder already.

An awesome answer on GameDev (and later found something similar on StackOverflow) explains that FFmpeg can create a video slideshow from images.

For those who don’t know, FFmpeg is a free software project that produces libraries and programs for handling multimedia data

I know what you might be thinking, how is FFmpeg going to help me, that isn’t JavaScript… right?

Well, before today I would have thought the same thing until I found videoconverter.js which apparently is a working copy of FFmpeg in JavaScript!

What’s the catch?

Well, the FFmpeg JS file is kind of large weighing in at ~6MB gzipped (or ~24 MB uncompressed). The browser memory footprint is bound to be quite large!

I will note I am also making a few big assumption here:

  • That the FFmpeg JS can actually read an image blob so we can build the video slideshow
  • That FFmpeg JS actually supports all the same functions as the standard FFmpeg application

Besides FFmpeg, what is another way?

You can pick the format of video you want to output and write your own encoder!

To get you started, you could look at the spec for AVI (Audio Video Interlaced) or possibly Theora. You would be writing the information to a blob like you did in your text download example.

This stuff really is out of my skill set so I will leave the finer details of this up to you.

This isn’t practical! This is a mountain of effort for a small video!

I said from the beginning that it wasn’t going to be easy. What @ShivanDragon mentioned in the comments is the way I would personally go about it. Pass the images off to a server, get it generated and then downloaded.

There are some reasons why you might want it in-browser but I really don’t see it being practical.

Edit: Hang on! I also asked whether sound is possible!

Whoops, I missed that part! Yes, adding sound is definitely possible though will add even more complexity into the mix. You can add audio as a second input file for FFmpeg which will insert it into the output video.

In terms of making your own video encoder, it will add a decent amount of extra effort for adding an audio stream. Probably best place to start is another few links to specs for audio like Vorbis or WAV.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật