Permalink
Browse files

checking for required transcoding bits

  • Loading branch information...
1 parent 6578898 commit a2abf681bb1d265058ef161b3b71b5f3a69f98f6 @benvanik committed Nov 23, 2011
Showing with 75 additions and 3 deletions.
  1. +75 −3 lib/content.js
View
@@ -14,7 +14,8 @@ var Content = function(id, source, target) {
mimeType: source.mimeType || undefined,
cookie: source.cookie || undefined,
referer: source.referer || undefined,
- auth: source.auth || undefined
+ auth: source.auth || undefined,
+ info: null // populated below
};
this.target = {
mimeType: target.mimeType || undefined,
@@ -30,7 +31,14 @@ var Content = function(id, source, target) {
this.extractMediaInfo_(function(info) {
util.puts(util.inspect(info));
self.source.info = info;
- self.readyToPlay_ = true;
+
+ // TODO: on the fly or when /cache is called
+ self.prepare_(function(err) {
+ if (!err) {
+ self.readyToPlay_ = true;
+ self.cached_ = true;
+ }
+ });
});
};
exports.Content = Content;
@@ -144,6 +152,70 @@ Content.prototype.extractMediaInfo_ = function(callback) {
}
};
+Content.prototype.prepare_ = function(callback) {
+ var needsRemux = false;
+ var needsVideoTranscode = false;
+ var needsAudioTranscode = false;
+
+ switch (this.source.info.container) {
+ case 'mov':
+ case 'mpegts':
+ break;
+ default:
+ needsRemux = true;
+ break;
+ }
+
+ var videoStream;
+ var audioStream;
+ for (var n = 0; n < this.source.info.streams.length; n++) {
+ var stream = this.source.info.streams[n];
+ switch (stream.type) {
+ case transcoding.StreamType.VIDEO:
+ videoStream = videoStream || stream;
+ break;
+ case transcoding.StreamType.AUDIO:
+ audioStream = audioStream || stream;
+ break;
+ }
+ }
+ switch (videoStream.codec) {
+ case 'h264':
+ break;
+ default:
+ needsVideoTranscode = true;
+ break;
+ }
+ switch (audioStream.codec) {
+ case 'aac':
+ case 'mp3':
+ break;
+ default:
+ needsAudioTranscode = true;
+ break;
+ }
+
+ if (needsVideoTranscode) {
+ util.puts('needs video transcode');
+ }
+ if (needsAudioTranscode) {
+ util.puts('needs audio transcode');
+ }
+ if (needsRemux) {
+ util.puts('needs remux');
+ }
+
+ if (needsVideoTranscode || needsAudioTranscode) {
+ // Needs either a video or audio transcode (and maybe a new container)
+ } else if (needsRemux) {
+ // Needs a simple remux (new container)
+ } else {
+ // Good to go
+ }
+
+ callback(null);
+};
+
Content.prototype.get = function(req, res) {
var sourceUrl = url.parse(this.source.content);
switch (sourceUrl.protocol) {
@@ -197,7 +269,7 @@ Content.prototype.localFileGet = function(req, res, sourceUrl) {
return;
}
- //
+ // TODO: transcoding, if required
var start = 0;
var end = stats.size;

0 comments on commit a2abf68

Please sign in to comment.