Giter Club home page Giter Club logo

Comments (10)

adampl avatar adampl commented on May 30, 2024 16

This is how I managed to have both Python 3.6 and FFmpeg in one image:

FROM jrottenberg/ffmpeg:4.0-scratch AS ffmpeg
FROM python:3.6
COPY --from=ffmpeg / /

from ffmpeg.

chriswiggins avatar chriswiggins commented on May 30, 2024 9

To add to this, we're using the following in our production Dockerfiles:

ENV LD_LIBRARY_PATH=/usr/local/lib
COPY --from=jrottenberg/ffmpeg /usr/local /usr/local/

Works well 👍

from ffmpeg.

Bobronium avatar Bobronium commented on May 30, 2024 7

This is how I got it to work. Leaving it here since this is the only result I found when googling for multistage builds with ffmpeg.

Complete Dockerfile

Resulted Docker file will also work on arm arch, e.g. on Raspberry Pi or Apple Silicon, considering base image supports it.

FROM debian:buster-slim as base  # replace with your actual base image, e.g. `python-slim`

FROM base as base-installer
RUN apt update

FROM base-installer as ffmpeg-installer
RUN apt install --no-install-recommends -y ffmpeg

FROM base as runtime
COPY --from=ffmpeg-installer /usr/bin/ffmpeg /usr/bin/ffmpeg
COPY --from=ffmpeg-installer /usr/lib/*-linux-gnu/* /usr/lib/
COPY --from=ffmpeg-installer /lib/*-linux-gnu/* /usr/lib/

How to get ffmpeg for any image

  1. Define stage where you have working ffmpeg (in this example I install it with apt, but you can use ffmpeg as base image):
    FROM debian:buster-slim as base  # replace with your actual base image, e.g. `python-slim`
    
    FROM base as base-installer
    RUN apt update
    
    FROM base-installer as ffmpeg-installer
    RUN apt install --no-install-recommends -y ffmpeg
  2. Verify that at this stage ffmpeg is indeed working:
    docker build --target ffmpeg-installer . -t ffmpeg
    docker run -it ffmpeg ffmpeg
  3. Get path where ffmpeg is installed:
    docker run -it ffmpeg which ffmpeg
    # /usr/bin/ffmpeg
  4. Add ffmpeg binary to your runtime stage:
    FROM base as runtime
    COPY --from=ffmpeg-installer /usr/bin/ffmpeg /usr/bin/ffmpeg
  5. Run ffmpeg from your runtime target and observe the error (or success!):
    docker build --target runtime -t runtime .
    docker run -it runtime ffmpeg
    # ffmpeg: error while loading shared libraries: libavdevice.so.58: cannot open shared object file: No such file or directory
  6. Find location of shared library in ffmpeg-installer target:
    docker run -it ffmpeg find / -name libavdevice.so.58      
    # /usr/lib/aarch64-linux-gnu/libavdevice.so.58
  7. Copy the lib location to your runtime stage (note * instead of arch name, this will work with multiarch builds):
    FROM base as runtime
    COPY --from=ffmpeg-installer /usr/bin/ffmpeg /usr/bin/ffmpeg
    COPY --from=builder-base /usr/lib/*-linux-gnu/* /usr/lib/
  8. Return to 5. untill you don't observe errors anymore (took 1 repeat for me).

from ffmpeg.

jrottenberg avatar jrottenberg commented on May 30, 2024 5

it exists now : https://github.com/videotools/ffmpeg-build

from ffmpeg.

GZaccaroni avatar GZaccaroni commented on May 30, 2024 1

To add to this, we're using the following in our production Dockerfiles:

ENV LD_LIBRARY_PATH=/usr/local/lib
COPY --from=jrottenberg/ffmpeg /usr/local /usr/local/

Works well 👍

With ubuntu20.04 and ffmpeg 20.04-ubuntu it is no longer working. I get the following error:

ffmpeg: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory

It is working with:

ENV LD_LIBRARY_PATH=/usr/local/lib
COPY --from=jrottenberg/ffmpeg / /

from ffmpeg.

washcroft avatar washcroft commented on May 30, 2024 1

Copying the entire image into your destination can sometimes cause problems, this also works:

ENV LD_LIBRARY_PATH=/usr/local/lib
COPY --from=ffmpeg /usr/local /usr/local
COPY --from=ffmpeg /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu

from ffmpeg.

Oliboy50 avatar Oliboy50 commented on May 30, 2024

I also experienced issues with this... I hoped it would work as expected

from ffmpeg.

vagari avatar vagari commented on May 30, 2024

I could have sworn I found a more straightforward method, but a while back I had some success with using LD_LIBRARY_PATH to copy over all the files to the new container and link them back up. I'll try to dig up the references when I have some time, but maybe this pointer will be enough to get you started down the right path...

from ffmpeg.

Oliboy50 avatar Oliboy50 commented on May 30, 2024

I tested every available distrib for 4.0 and 3.4... but I didn't managed to get the binary working in the final image

  • using ubuntu based image I had the same OP error message

  • using others based image (including scratch), my binary didn't want to execute at all (something like ffmpeg command was not found) even after chmod a+rx the binary, etc.

I didn't try @vagari solution thought

what I did after losing a lot of time was simply installing ffmpeg in my final image 😞:

FROM node:8.11.2-stretch

RUN apt-get update && apt-get install -y libav-tools ffmpeg

from ffmpeg.

leandromoreira avatar leandromoreira commented on May 30, 2024

I think it'd be nice to have intermediate images for development, I shameless did (copy & change) an ffmpeg-devel image and I already posted to dockerhub.

With this image you can create, test, compile and run your ffmpeg programs:

clean:
	@rm -rf ./build/*

make_hello: clean
	docker run --rm -it -v `pwd`:/files leandromoreira/ffmpeg-devel \
	  gcc -L/opt/ffmpeg/lib -I/opt/ffmpeg/include/ /files/MYCODE.c \
	  -lavcodec -lavformat -lavfilter -lavdevice -lswresample -lswscale -lavutil \
	  -o /files/build/MYPROGRAM

run_hello: make_hello
	docker run --rm -it -v `pwd`:/files leandromoreira/ffmpeg-devel /files/build/MYPROGRAM /files/small_bunny_1080p_60fps.mp4

from ffmpeg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.