reload stream from db before updating after encode, fixes #2442

This commit is contained in:
j 2014-07-29 17:43:38 +02:00
parent a520b7edaf
commit cfa7628551

View file

@ -624,7 +624,10 @@ class Stream(models.Model):
return stream return stream
def path(self, name=''): def path(self, name=''):
return self.file.get_path(name) if self.source:
return os.path.join(os.path.dirname(self.source.media.name), name)
else:
return self.file.get_path(name)
def extract_derivatives(self, rebuild=False): def extract_derivatives(self, rebuild=False):
config = settings.CONFIG['video'] config = settings.CONFIG['video']
@ -649,49 +652,38 @@ class Stream(models.Model):
return True return True
def encode(self): def encode(self):
if self.source: media = self.source.media.path if self.source else self.file.data
media = self.source.media.path ffmpeg = ox.file.cmd('ffmpeg')
if not self.media: if self.source or ffmpeg == 'ffmpeg':
self.media.name = os.path.join(os.path.dirname(self.source.media.name), self.name()) ffmpeg = None
target = self.media.path
info = ox.avinfo(media) if not self.media:
ok, error = extract.stream(media, target, self.name(), info) self.media.name = self.path(self.name())
if ok: target = self.media.path
self.available = True
self.error = '' info = ox.avinfo(media)
if self.file.failed: ok, error = extract.stream(media, target, self.name(), info, ffmpeg)
self.file.failed = False # file could have been moved while encoding
self.file.save() # get current version from db and update
else: _self = Stream.objects.get(id=self.id)
self.media = None _self.update_status(ok, error)
self.available = False
self.error = error def update_status(self, ok, error):
self.file.failed = True if ok:
self.file.save()
self.save()
elif self.file.data:
media = self.file.data.path
if not self.media: if not self.media:
self.media.name = self.path(self.name()) self.media.name = self.path(self.name())
target = self.media.path self.available = True
info = ox.avinfo(media) self.error = ''
ffmpeg = ox.file.cmd('ffmpeg') if self.file.failed:
if ffmpeg == 'ffmpeg': self.file.failed = False
ffmpeg = None
ok, error = extract.stream(media, target, self.name(), info, ffmpeg)
if ok:
self.available = True
self.error = ''
if self.file.failed:
self.file.failed = False
self.file.save()
else:
self.media = None
self.available = False
self.error = error
self.file.failed = True
self.file.save() self.file.save()
self.save() else:
self.media = None
self.available = False
self.error = error
self.file.failed = True
self.file.save()
self.save()
def make_timeline(self): def make_timeline(self):
if self.available and not self.source: if self.available and not self.source: