当前位置 : 首页 » 文章分类 :  开发  »  FFmpeg

FFmpeg

FFmpeg 使用笔记
https://www.ffmpeg.org/


Intel/M1 Mac Brew 安装 FFmpeg

brew install ffmpeg 安装 FFmpeg
Intel Mac 安装目录 /usr/local/Cellar/ffmpeg/4.4_2
M1 Mac 安装目录 /opt/homebrew/Cellar/ffmpeg/5.0.1_3


h.264 编码

支持H.264的封装格式有很多,如FLV ,MP4 , HLS(M3U8),MKV ,TS等格式
FFMpeg 本身并不支持 H.264 的编码器,而是由 FFMpeg 的第三方模块对其进行支持,例如 x264 和 OpenH264,二者各有各的优势。由于 OpenH264 开源比较晚,所以 x264 还是当前最常用的编码器,


ffmpeg

ffmpeg Documentation
https://ffmpeg.org/ffmpeg.html

语法 ffmpeg [global_options] {[input_file_options] -i input_url} ... {[output_file_options] output_url} ...

选项:
-hide_banner 全部 ffmpeg 命令默认都会打印版本、选项、库信息,命令中增加此选项可隐藏版本等信息。
-i url (input) 指定输入文件的 url,可以是媒体文件或视频流地址
-vcodec codec (output) 指定视频编解码器,等于 -codec:v

ffmpeg -i file/url 查看媒体文件/流基本信息

ffmpeg -i file/urlffprobe file/url 的结果完全相同,可用于查看媒体文件/流的基本信息

ffmpeg -i  drone01.mp4 -hide_banner
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'drone01.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.29.100
  Duration: 00:05:09.72, start: 0.000000, bitrate: 3093 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080, 3090 kb/s, 25 fps, 25 tbr, 12800 tbn (default)
    Metadata:
      handler_name    : VideoHandler
      vendor_id       : [0][0][0][0]
At least one output file must be specified

ffmpeg -version 查看版本

ffmpeg version 5.0

# ffmpeg -version
ffmpeg version 5.0 Copyright (c) 2000-2022 the FFmpeg developers
built with Apple clang version 13.0.0 (clang-1300.0.29.30)
configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/5.0 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-neon
libavutil      57. 17.100 / 57. 17.100
libavcodec     59. 18.100 / 59. 18.100
libavformat    59. 16.100 / 59. 16.100
libavdevice    59.  4.100 / 59.  4.100
libavfilter     8. 24.100 /  8. 24.100
libswscale      6.  4.100 /  6.  4.100
libswresample   4.  3.100 /  4.  3.100
libpostproc    56.  3.100 / 56.  3.100

ffmpeg version 4.4

# ffmpeg -version
ffmpeg version 4.4 Copyright (c) 2000-2021 the FFmpeg developers
built with Apple clang version 11.0.0 (clang-1100.0.33.17)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.4_2 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-avresample --enable-videotoolbox
libavutil      56. 70.100 / 56. 70.100
libavcodec     58.134.100 / 58.134.100
libavformat    58. 76.100 / 58. 76.100
libavdevice    58. 13.100 / 58. 13.100
libavfilter     7.110.100 /  7.110.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  9.100 /  5.  9.100
libswresample   3.  9.100 /  3.  9.100
libpostproc    55.  9.100 / 55.  9.100

ffmpeg version 4.2

# ffmpeg -version
ffmpeg version 4.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-44)
configuration: --prefix=/usr/local/ffmpeg
libavutil      56. 31.100 / 56. 31.100
libavcodec     58. 54.100 / 58. 54.100
libavformat    58. 29.100 / 58. 29.100
libavdevice    58.  8.100 / 58.  8.100
libavfilter     7. 57.100 /  7. 57.100
libswscale      5.  5.100 /  5.  5.100
libswresample   3.  5.100 /  3.  5.100

ffmpeg version 2.4.4

# ffmpeg -v
ffmpeg version 2.4.4 Copyright (c) 2000-2014 the FFmpeg developers
  built on Dec 20 2014 17:17:15 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
  configuration: --prefix=/home/langsim/work/ffmpegbuild-fdkaac/source/../dist --extra-ldflags=-L/home/langsim/work/ffmpegbuild-fdkaac/source/../dist/lib --extra-cflags=-I/home/langsim/work/ffmpegbuild-fdkaac/source/../dist/include --disable-debug --enable-static --enable-memalign-hack --enable-version3 --enable-gpl --enable-nonfree --enable-postproc --enable-libfaac --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-libx264 --enable-libfdk-aac --disable-doc --disable-bzlib --disable-zlib

ffmpeg -codecs 查看支持的编解码格式

# ffmpeg -codecs 
ffmpeg version 4.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-44)
  configuration: --prefix=/usr/local/ffmpeg
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
Codecs:
 D..... = Decoding supported
 .E.... = Encoding supported
 ..V... = Video codec
 ..A... = Audio codec
 ..S... = Subtitle codec
 ...I.. = Intra frame-only codec
 ....L. = Lossy compression
 .....S = Lossless compression
 ------
  D.V.LS h264                 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
  D.V.L. hevc                 H.265 / HEVC (High Efficiency Video Coding)
  D.A.L. mp3                  MP3 (MPEG audio layer 3) (decoders: mp3float mp3 ) 
  DEV.L. flv1                 FLV / Sorenson Spark / Sorenson H.263 (Flash Video) (decoders: flv ) (encoders: flv )
  ...

ffprobe

ffprobe Documentation
https://ffmpeg.org/ffprobe.html

语法 ffprobe [options] input_url

选项:
-hide_banner 全部 ffmpeg 命令默认都会打印版本、选项、库信息,命令中增加此选项可隐藏版本等信息。
-show_format 显示输入媒体的封装容器格式,封装格式信息都会位于 FORMAT 块中。

ffprobe file/url 查看媒体文件/流的基本信息

ffprobe file/url 可查看音视频文件/视频流的分辨率、码率、编码格式等信息

例1、查看视频文件的基本信息

ffprobe xx-video.mov
ffprobe version 5.0 Copyright (c) 2007-2022 the FFmpeg developers
  built with Apple clang version 13.0.0 (clang-1300.0.29.30)
  configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/5.0 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-neon
  libavutil      57. 17.100 / 57. 17.100
  libavcodec     59. 18.100 / 59. 18.100
  libavformat    59. 16.100 / 59. 16.100
  libavdevice    59.  4.100 / 59.  4.100
  libavfilter     8. 24.100 /  8. 24.100
  libswscale      6.  4.100 /  6.  4.100
  libswresample   4.  3.100 /  4.  3.100
  libpostproc    56.  3.100 / 56.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/masi/文件/00-产品模块/81-算子接入/算子接入演示录屏.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 0
    compatible_brands: qt
    creation_time   : 2021-12-29T07:34:58.000000Z
    com.apple.quicktime.make: Apple
    com.apple.quicktime.model: MacBookPro14,1
    com.apple.quicktime.software: Mac OS X 10.14.6 (18G103)
    com.apple.quicktime.creationdate: 2021-12-29T15:02:28+0800
  Duration: 00:31:00.98, start: 0.000000, bitrate: 3053 kb/s
  Stream #0:0[0x1](und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 2721 kb/s, 59.54 fps, 60 tbr, 6k tbn (default)
    Metadata:
      creation_time   : 2021-12-29T07:34:58.000000Z
      handler_name    : Core Media Video
      vendor_id       : [0][0][0][0]
      encoder         : H.264
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 324 kb/s (default)
    Metadata:
      creation_time   : 2021-12-29T07:34:58.000000Z
      handler_name    : Core Media Audio
      vendor_id       : [0][0][0][0]

例2、可正常打开的视频流能看到媒体信息

# ffprobe -hide_banner rtmp://127.0.0.1:8935/live/mytestvideo
Input #0, flv, from 'rtmp://127.0.0.1:8935/live/mytestvideo':
  Metadata:
    |RtmpSampleAccess: true
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.19.104
    server          : ILSC/1.0.0(CODE)
    srs_primary     : ILSC/1.0release
    srs_authors     : winlin,wenjie.zhao,hankun
    server_version  : 1.0.0
  Duration: N/A, start: 0.000000, bitrate: 2460 kb/s
  Stream #0:0: Data: none
  Stream #0:1: Video: h264 (High), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 2460 kb/s, 25 fps, 25 tbr, 1k tbn
Unsupported codec with id 0 for input stream 0

ffprobe 可用于测试视频流是否可打开

例3、ffprobe 可用于测试视频流是否可打开,正常打开可看到视频流的信息,打不开会报错,比如下面这个视频流就连不上

# ffprobe -hide_banner rtmp://127.0.0.1:1935/live/202112240548150001
[tcp @ 0x135804260] Connection to tcp://127.0.0.1:1935?tcp_nodelay=0 failed: Connection refused
[rtmp @ 0x1347043f0] Cannot open connection tcp://127.0.0.1:1935?tcp_nodelay=0
rtmp://127.0.0.1:1935/live/202112240548150001: Connection refused

VLC

CMD+N 打开网络视频流

填入 rtmp 地址后即可播放。

CMD+I 打开媒体信息

或者菜单栏 Window - Media Information


上一篇 Java-基础

下一篇 VMware虚拟机

阅读
评论
1.9k
阅读预计10分钟
创建日期 2015-05-08
修改日期 2022-06-29
类别
标签

页面信息

location:
protocol:
host:
hostname:
origin:
pathname:
href:
document:
referrer:
navigator:
platform:
userAgent:

评论