Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use with array playlist as input? #42

Closed
pietrop opened this issue Apr 21, 2017 · 1 comment
Closed

Use with array playlist as input? #42

pietrop opened this issue Apr 21, 2017 · 1 comment

Comments

@pietrop
Copy link

pietrop commented Apr 21, 2017

This is more of a question and less of an issue, but I'd been using the node deprecated BBC HTML5 Video Compositor, and I really liked the possibility of being able to pass in a playlist that consisted of an array of clips, as an EDL of some sort.

Is there a way to do the same in VideoContext?

@MatthewShotton
Copy link
Contributor

MatthewShotton commented Apr 21, 2017

Hi @pietrop

Yeah, absolutely this is possible!

I've added a static utility function called importSimpleEDL which you can pass a one dimensional array of clips and a VideoContext instance and it will automatically create the necessary sourceNodes and connect them to a track node.

The descriptions for the clips is in the same format as the html5-video-compositor.

It can be used like the following:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript" src="../dist/videocontext.js"></script>
</head>
<body>
    <p>
        <canvas id="canvas" width="480", height="320"></canvas>
    </p>
    <button id="play-button">Play</button>
    <button id="pause-button">Pause</button>
    <script type="text/javascript">

        window.onload = function(){

            var canvas = document.getElementById("canvas");
            var ctx = new VideoContext(canvas);


            var playlist = [
                {type:"video", sourceStart:0, start:0, duration:5, src:"video1.mp4"},
                {type:"video", sourceStart:0, start:5, duration:5, src:"video2.mp4"},
                {type:"video", sourceStart:10, start:10, duration:5, src:"video3.mp4"}
            ];

            var videoTrack = VideoContext.importSimpleEDL(ctx, playlist);
            // Connect the created track to the ouput canvas so it can be rendered.
            // You could also connect the video track to an effect node if you wanted to do effects.
            videoTrack.connect(ctx.destination);


            var playButton = document.getElementById("play-button");
            var pauseButton = document.getElementById("pause-button");
            playButton.onclick = function(){ ctx.play(); };
            pauseButton.onclick = function(){ ctx.pause(); };
        };
    </script>
</body>
</html>

The importSimpleEDL code is pretty straight forward and can be found here and should hopefully give a bit of an introduction about how to use the VideoContext.

The VideoContext in general has a bunch of advantages over the old html5-video-compositor such as better support on mobile, better resource management, support for doing transitions between clips, more effects. The downside is it's a bit more complicated to use as it provides a lower level interface, but in general you should be able to do everything that the html5-video-compositor could do and more.

Let me know if you have any other questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants