Issue
I am writing a Flask application and using a celery task for a long-running task. Basically, that long-running task uses the ffmpeg-python module to process a video. The code is working fine when I run it normally via flask API but when I am trying to execute that task via celery worker it does not recognize FFmpeg. Please help
@celery.task(bind=True)
def process_upload(self, file_name):
self.update_state(state='PROGRESS',
meta={'current': 1, 'total': 4,
'status': "extracting audio"})
get_audio(file_name=file_name)
return {'current': -1, 'total': 4, 'status': 'Task completed!'}
@app.route('/process_upload', methods=['POST'])
def processupload():
task = process_upload.apply_async(args=['output1'])
return jsonify({'task_id': task.id}), 202,
def get_audio(file_name):
from os.path import exists
import ffmpeg
try:
if not exists(file_name + '.mp3'):
video = ffmpeg.input(file_name + '.mp4')
output = ffmpeg.output(video.audio, f'{file_name}.mp3')
ffmpeg.run(output)
return True
except Exception as e:
raise e
Solution
Basically, after going through FFmpeg support material I got to know that FFmpeg-python needs FFmpeg installed on the machine with the proper setting of env variable which solved the issue.
command to install FFmpeg on Ubuntu,
sudo apt install ffmpeg
Answered By - Adil Rao
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.