Docker version of FFmpeg installation and deployment

background

During the development process, the project team wanted to use the audio format conversion function. After consulting relevant information, they finally chose to use FFmpeg .


Introduction to FFmpeg

Official website: https://ffmpeg.org

FFmpeg is an open source, cross-platform multimedia solution that can be used to record, convert and stream audio and video. Supports Linux, Windows and macOS operating systems.

As a powerful multimedia toolset, FFmpeg provides a wide range of functions and tools to enable developers to perform various audio and video processing tasks, such as:

  • Format conversion : With FFmpeg, you can convert audio and video from one format to another. It supports numerous audio and video codecs and can handle almost all common audio and video formats.

  • Video clipping and cropping : You can use FFmpeg to crop videos, extract the required segments, and also adjust parameters such as size, resolution, and frame rate of the video.

  • Audio processing : FFmpeg can perform various processing on audio files, including audio merging, segmentation, mixing, volume adjustment, noise reduction, etc.

  • Video processing : In addition to transcoding and editing, FFmpeg also supports video filters and special effects, such as adding watermarks, rotation, scaling, color adjustment, etc.

  • Video streaming : Using FFmpeg, you can live stream audio and video to the network for network playback, live broadcast, or other real-time applications.

FFmpeg provides command line tools and can also be integrated through C/C++ libraries. In addition, there are many third-party tools and frameworks based on FFmpeg available, making audio and video processing easier and more convenient.


Regarding the installation of ffmpeg, some people may have to struggle for a long time, or even a week. The reason is basically caused by compilation and installation.

Among the members of the project development team, some use Windows, Ubuntu, macOS and other systems for development, and the testing and production environments may be CentOS, Fedora, Ubuntu, Windows and other systems. Considering that other members may take over the project in the future, if everyone takes the time to install FFmpeg, I don’t know how long it will take because of the differences in environment. In order to improve productivity (reduce costs and increase efficiency), I decided to use docker to install ffmpeg.

1. Search for images

Prerequisite : Docker has been installed

Use docker search --no-trunc ffmpegthe command to search for ffmpeg and view the full image description

(base) mjl@ubuntu:~$ docker search --no-trunc ffmpeg
NAME                                      DESCRIPTION                                                                                    STARS     OFFICIAL   AUTOMATED
jrottenberg/ffmpeg                        FFmpeg 2.8 - 3.x - 4.x Copyright (c) 2000-2017 the FFmpeg developers                           419                  [OK]
linuxserver/ffmpeg                                                                                                                       106                  
opencoconut/ffmpeg                        Minimal FFmpeg Docker image built on Alpine Linux                                              30                   [OK]
nachochip/ffmpeg                          ffmpeg (x264, fdk-aac) inside debian                                                           14                   [OK]
nightseas/ffmpeg                          FFmpeg with CUDA encoder/decoder support.                                                      8                    [OK]
selenium/video                            Image with ffmpeg meant to be used with a Dynamic Grid                                         7                    
alfg/ffmpeg                               An FFmpeg Dockerfile from source. Built on Alpine Linux.                                       6                    [OK]
jellyfin/ffmpeg                                                                                                                          4                    
datarhei/ffmpeg                           FFmpeg Development Image for H.264-Processing                                                  4                    
rafalkrypa/ffmpeg                         Latest FFmpeg static build on minimal Alpine Linux container                                   3                    
sjourdan/ffmpeg                           FFmpeg on Alpine Docker Image                                                                  3                    [OK]
ffmpeg/coverity                           Environment for automated coverity testing of FFmpeg.                                          2                    [OK]
mycujoo/ffmpeg-docker                     ffmpeg docker container                                                                        0                    [OK]
krickwix/ffmpeg                                                                                                                          0                    
nicholasrobinson/ffmpeg-homebridge        A Homebridge Dockerfile built on oznu/docker-homebridge with FFmpeg copied from alfg/ffmpeg.   0                    
azamserver/nextcloud-imagemagick-ffmpeg   A Nextcloud docker image with ImageMagick & FFmpeg preinstalled                                0                    
jamesarems/ffmpeg                         CentOS 8 based ffmpeg server                                                                   0                    
onlinetvrecorder/ffmpeg                                                                                                                  0                    
vulhub/ffmpeg                                                                                                                            0                    
ffmpegextrah/ffmpeg                                                                                                                      0                    
ffmpegclearu/ffmpeg                                                                                                                      0                    
thinkz/ffmpeg                             ffmpeg with librtmp                                                                            0                    
umnelevator/ffmpeg                                                                                                                       0                    
nicolasarnaud4viseo/ffmpeg                                                                                                               0                    
chpkg/ffmpeg-to-s3                                                                               0         

