Skip to content

Commit

Permalink
Merge pull request #3 from danielbwatson/master
Browse files Browse the repository at this point in the history
Render two canvas slices from one video
  • Loading branch information
danielbwatson committed Mar 26, 2012
2 parents a28080f + 5c52d33 commit d0aceb3
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
apply plugin: 'war'
apply plugin: 'jetty'

jettyRun.contextPath = '/'
18 changes: 18 additions & 0 deletions src/main/webapp/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style/main.css" />
</head>
<body>
<video controls>
<source src="video/video.webm" type='video/webm; codecs="vp8, vorbis"' />
</video>
<br/>
<canvas id="primary"></canvas>
<br/>
<canvas id="secondary"></canvas>
<script src="js/jquery.js"></script>
<script src="js/main.js"></script>
</body>
</html>

4 changes: 4 additions & 0 deletions src/main/webapp/js/jquery.js

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions src/main/webapp/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

(function() {
var $video, $buffer, $primary, $secondary, video, buffer, primary, secondary, bufferCtx, primaryCtx, secondaryCtx,
initializeCanvases, config;

// var getResult = $.getJSON('/video/video.json');
//
//
// console.log(getResult);
// var configText = getResult.responseText;
// console.log(configText);
// config = jQuery.parseJSON(configText);


config = { "primary": { "x": 0, "y": 0, "w": 1200, "h": 720 }, "secondary": { "x": 1200, "y": 480, "w": 320, "h": 240 } };
$video = $('video');
$primary = $('#primary');
$secondary = $('#secondary');
video = $video[0];
primary = $primary[0];
secondary = $secondary[0];

initializeCanvases = function () {
var renderFrame;
primaryCtx = primary.getContext('2d');
secondaryCtx = secondary.getContext('2d');

primary.height = config.primary.h;
primary.width = config.primary.w;
secondary.width = config.secondary.w;
secondary.height = config.secondary.h;

renderFrame = function() {

// Render a slice into the primary canvas.
primaryCtx.drawImage(video, config.primary.x, config.primary.y, config.primary.w, config.primary.h, 0, 0,
config.primary.w, config.primary.h);

secondaryCtx.drawImage(video, config.secondary.x, config.secondary.y, config.secondary.w,
config.secondary.h, 0, 0, config.secondary.w, config.secondary.h);
};
setInterval(renderFrame, 30);

};
$video.bind('canplay', initializeCanvases);

video.play();

})();
1 change: 1 addition & 0 deletions src/main/webapp/style/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
video { display: none; }
Empty file.

0 comments on commit d0aceb3

Please sign in to comment.