Skip to content

Instantly share code, notes, and snippets.

@melotusme
Last active October 31, 2019 02:47
Show Gist options
  • Save melotusme/1baf0f33932f8e792b14542aff0f18f4 to your computer and use it in GitHub Desktop.
Save melotusme/1baf0f33932f8e792b14542aff0f18f4 to your computer and use it in GitHub Desktop.
ffmpeg
# 基础查询命令
ffmpeg -muxers
ffmpeg -demuxers
ffmpeg -codecs
ffmpeg -decoders
ffmpeg -encoders
ffmpeg -formats
ffmpeg -devices
ffmpeg -layouts
ffmpeg -sample_fmts
ffmpeg -filters
ffmpeg -protocols
ffmpeg -bsfs
ffmpeg -f avfoundation -list_devices true -i ""
# 录制视频
ffmpeg -f avfoundation -i 1 -r 30 -s 2880x1800 t.yuv
# 录制音频
ffmpeg -f avfoundation -i :0 sound.wav
# 分解与复用
ffmpeg -i demo.flv -vcodec copy -acodec copy demo_out.mp4
## 抽取视频 -an 不要音频
ffmpeg -i demo.mov -an -vcodec copy demo_out.h264
## 抽取音频 -vn 不要视频
ffmpeg -i demo.mov -vn -acodec copy demo_out.aac
# 提取 YUV 数据
ffmpeg -i input.mp4 -an -c:v rawvideo -pix_format yuv420p out.yuv
# ffmpeg 提取 PCM 数据
-ar audio rate 44.1k
-ac audio channel 单声道 双声道
-f 数据存储格式
signed 16bit little end
ffmpeg -i input.mp4 -vn -ar 44100 -ac 2 -f s16le out.pcm
ffplay -ar 44100 -ac 2 -f s16le out.pcm
# 滤镜 加水印、去水印、画中画、视频裁剪、音频倍速
## 视频裁剪
### 宽度-200
视频编码器 libx264
音频编码器 copy
ffmpeg -i input.mov -vf crop=in_w-200:in_h-200 -c:v libx264 -c:a copy out.mp4
# -ss 00:00:01 秒开始, 持续时间 -t 10 s
ffmpeg -i input.move -ss 00:00:01 -t 10 out.ts
### inputs.txt 文件列表
#### 内容格式
file '1.ts'
file '2.ts'
file '3.ts'
ffmpeg -f concat -i inputs.txt out.flv
# 图片与视频互转
# -r rate 张/s -f format
ffmpeg -i input.flv -r 1 -f image2 image-%3d.jpeg# 分解与复用
# 图片转视频
ffmpeg -i image-%3d.jpeg out.mp4
# 直播推流
ffmpeg -re -i out.mp4 -c copy -f flv rtmp://server/live/streamName
# 直播拉流
ffmpeg -i rtmp://server/live/streamName -c copy dump.flv
cmake_minimum_required(VERSION 3.15)
project(learning_demos C)
set(CMAKE_C_STANDARD 11)
include_directories("/usr/local/Cellar/ffmpeg/4.2.1_1/include")
link_directories("/usr/local/Cellar/ffmpeg/4.2.1_1/lib")
find_package(sdl2)
include_directories(${SDL2_INCLUDE_DIRS})
aux_source_directory(player PLAYER)
aux_source_directory(. CURRENT_DIR)
add_executable(learning_demos main.c ${PLAYER} ${CURRENT_DIR} )
target_link_libraries(
learning_demos
avcodec
avdevice
avfilter
avformat
avresample
avutil
postproc
swresample
swscale
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment