make derivatives more generic

This commit is contained in:
j 2011-02-06 18:10:28 +05:30
parent 7dd47d1544
commit b563afcfc8
7 changed files with 34 additions and 41 deletions

View file

@ -196,10 +196,13 @@ def stream(video, target, profile, info):
+ audio_settings \ + audio_settings \
+ video_settings + video_settings
if format == 'mp4': if format == 'webm':
cmd += ["%s.mp4"%target]
else:
cmd += ['-f', 'webm', target] 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 print cmd
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT) p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT)

View file

@ -139,7 +139,7 @@ class File(models.Model):
#upload and data handling #upload and data handling
video = models.FileField(null=True, blank=True, 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, data = models.FileField(null=True, blank=True,
upload_to=lambda f, x: f.path('data.bin')) 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): def save_chunk(self, chunk, chunk_id=-1):
if not self.available: if not self.available:
if not self.video: if not self.video:
self.video.save('%s.webm'%settings.VIDEO_PROFILE, chunk) self.video.save(settings.VIDEO_PROFILE, chunk)
else: else:
f = open(self.video.path, 'a') f = open(self.video.path, 'a')
#FIXME: should check that chunk_id/offset is right #FIXME: should check that chunk_id/offset is right

View file

@ -161,8 +161,6 @@ class VideoChunkForm(forms.Form):
@login_required_json @login_required_json
def firefogg_upload(request): def firefogg_upload(request):
profile = request.GET['profile'] profile = request.GET['profile']
if profile.endswith('.webm'):
profile = os.path.splitext(profile)[0]
oshash = request.GET['oshash'] oshash = request.GET['oshash']
#handle video upload #handle video upload
if request.method == 'POST': if request.method == 'POST':

View file

@ -333,6 +333,7 @@ class Item(models.Model):
else: else:
stream['baseUrl'] = os.path.dirname(s.video.url) 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['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 return stream
def get_layers(self): def get_layers(self):
@ -588,7 +589,7 @@ class Item(models.Model):
''' '''
def frame(self, position, width=128): 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: if stream.count()>0:
stream = stream[0] stream = stream[0]
else: else:
@ -627,7 +628,7 @@ class Item(models.Model):
#FIXME: how to detect if something changed? #FIXME: how to detect if something changed?
if files: if files:
stream, created = Stream.objects.get_or_create(item=self, stream, created = Stream.objects.get_or_create(item=self,
profile='%s.webm' % settings.VIDEO_PROFILE) profile=settings.VIDEO_PROFILE)
stream.video.name = stream.path() stream.video.name = stream.path()
cmd = [] cmd = []
if os.path.exists(stream.video.path): if os.path.exists(stream.video.path):
@ -766,7 +767,7 @@ class Item(models.Model):
def get_poster_frame_path(self): def get_poster_frame_path(self):
if self.poster_frame >= 0: 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) return self.frame(self.poster_frame, size)
frames = [] frames = []
@ -919,33 +920,13 @@ class Stream(models.Model):
return self.item.path(self.profile) return self.item.path(self.profile)
def extract_derivatives(self): def extract_derivatives(self):
if settings.VIDEO_H264: for profile in settings.VIDEO_DERIVATIVES:
profile = self.profile.replace('.webm', '.mp4')
derivative, created = Stream.objects.get_or_create(profile=profile, item=self.item) derivative, created = Stream.objects.get_or_create(profile=profile, item=self.item)
if created: if created:
derivative.source = self derivative.source = self
derivative.video.name = self.video.name.replace(self.profile, profile) derivative.video.name = self.video.name.replace(self.profile, profile)
derivative.encode() derivative.encode()
derivative.save() 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 return True
def encode(self): def encode(self):

View file

@ -144,15 +144,23 @@ SITE_CONFIG = join(PROJECT_ROOT, '0xdb.json')
DEFAULT_SORT = [{"key": "director", "operator": ""}] DEFAULT_SORT = [{"key": "director", "operator": ""}]
DEFAULT_THEME = "classic" DEFAULT_THEME = "classic"
VIDEO_PROFILE = '96p' VIDEO_PROFILE = '96p.webm'
VIDEO_DERIVATIVES = [] VIDEO_DERIVATIVES = []
VIDEO_H264 = False VIDEO_H264 = False
#Pad.ma #Pad.ma
#VIDEO_PROFILE = '480p' '''
#VIDEO_DERIVATIVES = ['96p', '270p', '360p'] VIDEO_PROFILE = '480p.webm'
#VIDEO_H264 = False VIDEO_DERIVATIVES = [
'96p.webm',
'240p.webm',
'360p.webm'
'96p.mp4',
'240p.mp4',
'360p.mp4',
'480p.mp4',
]
'''
TRANSMISSON_HOST = 'localhost' TRANSMISSON_HOST = 'localhost'
TRANSMISSON_PORT = 9091 TRANSMISSON_PORT = 9091

View file

@ -10,6 +10,7 @@ jQuery.support.video = function() {
video.webm = false; video.webm = false;
video.h264 = !!(v.canPlayType && v.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"').replace(/no/, '')); 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.ogg = !!(v.canPlayType && v.canPlayType('video/ogg; codecs="theora, vorbis"').replace(/no/, ''));
video.ogv = video.ogg;
} else { } else {
video.support = false; video.support = false;
} }

View file

@ -1734,10 +1734,11 @@
}); });
} else if (app.user.ui.itemView == 'player') { } else if (app.user.ui.itemView == 'player') {
var video = result.data.item.stream, 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.height = video.profiles[0]
video.width = parseInt(video.height * video.aspectRatio / 2) * 2; 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({ app.$ui.contentPanel.replace(1, app.$ui.player = new Ox.VideoPanelPlayer({
annotationsSize: app.user.ui.annotationsSize, annotationsSize: app.user.ui.annotationsSize,
duration: video.duration, duration: video.duration,
@ -1775,10 +1776,11 @@
'in': 5, 'in': 5,
'out': 10, 'out': 10,
'value': 'This subtitle is just a test...' '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.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({ app.$ui.contentPanel.replace(1, app.$ui.editor = new Ox.VideoEditor({
annotationsSize: app.user.ui.annotationsSize, annotationsSize: app.user.ui.annotationsSize,
cuts: cuts, cuts: cuts,