ffmpeg 维基百科
FFmpeg 是一个开放源代码的自由软件,可以执行音频和视频多种格式的录影、转换、串流功能,包含了libavcodec——这是一个用于多个项目中音频和视频的解码器库,以及libavformat——一个音频与视频格式转换库。

“FFmpeg”这个单词中的“FF”指的是“Fast Forward(快速前进)”。有些新手写信给“FFmpeg”的项目负责人,询问FF是不是代表“Fast Free”或者“Fast Fourier”等意思,“FFmpeg”的项目负责人回信说:“Just for the record, the original meaning of "FF" in FFmpeg is "Fast Forward"...”

这个项目最初是由法国程序员法布里斯·贝拉(Fabrice Bellard)发起的,而现在是由迈克尔·尼德梅尔(Michael Niedermayer)在进行维护。许多FFmpeg的开发者同时也是MPlayer项目的成员,FFmpeg在MPlayer项目中是被设计为服务器版本进行开发。

2011年3月13日,FFmpeg部分开发人士决定另组Libav,同时制定了一套关于项目继续发展和维护的规则。

ffmpeg 命令行程序
命令行应用程序
ffmpeg:用于对视频文档或音频档案转换格式
ffplay:一个简单的播放器,基于SDL与FFmpeg库
ffprobe:用于显示媒体文件的信息,见MediaInfo
ffmpeg 常用参数
参数明细可用ffmpeg -h显示;编解码器名称等明细可用ffmpeg -formats显示。

下列为较常使用的参数:

主要参数

-i——设置输入文件名。
-f——设置输出格式。
-y——若输出文件已存在时则覆盖文件。
-fs——超过指定的文件大小时则结束转换。
-t——指定输出文件的持续时间,以秒为单位。
-ss——从指定时间开始转换,以秒为单位。
-ss和-t一起使用时代表从-ss的时间开始转换持续时间为-t的视频,例如:-ss 00:00:01.00 -t 00:00:10.00即从00:00:01.00开始转换到00:00:11.00。
-title——设置标题。
-timestamp——设置时间戳。
-vsync——增减Frame使影音同步。
-c——指定输出文件的编码。
-metadata——更改输出文件的元数据。
-help——查看帮助信息。
影像参数
-b:v——设置影像流量,默认为200Kbit/秒。(单位请引用下方注意事项)
-r——设置帧率值,默认为25。
-s——设置画面的宽与高。
-aspect——设置画面的比例。
-vn——不处理影像,于仅针对声音做处理时使用。
-vcodec( -c:v )——设置影像影像编解码器,未设置时则使用与输入文件相同之编解码器。

ffmpeg linux shell 批量提取音频内容

cat cc.sh 
#!/bin/sh
 
 
folder="."
id=0
for file_a in ${folder}/*
do
    let id++
    in_filename=`basename $file_a`
    num=`echo $id | awk '{printf("%02d",$0)}'`;
    out_filename="output/$num.aac"
    if [ "${in_filename##*.}"x = "mp4"x ]||[ "${in_filename##*.}"x = "ts"x ];then
    ffmpeg -i $in_filename -vn  $out_filename 
    fi
done

ffmpeg 下载 m3u8

ffmpeg -i http://.../playlist.m3u8 -c copy -bsf:a aac_adtstoasc output.mp4

ffmpeg aac_adtstoasc 格式说明

官方说明地址在这儿:https://ffmpeg.org/ffmpeg-bitstream-filters.html#aac_005fadtstoasc
*Convert MPEG-2/4 AAC ADTS to an MPEG-4 Audio Specific Configuration bitstream.
This filter creates an MPEG-4 AudioSpecificConfig from an MPEG-2/4 ADTS header and removes the ADTS header.
This filter is required for example when copying an AAC stream from a raw ADTS AAC or an MPEG-TS container to MP4A-LATM, to an FLV file, or to MOV/MP4 files and related formats such as 3GP or M4A. Please note that it is auto-inserted for MP4A-LATM and MOV/MP4 and related formats.*

1)将AAC编码器编码后的原始码流(ADTS头 + ES流)封装为MP4或者FLV或者MOV等格式时,需要先将ADTS头转换为MPEG-4 AudioSpecficConfig (将音频相关编解码参数提取出来),并将原始码流中的ADTS头去掉(只剩下ES流)。
2)相反,从MP4或者FLV或者MOV等格式文件中解封装出AAC码流(只有ES流)时,需要在解析出的AAC码流前添加ADTS头(含音频相关编解码参数)。

ubuntu ffmpeg screen capture

ffmpeg -f x11grab -video_size 1920x1030 -framerate 50 -i :0.0 -vf format=yuv420p output.mp4

Capturing your Desktop / Screen Recording for Linux
Use the x11grab device:

ffmpeg -video_size 1024x768 -framerate 25 -f x11grab -i :0.0+100,200 output.mp4

This will grab the image from desktop, starting with the upper-left corner at x=100, y=200 with a width and height of 1024⨉768.

If you need audio too, you can use ALSA (see Capture/ALSA for more info):

ffmpeg -video_size 1024x768 -framerate 25 -f x11grab -i :0.0+100,200 -f alsa -ac 2 -i hw:0 output.mkv

Or the pulse input device (see Capture/PulseAudio for more info):

ffmpeg -video_size 1024x768 -framerate 25 -f x11grab -i :0.0+100,200 -f pulse -ac 2 -i default output.mkv

ffmpeg 编译参数

ffmpeg -version

ffmpeg version N-105038-g30322ebe3c Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)
configuration: --enable-libx264 --enable-libpulse --enable-gpl --enable-openssl --enable-nonfree --enable-x86asm --enable-libmp3lame --enable-libx265 --enable-librtmp

ffmpeg 编解码列表

$ ffmpeg -codecs
$ ffmpeg -encoders
$ ffmpeg -decoders
$ ffmpeg -formats

ffmpeg 错误 OpenSSL <3.0.0 is incompatible with the gpl

Add --enable-nonfree

ffmpeg 录制电脑音频

pactl list short sources

1 alsa_output.pci-0000_00_1f.3.analog-stereo.monitor module-alsa-card.c s16le 2ch 48000Hz IDLE
2 alsa_input.pci-0000_00_1f.3.analog-stereo module-alsa-card.c s16le 2ch 48000Hz SUSPENDED

ffmpeg pulse 电脑录音

ffmpeg -f pulse -i 1 -ac 1 out.mp3

You can reference sources either by number: -f pulse -i 5, or by name -f pulse -i alsa_input.pci-0000_00_1b.0.analog-stereo, or just use -f pulse -i default to use the source currently set as default in pulseaudio.

ffmpeg 麦克风录音

ffmpeg -f pulse -i alsa_input.pci-0000_00_1b.0.analog-stereo -ac 1 recording.m4a

ffmpeg 录取播放声音

ffmpeg -f pulse -i alsa_output.pci-0000_00_1b.0.analog-stereo.monitor -ac 2 recording.m4a

Linux 录取电脑音视频

ffmpeg -video_size 1024x768 -framerate 25 -f x11grab -i :0.0+100,200 -f pulse -ac 2 -i 1 output.mkv

move the moov atom to the begining of the video file using FFMpeg

ffmpeg -i input_video_file.mp4 -vcodec copy -acodec copy -movflags faststart output_video_file.mp4

ffmpeg 分割mp4

ffmpeg -i input.mp4 -c copy -segment_time 30 -f segment output%03d.mp4

ffmpeg -i input.mp4 -c copy -segment_time 30 -f segment -segment_start_number 1 -individual_header_trailer 1 -break_non_keyframes 1 -reset_timestamps 1 output%03d.mp4

FFMPEG推流到rtsp server 命令
FFmpeg推流
注意:在推流之前先运行rtsp-simple-server,下载地址: https://github.com/bluenviron/mediamtx/releases

UDP推流

ffmpeg -re -i input.mp4 -c copy -f rtsp rtsp://127.0.0.1:8554/stream

TCP推流

ffmpeg -re -i input.mp4 -c copy -rtsp_transport tcp -f rtsp rtsp://127.0.0.1:8554/stream

循环推流

ffmpeg -re -stream_loop -1 -i input.mp4 -c copy -f rtsp rtsp://127.0.0.1:8554/stream

其中:

-re 为以流的方式读取;

-stream_loop 为循环读取视频源的次数,-1为无限循环;

-i 为输入的文件;

-f 为格式化输出到哪里;
Referenced from:https://blog.csdn.net/chan1987818/article/details/128219230

本文链接地址:https://const.net.cn/635.html

标签: ffmpeg

添加新评论