Permalink
Browse files

simple ghetto remuxing!

  • Loading branch information...
1 parent a2abf68 commit 310817d84c2c9d5d7e2b782d9b1cac8c71e472fb @benvanik committed Nov 23, 2011
Showing with 61 additions and 14 deletions.
  1. +61 −14 lib/content.js
View
@@ -27,6 +27,10 @@ var Content = function(id, source, target) {
this.seekable_ = false;
this.readyToPlay_ = false;
+ this.needsVideoTranscode_ = false;
+ this.needsAudioTranscode_ = false;
+ this.needsRemux_ = false;
+
var self = this;
this.extractMediaInfo_(function(info) {
util.puts(util.inspect(info));
@@ -94,9 +98,10 @@ Content.prototype.createRemoteRequest_ = function(method, headers, callback) {
};
Content.prototype.downloadFile_ = function(url, start, end, callback) {
- var headers = {
- 'Range': 'bytes=' + start + '-' + end
- };
+ var headers = {};
+ if (end !== undefined) {
+ headers['Range'] = 'bytes=' + (start || 0) + '-' + end;
+ }
var tempName = temp.generateName();
var tempFile = fs.createWriteStream(tempName);
@@ -195,25 +200,67 @@ Content.prototype.prepare_ = function(callback) {
break;
}
- if (needsVideoTranscode) {
- util.puts('needs video transcode');
- }
- if (needsAudioTranscode) {
- util.puts('needs audio transcode');
- }
- if (needsRemux) {
- util.puts('needs remux');
- }
+ this.needsVideoTranscode_ = needsVideoTranscode;
+ this.needsAudioTranscode_ = needsAudioTranscode;
+ this.needsRemux_ = needsRemux;
if (needsVideoTranscode || needsAudioTranscode) {
// Needs either a video or audio transcode (and maybe a new container)
+ util.puts('needs transcoding, video: ' +
+ needsVideoTranscode + ', audio: ' + needsAudioTranscode);
+ this.offlineTranscode_(callback);
} else if (needsRemux) {
// Needs a simple remux (new container)
+ util.puts('needs remuxing');
+ this.offlineTranscode_(callback);
} else {
- // Good to go
+ // Good to go!
+ callback(null);
}
+};
+
+Content.prototype.offlineTranscode_ = function(callback) {
+ var self = this;
+
+ function transcode(filename) {
+ var tempName = temp.generateName();
+ this.source.content = 'file://' + tempName;
+ util.puts(this.source.content);
+
+ transcoding.process(filename, tempName, transcoding.profiles.APPLE_TV_2, {
+ }, function(err, sourceInfo, targetInfo) {
+ if (err) {
+ callback(err);
+ return;
+ }
+
+ // ?
+ });
+
+ callback(null);
+ };
- callback(null);
+ var sourceUrl = url.parse(this.source.content);
+ switch (sourceUrl.protocol) {
+ case 'file:':
+ // Already local
+ transcode.call(this, sourceUrl.pathname);
+ break;
+ case 'http:':
+ case 'https:':
+ // Download first, then process
+ this.downloadFile_(this.source.content, 0, undefined, function(filename) {
+ if (filename) {
+ transcode.call(self, filename);
+ } else {
+ callback(null);
+ }
+ });
+ break;
+ default:
+ callback(new Error('Unknown protocol ' + sourceUrl.protocol));
+ break;
+ }
};
Content.prototype.get = function(req, res) {

0 comments on commit 310817d

Please sign in to comment.