0

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

Celery Error Attached

Adil Rao
  • 1
  • 1
  • Welcome to Stack Overflow. [Please do not upload images of errors when asking a question.](//meta.stackoverflow.com/q/285551) Instead, copy and paste the text, formatted like multi-line code. We [will not transcribe](https://meta.stackoverflow.com/questions/415040) them for you. – Karl Knechtel Sep 15 '22 at 12:21

2 Answers2

0

It looks like you're not running the Celery tasks in the same Python environment than the Flask app. Could you double check if your Flask app is running using /home/adil/.local/lib/python3.10 as python interpreter?

  • I was running Falsk app in venv on my windows machine and celery was running on windows WSL. I tried running both on windows WSL and got the same error. – Adil Rao Sep 15 '22 at 11:51
  • I just check by running the function directly via the flask app and it is also giving the same "FFmpeg not found error" but then I am installing FFmpeg-python via pip it says the requirement is already satisfied. – Adil Rao Sep 15 '22 at 11:55
0

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

Adil Rao
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 20 '22 at 05:59