django - Passing python's file like object to ffmpeg via subprocess -


i have django filefield, use store wav files on amazon s3 server. have set celery task read file , convert mp3 , store filefield. problem facing unable pass input file ffmpeg file not physical file on hard disk drive. circumvent that, used stdin feed input stream of file django's filefield. here example:

output_file = namedtemporaryfile(suffix='.mp3') subprocess.call(['ffmpeg', '-y', '-i', '-', output_file.name], stdin=recording_wav) 

where recording_wav file is: , stored on amazon s3 server. error above subprocess call is:

attributeerror: 'cstringio.stringo' object has no attribute 'fileno' 

how can this? in advance help.

edit:

full traceback:

[2012-07-03 04:09:50,336: error/mainprocess] task api.tasks.convert_audio[b7ab4192-2bff-4ea4-9421-b664c8d6ae2e] raised exception: attributeerror("'cstringio.stringo' object has no attribute 'fileno'",) traceback (most recent call last):   file "/home/tejinder/envs/tmai/local/lib/python2.7/site-packages/celery/execute/trace.py", line 181, in trace_task     r = retval = fun(*args, **kwargs)   file "/home/tejinder/projects/tmai/../tmai/apps/api/tasks.py", line 56, in convert_audio     subprocess.popen(['ffmpeg', '-y', '-i', '-', output_file.name], stdin=recording_wav)   file "/usr/lib/python2.7/subprocess.py", line 672, in __init__     errread, errwrite) = self._get_handles(stdin, stdout, stderr)   file "/usr/lib/python2.7/subprocess.py", line 1043, in _get_handles     p2cread = stdin.fileno()   file "/home/tejinder/envs/tmai/local/lib/python2.7/site-packages/django/core/files/utils.py", line 12, in <lambda>     fileno = property(lambda self: self.file.fileno)   file "/home/tejinder/envs/tmai/local/lib/python2.7/site-packages/django/core/files/utils.py", line 12, in <lambda>     fileno = property(lambda self: self.file.fileno) attributeerror: 'cstringio.stringo' object has no attribute 'fileno' 

use subprocess.popen.communicate pass input subprocess:

command = ['ffmpeg', '-y', '-i', '-', output_file.name] process = subprocess.popen(command, stdin=subprocess.pipe) process.communicate(recording_wav) 

for fun, use ffmpeg's output avoid namedtemporaryfile:

command = ['ffmpeg', '-y', '-i', '-', '-f', 'mp3', '-'] process = subprocess.popen(command, stdin=subprocess.pipe) recording_mp3, errordata = process.communicate(recording_wav) 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -