Permalink
Browse files

using node-transcoding now to query media info

  • Loading branch information...
1 parent 3d1b7ac commit 331b49118b3587b8aaad41e17ba673a239f3be23 @benvanik committed Nov 23, 2011
Showing with 53 additions and 106 deletions.
  1. +5 −0 README.md
  2. +2 −2 apps/chrome/src/background.js
  3. +9 −0 apps/chrome/src/service.js
  4. +19 −4 apps/chrome/src/test.html
  5. +16 −5 lib/content.js
  6. +0 −94 lib/mediainfo.js
  7. +2 −1 package.json
View
@@ -81,6 +81,11 @@ Setup a new content serving request:
readyToPlay: boolean
}
+ GET /content/[id]/info
+ --> {
+ ...tons of info...
+ }
+
POST /content/[id]/cache
{}
--> {}
@@ -104,8 +104,8 @@ function handleResponseStarted(tabId, details) {
case 'video/quicktime':
// Need transcoding:
// case 'video/avi':
- // case 'video/x-flv':
- // case 'video/x-m4v':
+ case 'video/x-flv':
+ case 'video/x-m4v':
// case 'video/x-msvideo':
// case 'video/x-ms-asf':
// case 'video/webm':
@@ -171,3 +171,12 @@ Service.prototype.getContentStatus = function(contentId, callback) {
}
});
};
+
+Service.prototype.getContentInfo = function(contentId, callback) {
+ this.get_('/content/' + contentId + '/info', function(response) {
+ window.console.log(response);
+ if (callback) {
+ callback(response);
+ }
+ });
+};
View
@@ -103,7 +103,9 @@
var checkReady = function() {
service.getContentStatus(contentId, function(status) {
if (status.readyToPlay) {
- callback();
+ service.getContentInfo(contentId, function(info) {
+ callback(info);
+ });
} else {
window.setTimeout(checkReady, 100);
}
@@ -123,22 +125,28 @@
};
service.setupContent(source, target, function(response) {
var contentId = response.id;
- waitUntilContentReady(contentId, function() {
+ waitUntilContentReady(contentId, function(info) {
+ // TODO: better presentation
+ infoBox.innerText = JSON.stringify(info);
play(endpoint + '/content/' + contentId);
});
});
}
function testContentLocal() {
- testContent('file:///Users/noxa/Downloads/test.m4v');
+ testContent('file:///Users/noxa/test_videos/test.m4v');
}
function testContentRemote() {
testContent('http://wwwappskc.lonestar.edu/cgi/video/html5/test.m4v');
}
+ function testContentFlv() {
+ testContent('file:///Users/noxa/test_videos/test.flv');
+ }
+
function testContentWebM() {
- testContent('file:///Users/noxa/Downloads/test1.webm');
+ testContent('file:///Users/noxa/test_videos/test1.webm');
}
function play(content) {
@@ -147,6 +155,7 @@
window.addEventListener('load', function() {
deviceList = document.getElementById('deviceList');
+ infoBox = document.getElementById('infoBox');
statusBox = document.getElementById('statusBox');
seekBar = document.getElementById('seekBar');
seekBar.addEventListener('mousedown', function() {
@@ -182,10 +191,16 @@
<a href="javascript:testRemote();">test</a>&nbsp;
<a href="javascript:testContentLocal();">test/fs</a>&nbsp;
<a href="javascript:testContentRemote();">test/remote</a>&nbsp;
+ <a href="javascript:testContentFlv();">test/flv</a>&nbsp;
<a href="javascript:testContentWebM();">test/webm</a>&nbsp;
<br/>
<input id="urlInput" type="text" size="150"></input>
<a href="javascript:play(document.getElementById('urlInput').value);">
play</a>
+ <br/>
+ <br/>
+ <div id="infoBox">
+ [info]
+ </div>
</body>
</html>
View
@@ -1,7 +1,7 @@
var fs = require('fs');
var http = require('http');
-var mediainfo = require('./mediainfo');
var temp = require('./temp');
+var transcoding = require('transcoding');
var url = require('url');
var util = require('util');
@@ -28,7 +28,7 @@ var Content = function(id, source, target) {
var self = this;
this.extractMediaInfo_(function(info) {
- console.log(util.inspect(info));
+ util.puts(util.inspect(info));
self.source.info = info;
self.readyToPlay_ = true;
});
@@ -121,13 +121,17 @@ Content.prototype.extractMediaInfo_ = function(callback) {
switch (sourceUrl.protocol) {
case 'file:':
var filename = decodeURI(sourceUrl.pathname);
- mediainfo.extractInfo(filename, callback);
+ transcoding.queryInfo(filename, function(err, info) {
+ callback(err ? null : info);
+ });
return;
case 'http:':
case 'https:':
this.downloadFile_(this.source.content, 0, 64000, function(filename) {
if (filename) {
- mediainfo.extractInfo(filename, callback);
+ transcoding.queryInfo(filename, function(err, info) {
+ callback(err ? null : info);
+ });
} else {
callback(null);
}
@@ -193,6 +197,9 @@ Content.prototype.localFileGet = function(req, res, sourceUrl) {
return;
}
+ //
+
+ /*
var start = 0;
var end = stats.size;
if (req.headers['range']) {
@@ -219,7 +226,7 @@ Content.prototype.localFileGet = function(req, res, sourceUrl) {
end: end
}).pipe(res, {
end: true
- });
+ });*/
});
};
@@ -284,6 +291,10 @@ Content.prototype.status = function(req, callback) {
});
};
+Content.prototype.info = function(req, callback) {
+ callback(this.source.info);
+};
+
Content.prototype.cache = function(req, callback) {
callback({});
};
View
@@ -1,94 +0,0 @@
-var child_process = require('child_process');
-var util = require('util');
-
-var DomJS = require('dom-js').DomJS;
-
-exports.extractInfo = function(filename, callback) {
- var results = '';
- var mediainfo = child_process.spawn('mediainfo', [
- '--output=xml',
- filename
- ]);
- mediainfo.stdout.on('data', function(data) {
- results += data;
- });
- mediainfo.stderr.on('data', function(data) {
- console.log('mediainfo stderr: ' + data);
- });
- mediainfo.on('exit', function(code) {
- if (code == 0) {
- var domjs = new DomJS();
- domjs.parse(results, function(err, dom) {
- function getProperty(el, name) {
- for (var n = 0; n < el.children.length; n++) {
- var child = el.children[n];
- if (child.name == name) {
- return child.children[0].text;
- }
- }
- return null;
- };
- var info = {
- format: null,
- //duration: 0,
- videoTracks: [],
- audioTracks: []
- };
- for (var n = 0; n < dom.children.length; n++) {
- var fileEl = dom.children[n];
- if (fileEl.name == 'File') {
- for (var m = 0; m < fileEl.children.length; m++) {
- var trackEl = fileEl.children[m];
- if (trackEl.name == 'track') {
- switch (trackEl.attributes.type) {
- case 'General':
- // Format: 'Flash Video'
- info.format = getProperty(trackEl, 'Format');
- // Duration: '2mn 6s'
- var duration = getProperty(trackEl, 'Duration');
- // TODO: convert and store info.duration
- break;
- case 'Video':
- var videoTrack = {
- type: 'video',
- // Format: AVC
- format: getProperty(trackEl, 'Format'),
- // Width: 640 pixels
- width: parseInt(getProperty(trackEl, 'Width')
- .replace(/ pixels/, '')),
- // Height: 360 pixels
- height: parseInt(getProperty(trackEl, 'Height')
- .replace(/ pixels/, '')),
- // Frame_rate: 29.970 fps
- frameRate: parseFloat(
- getProperty(trackEl, 'Frame_rate')
- .replace(/ fps/, '')),
- // Format_profile: Main@L3.0
- profile: parseInt(
- getProperty(trackEl, 'Format_profile')
- .replace(/[^0-9]/g, '')),
- // Format_settings__QPel: No
- qpel: (getProperty(trackEl, 'Format_settings__QPel')
- != 'No')
- };
- info.videoTracks.push(videoTrack);
- break;
- case 'Audio':
- var audioTrack = {
- // Format: AAC
- format: getProperty(trackEl, 'Format')
- };
- info.audioTracks.push(audioTrack);
- break;
- }
- }
- }
- }
- }
- callback(info);
- });
- } else {
- console.log('child process exited with code ' + code);
- }
- });
-};
View
@@ -26,7 +26,8 @@
"tav": "0.1.0",
"node-uuid": "1.2.0",
"dom-js": "0.0.6",
- "airplay": ">=0.0.1"
+ "airplay": ">=0.0.1",
+ "transcoding": ">=0.0.1"
},
"scripts": {
"start": "node server.js"

0 comments on commit 331b491

Please sign in to comment.