FFmpeg #

FFmpeg/FFmpeg Github stars

Fast Forward Moving Picture Experts Group

FFmpeg is a collection of libraries and tools to process multimedia content such as audio, video, subtitles and related metadata.

安装 #

linux 安装 ffmpeg


ffmpeg -re -i car-brand.MOV -rtsp_transport tcp -vcodec h264 -f rtsp rtsp://localhost/test

ffplay #

# 添加到 ~/.zshrc
function rtsp() {
	ffplay -analyzeduration 1000000 -fflags nobuffer -probesize 32 -sync ext $@

命令 #

ffmpeg -i rtsp://admin:root123@ -vcodec copy -acodec copy  -rtsp_transport tcp -f rtsp rtsp://

# 音视频转码后推送
ffmpeg -i rtsp://admin:root123@ -vcodec libx264 -acodec libvo_aacenc  -rtsp_transport tcp -f rtsp rtsp://

ffmpeg -re -i ./car-brand.MOV -stream_loop -1  -vcodec libx264 -acodec aac -f rtsp rtsp://
ffmpeg -re -i ./car-brand.MOV -rtsp_transport tcp -vcodec h264 -f rtsp rtsp://localhost/test
ffmpeg -re -i ./car-brand.MOV -rtsp_transport udp -vcodec h264 -f rtsp rtsp://localhost/test

ffmpeg -re -stream_loop -1 -i carbrand.MOV -rtsp_transport tcp -vcodec h264 -f rtsp rtsp://localhost/test1
ffmpeg -re -stream_loop -1 -i carbrand.MOV -c copy                          -f rtsp rtsp://localhost:8554/mystream

ffmpeg 参数 #

# 参考文档 https://ffmpeg.org/ffmpeg.html

Main options:
# Force input or output file format. The format is normally auto detected for input files and guessed from the file extension for output files, so this option is not needed in most cases.
-f fmt              force format
# Select an encoder (when used before an output file)
# or a decoder (when used before an input file) for one or more streams.
# codec is the name of a decoder/encoder
# or a special value copy (output only) to indicate that the stream is not to be re-encoded.
-c codec            codec name
-codec codec        codec name
# input file url
-i url
# Set number of times input stream shall be looped. Loop 0 means no loop, loop -1 means infinite loop.
# -1 无限循环
-stream_loop number

Video options:
-r rate             set frame rate (Hz value, fraction or abbreviation)
-vcodec codec       force video codec ('copy' to copy stream)

Audio options:
-acodec codec       force audio codec ('copy' to copy stream)

# Read input at native frame rate. Mainly used to simulate a grab device, or live input stream (e.g. when reading from a file).
# 用来模拟一个摄像头或者实时流,不要在正式环境使用

h264_nvenc vs libx264 vs h264 #

h264_nvenc uses the NVidia hardware assisted H.264 video encoder. libx264 is a software (CPU) based H.264 encoder.