From 0feeef6d7d2fb9f25acdedde36cd38bf5a8789c8 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 6 Feb 2011 18:10:28 +0530 Subject: [PATCH] make derivatives more generic --- pandora/archive/extract.py | 9 +++++--- pandora/archive/models.py | 4 ++-- pandora/archive/views.py | 2 -- pandora/item/models.py | 29 +++++-------------------- pandora/settings.py | 18 ++++++++++----- static/js/jquery/jquery.videosupport.js | 1 + static/js/pandora.js | 12 +++++----- 7 files changed, 34 insertions(+), 41 deletions(-) diff --git a/pandora/archive/extract.py b/pandora/archive/extract.py index ef01080da..a840a67a8 100644 --- a/pandora/archive/extract.py +++ b/pandora/archive/extract.py @@ -196,10 +196,13 @@ def stream(video, target, profile, info): + audio_settings \ + video_settings - if format == 'mp4': - cmd += ["%s.mp4"%target] - else: + if format == 'webm': cmd += ['-f', 'webm', target] + if format == 'mp4': + #mp4 needs postprocessing(qt-faststart), write to temp file + cmd += ["%s.mp4"%target] + else : + cmd += [target] print cmd p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT) diff --git a/pandora/archive/models.py b/pandora/archive/models.py index 4f44775f4..fbde9fb7f 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -139,7 +139,7 @@ class File(models.Model): #upload and data handling video = models.FileField(null=True, blank=True, - upload_to=lambda f, x: f.path('%s.webm'%settings.VIDEO_PROFILE)) + upload_to=lambda f, x: f.path(settings.VIDEO_PROFILE)) data = models.FileField(null=True, blank=True, upload_to=lambda f, x: f.path('data.bin')) @@ -221,7 +221,7 @@ class File(models.Model): def save_chunk(self, chunk, chunk_id=-1): if not self.available: if not self.video: - self.video.save('%s.webm'%settings.VIDEO_PROFILE, chunk) + self.video.save(settings.VIDEO_PROFILE, chunk) else: f = open(self.video.path, 'a') #FIXME: should check that chunk_id/offset is right diff --git a/pandora/archive/views.py b/pandora/archive/views.py index 9c123c320..ad7f219b3 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -161,8 +161,6 @@ class VideoChunkForm(forms.Form): @login_required_json def firefogg_upload(request): profile = request.GET['profile'] - if profile.endswith('.webm'): - profile = os.path.splitext(profile)[0] oshash = request.GET['oshash'] #handle video upload if request.method == 'POST': diff --git a/pandora/item/models.py b/pandora/item/models.py index 125b2c0ce..3fe2dbf6d 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -333,6 +333,7 @@ class Item(models.Model): else: stream['baseUrl'] = os.path.dirname(s.video.url) stream['profiles'] = list(set(map(lambda s: int(os.path.splitext(s['profile'])[0][:-1]), self.streams.all().values('profile')))) + stream['formats'] = list(set(map(lambda s: os.path.splitext(s['profile'])[1][1:], self.streams.all().values('profile')))) return stream def get_layers(self): @@ -588,7 +589,7 @@ class Item(models.Model): ''' def frame(self, position, width=128): - stream = self.streams.filter(profile=settings.VIDEO_PROFILE+'.webm') + stream = self.streams.filter(profile=settings.VIDEO_PROFILE) if stream.count()>0: stream = stream[0] else: @@ -627,7 +628,7 @@ class Item(models.Model): #FIXME: how to detect if something changed? if files: stream, created = Stream.objects.get_or_create(item=self, - profile='%s.webm' % settings.VIDEO_PROFILE) + profile=settings.VIDEO_PROFILE) stream.video.name = stream.path() cmd = [] if os.path.exists(stream.video.path): @@ -766,7 +767,7 @@ class Item(models.Model): def get_poster_frame_path(self): if self.poster_frame >= 0: - size = int(settings.VIDEO_PROFILE[:-1]) + size = int(settings.VIDEO_PROFILE.split('.')[0][:-1]) return self.frame(self.poster_frame, size) frames = [] @@ -919,33 +920,13 @@ class Stream(models.Model): return self.item.path(self.profile) def extract_derivatives(self): - if settings.VIDEO_H264: - profile = self.profile.replace('.webm', '.mp4') + for profile in settings.VIDEO_DERIVATIVES: derivative, created = Stream.objects.get_or_create(profile=profile, item=self.item) if created: derivative.source = self derivative.video.name = self.video.name.replace(self.profile, profile) derivative.encode() derivative.save() - - for p in settings.VIDEO_DERIVATIVES: - profile = p + '.webm' - target = self.video.path.replace(self.profile, profile) - derivative, created = Stream.objects.get_or_create(profile=profile, item=self.item) - if created: - derivative.source = self - derivative.video.name = self.video.name.replace(self.profile, profile) - derivative.encode() - derivative.save() - - if settings.VIDEO_H264: - profile = p + '.mp4' - derivative, created = Stream.objects.get_or_create(profile=profile, item=self.item) - if created: - derivative.source = self - derivative.video.name = self.video.name.replace(self.profile, profile) - derivative.encode() - derivative.save() return True def encode(self): diff --git a/pandora/settings.py b/pandora/settings.py index 55150a99f..06be2e55d 100644 --- a/pandora/settings.py +++ b/pandora/settings.py @@ -144,15 +144,23 @@ SITE_CONFIG = join(PROJECT_ROOT, '0xdb.json') DEFAULT_SORT = [{"key": "director", "operator": ""}] DEFAULT_THEME = "classic" -VIDEO_PROFILE = '96p' +VIDEO_PROFILE = '96p.webm' VIDEO_DERIVATIVES = [] VIDEO_H264 = False #Pad.ma -#VIDEO_PROFILE = '480p' -#VIDEO_DERIVATIVES = ['96p', '270p', '360p'] -#VIDEO_H264 = False - +''' +VIDEO_PROFILE = '480p.webm' +VIDEO_DERIVATIVES = [ + '96p.webm', + '240p.webm', + '360p.webm' + '96p.mp4', + '240p.mp4', + '360p.mp4', + '480p.mp4', +] +''' TRANSMISSON_HOST = 'localhost' TRANSMISSON_PORT = 9091 diff --git a/static/js/jquery/jquery.videosupport.js b/static/js/jquery/jquery.videosupport.js index ae999c3f8..01197b84a 100644 --- a/static/js/jquery/jquery.videosupport.js +++ b/static/js/jquery/jquery.videosupport.js @@ -10,6 +10,7 @@ jQuery.support.video = function() { video.webm = false; video.h264 = !!(v.canPlayType && v.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"').replace(/no/, '')); video.ogg = !!(v.canPlayType && v.canPlayType('video/ogg; codecs="theora, vorbis"').replace(/no/, '')); + video.ogv = video.ogg; } else { video.support = false; } diff --git a/static/js/pandora.js b/static/js/pandora.js index 769dab2d5..c14a33c30 100755 --- a/static/js/pandora.js +++ b/static/js/pandora.js @@ -1734,10 +1734,11 @@ }); } else if (app.user.ui.itemView == 'player') { var video = result.data.item.stream, - subtitles = result.data.item.layers.subtitles; + subtitles = result.data.item.layers.subtitles, + format = Ox.supportedVideoFormat(video.formats); video.height = video.profiles[0] video.width = parseInt(video.height * video.aspectRatio / 2) * 2; - video.url = video.baseUrl + '/' + video.height + 'p.' + ($.support.video.webm ? 'webm' : 'mp4'); + video.url = video.baseUrl + '/' + video.height + 'p.' + format; app.$ui.contentPanel.replace(1, app.$ui.player = new Ox.VideoPanelPlayer({ annotationsSize: app.user.ui.annotationsSize, duration: video.duration, @@ -1775,10 +1776,11 @@ 'in': 5, 'out': 10, 'value': 'This subtitle is just a test...' - }]; - video.height = video.profiles[0] + }], + format = Ox.supportedVideoFormat(video.formats); + video.height = video.profiles[0]; video.width = parseInt(video.height * video.aspectRatio / 2) * 2; - video.url = video.baseUrl + '/' + video.height + 'p.' + ($.support.video.webm ? 'webm' : 'mp4'); + video.url = video.baseUrl + '/' + video.height + 'p.' + format; app.$ui.contentPanel.replace(1, app.$ui.editor = new Ox.VideoEditor({ annotationsSize: app.user.ui.annotationsSize, cuts: cuts,