简体   繁体   中英

ffmpeg-python 'OSError[2] No such file or directory' error

I recently wanted to integrate ffmpeg-python with my dockerized flask app. I installed ffmpeg through homebrew on my mac. It works when I do it manually but when it comes to my project. I cannot run ffmpeg. It throws OSError[2]: No such file or directory Here is my code in views.py :

@admin.route('/partners/upload_videos')
def partners_video_upload():

    # Uploading video using ffmpeg-python
    (ffmpeg
        .input('in.mp4')
        .output('output.mp4')
        .run()
        )


    return render_template('admin/partner/upload_videos.html')

the in.mp4 video file is in the same directory as views.py* file. I cannot seem to resolve the issue. I tried with subprocess.call() and subprocess.run() as well. Still the same error persists.

A Docker image is an isolated, standalone filesystem. And it runs Linux. You can't access executables installed via Homebrew. So you need to install ffmepg inside the image, eg RUN apt-get install -y ffmpeg in the Dockerfile if it's a Debian-based image.

I found the solution. By the default when ffmpeg is installed in a docker container and in.mp4 is specified, ffmpeg looks at the root directory of the project. So we have to specify the full path for ffmpeg to find your input video. So I did it that way and it worked nicely: Here is my code:

@admin.route('/partners/upload_videos')
def partners_video_upload():

    # Uploading video using ffmpeg-python
    (ffmpeg
        .input('.\myproject\static\videos\in.mp4')
        .output('.\myproject\static\videos\converted\output.mp4')
        .run()
        )

    return render_template('admin/partner/upload_videos.html')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM