Video captioning made easy with the YouTube JavaScript API

One thing that has been annoying me for ages is that no video player on the web allows you to write comments for a specific time in the video that get displayed as plain text. Viddler allows you to comment at a certain time and it appears in the video, but the benefits of time based captioning both in terms of accessibility and SEO didn’t quite transpire to any video site maintainers yet. Edit: Darn, I hadn’t looked at Viddler for a long time, it actually does this now, well done!

Google just released a JavaScript API for YouTube which makes it dead easy to control a video with JavaScript. You can start, stop and jump to a certain time of the video but more importantly – you have events firing when something happens to the player. This made it easy for me to whip up a proof of concept how time-based captioning might work as an interface. Click the screenshot to see it in action.

Screenshot of video with timed captions created with a small JavaScript

Start the video and hit the pause button to add a new caption. You can delete captions by hitting the x links and you can jump back to the section of the video by clicking the time stamp.

Check the source for how it is done. In order to make this a service, all you need to do is have a backend script that gets all the form fields and store it in a DB.

Tags: , , , , ,

14 Responses to “Video captioning made easy with the YouTube JavaScript API”

  1. stefield Says:

    Does this mean I can create my gallery of Britney Spears nipple slip videos then?

    It’d be cool if you grab the frame at pause point as an image to quickly create a slide show too.

  2. Marin Says:

    Ho man, that will make the transcription works so easy :)

    Finally we have an easy way of providing skiplinks and alternative content for those (sometimes not so) interesting movies

  3. diana Says:

    it doesn’t work for me, not in Opera, nor in Firefox??

  4. this field is required Says:

    > One thing that has been annoying me for ages is that no video player on the web allows you to write comments for a specific time in the video that get displayed as plain text. Viddler allows you to comment at a certain time and it appears in the video, but the benefits of time based captioning both in terms of accessibility and SEO didn’t quite transpire to any video site maintainers yet.

    Are you retarded? “No one does X. Y does X.” We should also not forget http://en.wikipedia.org/wiki/Nico_Nico_Douga which is nearly completely devoted to having text overlayed on video at specific times even if it does normally consist of??????????????or ?????????.

    Edit: Good information. Bad style. Thanks anyways.

  5. Thom Shannon Says:

    @”a brain is required”

    I think you missed the point, what Chris was saying is “No one does X. Y almost does X but not quite”. He said no video sites appear to make the comments available in the source for SEO, Screenreaders and other such things. Nico may have the comments in the source but you have to login so it’s certainly not search engine friendly! (Viddler do actually seem to write time coded comments out below the video though)

  6. Sarah Bourne Says:

    I recently came across this site, free for now anyway, that not only has a widget for captioning, but lets other folks in on the fun by letting them add transcriptions in other languages: http://www.dotsub.com/ It looks like it uses a very similar approach to yours, but then again, how many different ways could there be? But a “poor man’s” YouTube API would be wicked awesome (note the local dialect!) – it would solve some accessibility issues we’re struggling with here in Massachusetts.

  7. Carlos Says:

    The only thing I get when I click on the “give me the transcript” button is a dialog box asking me to save or open a json file. Is there something I’m missing?

  8. diana Says:

    @Carlos: I have the same prob

  9. Chris Says:

    @carlos, diana: This is what it is for now. I am trying to work out a player for it, but haven’t come around to that yet.

  10. Bill Says:

    Anxiously awaiting more….

  11. hernan Says:

    Check out this implementation of youtube api for subtitles:

    http://www.captiongrabber.com

  12. harald Says:

    i need such thing for “google videos”. do you have one?

  13. mk Says:

    Hi!
    I’m not an expert about js and youtub api! :(
    I’m seeing your script, showed here:
    http://icant.co.uk/sandbox/youtube-captioning.html

    I want to use your same structure but I want to load all functions and objects needed after an event like a click on a link, so onclick=”javascript:loadPlayer()”;

    My function is:
    function caricaPlayer(){
    var vid = document.createElement(‘div’);
    vid.id=’videoForm’;
    vid.setAttribute(’style’,'float:left; margin: 4px;’);

    var env_var = document.createElement(‘input’);
    env_var.type = ‘hidden’;
    env_var.name = ‘objuri’;

    var script_header = document.createElement(’script’);
    script_header.type = ‘text/javascript’;
    script_header.src = ‘http://swfobject.googlecode.com/svn/tags/rc3/
    swfobject/src/swfobject.js’;

    var script_header2 = document.createElement(’script’);
    script_header2.type = ‘text/javascript’;
    script_header2.src = ‘http://lamp.local/madcow_bk/videoCMD.js’;

    var div_video = document.createElement(‘div’);
    div_video.id = ‘ytapiplayer’;
    div_video.innerHTML = \” You need Flash player 8+ and JavaScript enabled
    to view this video.\”;

    document.documentElement.getElementsByTagName(‘HEAD’)0.appendChild
    (script_header);
    vid.appendChild(div_video);
    vid.appendChild(script_header2);
    vid.appendChild(env_var);
    vid.innerHTML += \”Player state: –\”;
    vid.innerHTML += \”Play | Pause | Stop | Mute | Unmute |\”;
    document.body.appendChild(vid);
    }

    videoCMD.js contains all functions and the script that has to start the player:

    var params = {allowScriptAccess:”always”};
    var atts = {id:”myytplayer”};
    swfobject.embedSWF(“http://www.youtube.com/v/
    T4y6M2AeQ00&border=0&enablejsapi=1&playerapiid=ytplayer”,
    “ytapiplayer”, “425″, “356″, “8″, null, null, params, atts);

    So I can see the command link like play, stop, ecc…
    but in firebugs js error I read
    “ytplayer is not defined
    if (ytplayer) {“

    Why?
    The player doesen’t start because whan I click I read the div message:
    “You need Flash player 8+ and JavaScript enabled to view this video.” but it diseppear in some second without showing the video! :(

    Can you help me?
    Thank’s

    Mk

  14. Mirko Says:

    Would you mind sharing your PHP code too? Does it require a backend DB or could one do without one too?
    Thanks!

Leave a Reply

Wait till I come! is the blog of Christian Heilmann , a developer evangelist living and working in London, England. Download vcard.

Feed me, Seymour: Entries (RSS) and Comments (RSS).