how to create thumbnail image by using video url for jquery jplayer

Udaya Ravi picture Udaya Ravi · Mar 3, 2015 · Viewed 9.3k times · Source

i need create to show thumbnail image in poster by using video url for jquery j-player.i have seek in forum.but i didn't got any useful information related to thumbnail.anyone can give me some ideas to do it..
Thanks Advance..

$("#jquery_jplayer_2"+playid).jPlayer({
    ready: function () {
        $(this).jPlayer("setMedia", {
            /*m4v: "media/tokyo.m4v",
            ogv: "media/tokyo.ogv",
            poster: "media/poster.jpg"*/
            m4v: playpath,
            ogv: playpath,
            poster: playpath
        });
    },
    ended: function (event) {
        $("#jquery_jplayer_2"+playid).jPlayer("play", 0);
    },
    swfPath: "swf",
    supplied: "m4v, ogv",
    cssSelectorAncestor: "#jp_interface_2"
})
.bind($.jPlayer.event.play, function() { // pause other instances of player when current one play
        $(this).jPlayer("pauseOthers");
    });

Answer

eladcon picture eladcon · Mar 4, 2015

You can create a new canvas to capture the image:

var canvas = document.createElement('canvas');
canvas.width = 640;
canvas.height = 480;
var context = canvas.getContext('2d');
context.drawImage(video, 0, 0, canvas.width, canvas.height);

and then save it to dataURI:

var dataURI = canvas.toDataURL('image/jpeg');

From here you can use it in an image element, save it as a file or upload it to your server:

$('img1').attr("src", dataURI);

Take a look at this plunker. Start the video and press the GET button. Notice that since the video is coming from another domain I had to set the crossOrigin attribute on the video element in the jplayer ready event:

$(this).find("video")[0].setAttribute("crossOrigin", "anonymous");