2. Pull the image

From the search results above, we can see that jrottenberg/ffmpeg has the most stars in the first line, so we decided to use it.

Use docker pull jrottenberg/ffmpegthe command to pull the image (change to a faster image source in advance, otherwise just wait patiently):

(base) mjl@ubuntu:~$ docker pull jrottenberg/ffmpeg
Using default tag: latest
latest: Pulling from jrottenberg/ffmpeg
7b722c1070cd: Pull complete 
5fbf74db61f1: Pull complete 
ed41cb72e5c9: Pull complete 
7ea47a67709e: Pull complete 
c56548ea744b: Pull complete 
24130a6ef4f3: Pull complete 
2d757c4d9a11: Pull complete 
Digest: sha256:21eb739725c43bd7187982e5fa4b5371b495d1d1f6f61ae1719ca794817f8641
Status: Downloaded newer image for jrottenberg/ffmpeg:latest
docker.io/jrottenberg/ffmpeg:latest

3. Export image

After the pull is completed, use to docker image lslist the locally downloaded images. We see that there is an jrottenberg/ffmpegimage with a size of 218MB.

(base) mjl@ubuntu:~$ docker image ls
REPOSITORY                                  TAG          IMAGE ID       CREATED         SIZE
jrottenberg/ffmpeg                          latest       2100506dfbea   4 years ago     218MB

We need to export this image into a tar package. It can be exported using the following command:

(base) mjl@ubuntu:~$ docker save -o ffmpeg.tar jrottenberg/ffmpeg:latest

Export as ffmpeg.tarfile:

(base) mjl@ubuntu:~$ ll
-rw-------   1 mjl mjl 222621696  5月  3 22:27 ffmpeg.tar

The exported tar package can be transferred to an offline server via scp or ftp.

4. Load the image

In the server, use to docker image lslist the locally downloaded images. You can see that there is only one hello-wordimage on the server (as shown below).

(base) [root@10-23-2-211 ~]# docker image ls
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
hello-world   latest    bf756fb1ae65   3 years ago   13.3kB

Next, docker load -i ffmpeg.tarimport the tar package into Docker using:

(base) [root@10-23-2-211 ~]# docker load -i ffmpeg.tar 
0de2edf7bff4: Loading layer [==================================================>]  121.3MB/121.3MB
b2fd8b4c3da7: Loading layer [==================================================>]  15.87kB/15.87kB
f67191ae09b8: Loading layer [==================================================>]  11.78kB/11.78kB
68dda0c9a8cd: Loading layer [==================================================>]  3.072kB/3.072kB
1c86e8f0fce5: Loading layer [==================================================>]  2.048kB/2.048kB
e38e18db08fb: Loading layer [==================================================>]  31.93MB/31.93MB
b0e2549b869a: Loading layer [==================================================>]  69.36MB/69.36MB
Loaded image: jrottenberg/ffmpeg:latest

After the import is completed, we continue to use docker image lsthe command to check whether the import was successful:

(base) [root@10-23-2-211 ~]# docker image ls
REPOSITORY           TAG       IMAGE ID       CREATED       SIZE
hello-world          latest    bf756fb1ae65   3 years ago   13.3kB
jrottenberg/ffmpeg   latest    2100506dfbea   4 years ago   218MB

From the above output results, we can see that there is an additional jrottenberg/ffmpegimage with a size of 218MB, indicating that the import was successful.

5. Start the container

docker psView running containers using :

(base) [root@10-23-2-211 ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

Start the container:

(base) [root@10-23-2-211 ~]# docker run -itd --name app_ffmpeg -p 8066:8080 -v /home/mjl/ffmpeg/:/mnt/app/ --entrypoint='bash' jrottenberg/ffmpeg
2cd7573a3c44da0ccfacd1e46cb40a523dfaf99dc0e298db3053f473a0ecd11e

Use again docker psto view running containers:

(base) [root@10-23-2-211 ~]# docker ps
CONTAINER ID   IMAGE                COMMAND   CREATED         STATUS         PORTS                    NAMES
2cd7573a3c44   jrottenberg/ffmpeg   "bash"    4 seconds ago   Up 3 seconds   0.0.0.0:8066->8080/tcp   app_ffmpeg

The container is now started.

Guess you like

Origin blog.csdn.net/mjl3861770/article/details/132111510