0

I have a page that plays 4 videos from a local source, and I combine those all into a canvas so that all display through one element (I update the image on the canvas every X seconds). Is there any way I can save that into a video file?

Eliezer
  • 7,209
  • 12
  • 56
  • 103

1 Answers1

1

First: I do not recommend the following method for big amounts of data!!

You can create an array with a size big enough to store the whole video:

//Size: Colour channels * width * height * noOfFrames
//THIS WILL GET BIG!!
var video = new Uint8Array(3*640*480*24);

Then store every frame of your video in the array

Now you could use this snippet as a start to convert it to a DataUrl:

var base64String = btoa(String.fromCharCode.apply(null, video));

(http://stackoverflow.com/a/11562550/1554114)

This would give you something like RAW-Video.
This is a link with a DataUrl, save it via right-click / save as.. / "Test.mp4"
(Let's see if SO can handle this :D -- No, it can't :( -- Press the 'edit' button to see what it looks like)

Implementing h264 in JavaScript is up to you then ;)

Nippey
  • 4,708
  • 36
  • 44
  • Thanks! For now I'll be fine with RAW-Video. What are the chances this will crash (out of memory or something like that) while using a canvas that is displaying the video from 4 1280 x 720 videos? – Eliezer Nov 20 '12 at 12:37
  • 1
    I don't even want to imagine this. That are 66MB/s `:D` And as this code can't work piece by piece, the conversion to dataURL will consume additionally about three times the original array size I guess. – Nippey Nov 20 '12 at 13:25
  • I modified my code so that when the video plays for 1 second it stops and dumps the raw data to the screen....this is 1 second of a 6 minute video and 5 minutes have already gone by and it's not close to being done :-) – Eliezer Nov 21 '12 at 04:50
  • Hi, I have been able to merge my two videos into one canvas, but I am not able to find any way to save the video output of canvas. I was thinking of saving each frame as an image and then using any backend programming language convert the same into video, but that would not be efficient for high quality videos. And I have done very less work on canvas, could you please explain the code above. I could not get it that what the above code would do – Deepanshu Goyal Jul 09 '15 at 11:05