docker 与 ffmpeg

创建容器
docker run -it -v /mnt/f/ffmpeg:/mnt/f/ffmpeg --name ffmpeg 49a981f2b85f /bin/bash

在 Linux 上编译 FFmpeg:
安装依赖库:

bash 复制代码
sudo apt-get update
sudo apt-get install build-essential yasm cmake libtool libc6 libc6-dev unzip wget

下载 FFmpeg 源代码:

bash 复制代码
git clone https://github.com/FFmpeg/FFmpeg.git
cd FFmpeg

#查看远程分支
git branch -r
#切换分支
git checkout -b  origin/release/5.1  origin/release/5.1

配置和编译:

bash 复制代码
./configure --enable-shared
make -j20  # 使用多个核心进行编译,可以根据你的 CPU 核心数进行调整
sudo make install

上述命令假设你在 FFmpeg 源代码目录下执行。--enable-shared 表示编译生成共享库。

WARNING: pkg-config not found, library detection may fail.

bash 复制代码
sudo apt-get update
sudo apt-get install pkg-config

No rule to make target 'libavcodec/x86/lpc.asm', needed by 'libavcodec/x86/lpc.o'. Stop

bash 复制代码
sudo apt-get update
sudo apt-get install yasm

安装路径

bash 复制代码
root@cec0f3db763d:~# whereis ffmpeg
ffmpeg: /usr/local/bin/ffmpeg

配置环境
sudo gedit /etc/ld.so.conf

加入一行

安装成功

bash 复制代码
root@cec0f3db763d:~# ffmpeg
ffmpeg version n5.1.4-1-gae14d9c06b Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.2)
  configuration: --enable-shared
  libavutil      57. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  libavdevice    59.  7.100 / 59.  7.100
  libavfilter     8. 44.100 /  8. 44.100
  libswscale      6.  7.100 /  6.  7.100
  libswresample   4.  7.100 /  4. 13.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

切换到挂载目录
cd /mnt/f/ffmpeg/

查询视频信息
ffprobe IVR_20231214_172440.mp4

bash 复制代码
root@cec0f3db763d:/mnt/f/ffmpeg# ffprobe IVR_20231214_170605.mp4    
ffprobe version n5.1.4-1-gae14d9c06b Copyright (c) 2007-2023 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.2)
  configuration: --enable-shared
  libavutil      57. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  libavdevice    59.  7.100 / 59.  7.100
  libavfilter     8. 44.100 /  8. 44.100
  libswscale      6.  7.100 /  6.  7.100
  libswresample   4.  7.100 /  4. 13.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'IVR_20231214_170605.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 00:00:10.40, start: 0.000000, bitrate: 3459 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt470bg/bt470bg/bt709, progressive), 1024x768, 3455 kb/s, 42.22 fps, 50 tbr, 90k tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]

提取所有帧
ffmpeg -i VID_20231214_091908.mp4 -vf "select=1" -vsync vfr frame/%04d.jpg
ffmpeg -i VID_20231214_091908.mp4 -vf "select=gt(scene\,0.1)" -vsync vfr frame/%04d.jpg

  • 使用了 select 过滤器,该过滤器根据场景的变化选择帧。gt(scene,0.5) 表示选择那些场景变化比 0.5 大的帧。
    捕捉到视频中场景变化较大的帧。
  • -vsync vfr 选项指定使用可变帧率,因为我们选择了帧,而不是按照常规的固定帧率。
  • -vsync 选项为 cfr(恒定帧率)
  • frames/%04d.jpg 指定输出的帧图像保存在 frames 目录下,文件名为四位数字格式。

视频转换
ffmpeg -i IVR_20231222_144442.mp4 -c:v libx264 -c:a aac output_video.mp4

  • -c:v libx264: 指定视频编码器为 libx264(H.264)。
  • -preset medium: 使用中等质量的预设,你可以根据需要调整。
  • -crf 23: 控制视频质量,数值越小,质量越高,18-28 之间是常用的范围。
  • -c:a aac -b:a 192k: 指定音频编码器为 AAC,音频比特率为 192kbps。

sudo apt install libx264-dev

检查是否支持
ffmpeg -codecs | grep libx264

安装h264
sudo apt-get install libx264-dev

下载源码
git clone https://code.videolan.org/videolan/x264.git
cd x264

编译和安装 libx264

bash 复制代码
./configure --enable-shared
make
sudo make install

asm错误

bash 复制代码
root@cec0f3db763d:/x264# ./configure --enable-shared
Found no assembler
Minimum version is nasm-2.13
If you really want to compile without asm, configure with --disable-asm.

安装 NASM: 按照错误消息的建议,安装 nasm

bash 复制代码
sudo apt-get install nasm

h264编译成功

bash 复制代码
root@cec0f3db763d:/x264# ./configure --enable-shared
platform:       X86_64
byte order:     little-endian
system:         LINUX
cli:            yes
libx264:        internal
shared:         yes
static:         no
bashcompletion: no
asm:            yes
interlaced:     yes
avs:            yes
lavf:           yes
ffms:           no
mp4:            no
gpl:            yes
thread:         posix
opencl:         yes
filters:        resize crop select_every
lto:            no
debug:          no
gprof:          no
strip:          no
PIC:            yes
bit depth:      all
chroma format:  all

重新编译 ffmpeg

bash 复制代码
#git clone https://github.com/FFmpeg/FFmpeg.git
#cd FFmpeg
./configure --enable-libx264
make
sudo make install

错误

这个错误表明在尝试编译 ffmpeg 时,缺少对 GPL 许可证的支持。libx264 是一个使用 GPL 许可证的视频编码库

bash 复制代码
ibx264 is gpl and --enable-gpl is not specified.

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.libera.chat.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.

解决
./configure --enable-gpl
./configure --enable-shared --enable-gpl --enable-libx264
sudo ldconfig

相关推荐
m0_741768854 小时前
使用docker的小例子
运维·docker·容器
最新小梦7 小时前
Docker日志管理
运维·docker·容器
ZHOU西口8 小时前
微服务实战系列之玩转Docker(十五)
nginx·docker·微服务·云原生·swarm·docker swarm·dockerui
lgbisha9 小时前
828华为云征文|华为云Flexus X实例docker部署最新Appsmith社区版,搭建自己的低代码平台
低代码·docker·华为云
记得开心一点嘛9 小时前
在Linux系统上使用Docker部署javaweb项目
linux·运维·docker
superconvert9 小时前
主流流媒体的综合性能大 PK ( smart_rtmpd, srs, zlm, nginx rtmp )
websocket·ffmpeg·webrtc·hevc·rtmp·h264·hls·dash·rtsp·srt·flv
Persistence is gold11 小时前
cassandra指定配置文件的docker启动方法
运维·docker·容器
C语言扫地僧12 小时前
Docker 镜像制作(Dockerfile)
linux·服务器·docker·容器
ken_coding15 小时前
Windows11 WSL2的ubuntu 22.04中拉取镜像报错
linux·ubuntu·docker
cuijiecheng201815 小时前
音视频入门基础:AAC专题(8)——FFmpeg源码中计算AAC裸流AVStream的time_base的实现
ffmpeg·音视频·aac