Commit 2e7b49fb authored by Gabriel Monnerat's avatar Gabriel Monnerat

refactor code to don't create two File objects

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@43640 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 70914e3e
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
from cloudooo.file import File from cloudooo.file import File
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from tempfile import mktemp
class FFMPEGHandler(object): class FFMPEGHandler(object):
...@@ -51,20 +52,20 @@ class FFMPEGHandler(object): ...@@ -51,20 +52,20 @@ class FFMPEGHandler(object):
# XXX This implementation could use ffmpeg -i pipe:0, but # XXX This implementation could use ffmpeg -i pipe:0, but
# XXX seems super unreliable currently and it generates currupted files in # XXX seems super unreliable currently and it generates currupted files in
# the end # the end
output = File(self.base_folder_url, '', destination_format) output_url = mktemp(suffix=".%s" % destination_format,
dir=self.input.directory_name)
command = ["ffmpeg",
"-i",
self.input.getUrl(),
"-y",
output_url]
try: try:
command = ["ffmpeg",
"-i",
self.input.getUrl(),
"-y",
output.getUrl()]
stdout, stderr = Popen(command, stdout, stderr = Popen(command,
stdout=PIPE, stdout=PIPE,
stderr=PIPE, stderr=PIPE,
close_fds=True, close_fds=True,
env=self.environment).communicate() env=self.environment).communicate()
output.reload() self.input.reload(output_url)
return output.getContent() return self.input.getContent()
finally: finally:
self.input.trash() self.input.trash()
output.trash()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment