FFmpeg 命令

1. 推流

1). 查看支持的设备

ffmpeg -f avfoundation -list_devices true -i ""

输出:

MacBook-Air:~ mazaiting$ ffmpeg -f avfoundation -list_devices true -i ""
ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 7.0.2 (clang-700.1.81)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4.1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
[AVFoundation input device @ 0x7f941a5002a0] AVFoundation video devices:
[AVFoundation input device @ 0x7f941a5002a0] [0] FaceTime HD Camera
[AVFoundation input device @ 0x7f941a5002a0] [1] Capture screen 0
[AVFoundation input device @ 0x7f941a5002a0] AVFoundation audio devices:
[AVFoundation input device @ 0x7f941a5002a0] [0] Apowersoft_AudioDevice
[AVFoundation input device @ 0x7f941a5002a0] [1] Built-in Microphone
: Input/output error
MacBook-Air:~ mazaiting$

2). 推流桌面 - 只有桌面内容

ffmpeg -f avfoundation -pixel_format uyvy422 -i "1" -f flv rtmp://localhost:12345/zbcs/room
ffmpeg -f avfoundation -i "1" -vcodec libx264 -preset ultrafast -acodec libfaac -f flv rtmp://localhost:12345/zbcs/room

3). 推流摄像头

ffmpeg -f avfoundation -framerate 30 -video_size 1280x720 -i  "0"  -vcodec libx264 -acodec libfaac -f flv rtmp://localhost:12345/zbcs/room

4). 只推流麦克风

ffmpeg -f avfoundation -i ":0" -vcodec libx264 -preset ultrafast -acodec libmp3lame -ar 44100 -ac 1 -f flv rtmp://localhost:12345/zbcs/room

5). 摄像头+麦克分

ffmpeg -f avfoundation -framerate 30 -video_size 1280x720 -i "0:0" -vcodec libx264 -preset ultrafast -acodec libmp3lame -ar 44100 -ac 1 -f flv rtmp://localhost:12345/zbcs/room

6). 推流视频

ffmpeg -re -i /Users/mazaiting/Downloads/台球.mp4 -vcodec copy -f flv rtmp://localhost:12345/live1/room
2.基本命令

1).分离视频音频流

ffmpeg -i input_file -vcodec copy -an output_file_video  //分离视频流
ffmpeg -i input_file -acodec copy -vn output_file_audio  //分离音频流

2).视频解复用

ffmpeg –i test.mp4 –vcodec copy –an –f m4v test.264ffmpeg –i test.avi –vcodec copy –an –f m4v test.264

3).视频转码

ffmpeg –i test.mp4 –vcodec h264 –s 352*278 –an –f m4v test.264 //转码为码流原始文件
ffmpeg –i test.mp4 –vcodec h264 –bf 0 –g 25 –s 352*278 –an –f m4v test.264 //转码为码流原始文件
ffmpeg –i test.avi -vcodec mpeg4 –vtag xvid –qsame test_xvid.avi //转码为封装文件

其中:
-bf B帧数目控制
-g 关键帧间隔控制
-s 分辨率控制

4).视频封装

ffmpeg –i video_file –i audio_file –vcodec copy –acodec copy output_file

5).视频剪切

ffmpeg –i test.avi –r 1 –f image2 image-%3d.jpeg //提取图片
ffmpeg -ss 0:1:30 -t 0:0:20 -i input.avi -vcodec copy -acodec copy output.avi //剪切视频

其中:
-r 提取图像的频率
-ss 开始时间
-t 持续时间

6).视频录制

ffmpeg –i rtsp://192.168.3.205:5555/test –vcodec copy out.avi

7.YUV序列播放

ffplay -f rawvideo -video_size 1920x1080 input.yuv

8.YUV序列转AVI

ffmpeg –s w*h –pix_fmt yuv420p –i input.yuv –vcodec mpeg4 output.avi

9.常用参数说明:

主要参数: 
i 设定输入流 
f 设定输出格式 
ss 开始时间 
视频参数: 
b 设定视频流量,默认为200Kbit/s-r 设定帧速率,默认为25 
s 设定画面的宽与高-aspect 设定画面的比例 
vn 不处理视频-vcodec 设定视频编解码器,未设定时则使用与输入流相同的编解码器 
音频参数: 
ar 设定采样率 
ac 设定声音的Channel数 
acodec 设定声音编解码器,未设定时则使用与输入流相同的编解码器an 不处理音频
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值