ffmpeg命令(持续更新)

编译ffmpeg注意事项

头文件部分需要修改
注意:
头文件引用的时候,必须加extern “C"

// for int64_t print using PRId64 format.
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
// for cpp to use c-style macro UINT64_C in libavformat
#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#endif

target_link_libraries(
        ${PROJECT_NAME}
        libavfilter.a
        libavformat.a
        libavcodec.a
        libavutil.a
        libswscale.a
        libswresample.a
        libavdevice.a
        libpostproc.a
        libx264.a
        libfdk-aac.a
        pthread
        m
        rt
        z
        dl
)

build for srs

ffmpeg:
./configure --enable-libx264 --enable-libfdk-aac --enable-nonfree --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --enable-static --disable-shared --enable-gpl --extra-libs=-ldl --extra-libs=-lm
Aacplus:
Unzip libaacplus-2.0.2.zip
cp ~/CLionProjects/jvsrs/trunk/3rdparty/libaacplus-patch-26410-800.zip src/26410-800.zip
./autogen.sh
./configure —enable-static
Make & make install
X264:
./configure —enable-static
Fdk-aac:
注意删除掉动态库
出现找不到fdk_aac库的时候,去ffbuild/config.log看看究竟是什么错误,一般不是路径的错误导致的,而是缺少库等连接错误
srs 新版配置方案
# 打开传码功能,因为音频格式不兼容,标准HLS只支持AAC
# 将设备推上来的流传码后转推到 hlsVhost 上
    transcode {
        enabled          on;
        ffmpeg           ./ffmpeg/bin/ffmpeg;
        engine ff {
            enabled      on;
            vcodec       copy;
            #acodec       libaacplus;
            acodec       libfdk_aac;
            abitrate     16;
            asample_rate 44100;
            achannels    1;
            aparams {
            }
            output       rtmp://127.0.0.1:[port]/[app]?vhost=hlsVhost/[stream];
        }
    }
}

# 该 Vhost 接收传码后的流,并生成 hls 协议文件
vhost hlsVhost {
    hls {
        enabled         on;
# HLS文件输入路径
        hls_path        /usr/local/nginx/html;
# 分片长度
        hls_fragment    2;
# 窗口大小(分片长度*分片数)
        hls_window     4;
    }
}

rtsp 2 hls

ffmpeg  -re -rtsp_transport tcp -i "rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=2" -c:v copy -c:a aac -strict -2 -segment_list_size 4 -hls_flags delete_segments  -hls_time 5 -f hls output.m3u8

以uts时间作为ts文件结尾,生成hls列表

./ffmpeg -re -i trailer.mp4 -v verbose -c copy -f hls -hls_segment_filename trailer-%s.ts -use_localtime 1 -bsf:v h264_mp4toannexb trailer.m3u8

rtsp 2 rtmp

ffmpeg (-rtsp_transport tcp) -i [rtsp://admin:[email protected]:8554/live0.h264](rtsp://admin:[email protected]:8554/live0.h264) -vcodec copy -acodec copy -f flv rtmp://172.16.39.85/live/test

ffplay

ffplay -protocol_whitelist "file,http,https,rtp,udp,tcp,tls" test.sdp

提取h264

ffmpeg -i 20130312_133313.mp4 -codec copy -bsf: h264_mp4toannexb -f h264 20130312_133313.264

使用srs转码

./ffmpeg -i [rtsp://admin:[email protected]:8554/live1.h264](rtsp://admin:[email protected]:8554/live1.h264) -vcodec copy -acodec  libaacplus -b:a 70000 -ar 44100 -ac 2 -f flv [rtmp://172.18.3.108/live/live1.h264](rtmp://172.18.3.108/live/live1.h264)

use: libfdk_aac  记住这里是下划线

硬件加速 hard

可以先通过ffmpeg -hwaccels查看下支持的硬件加速表

ffmpeg  \
        -hwaccel videotoolbox \
        -c:v h264_cuvid \
        -c:v h264 \
        -i [rtmp://172.16.39.85:1935/live/test](rtmp://172.16.39.85:1935/live/test) \
        -f image2pipe \
        -pix_fmt bgr24 \
        -vcodec rawvideo \
        -s 1280x720 \
        -r 15 \
        - >/tmp/audiohh

push rtmp

#!/bin/bash
for((i=1;i<=200;i++));
do
   nohup ffmpeg -re -i lindan.flv -vcodec copy -acodec copy -f flv -y [rtmp://172.16.39.214/live/pc1test$i](rtmp://172.16.39.214/live/pc1test$i) &
done

// cycle forever
for((;;)); do \
        ffmpeg -re -i big_buck_bunny_480p_h264.mov \
        -vcodec copy -acodec copy \
        -f flv -y [rtmp://127.0.0.1/live/test;](rtmp://127.0.0.1/live/test;) \
    sleep 3
done

ffmpeg 生产h264 rtp流

ffmpeg -re -i bbb.264 -an -f rtp -c:v libx264 -profile baseline -slices 10 -rtpflags h264_mode0 -payload_type 98 -pkt_size 1460 -slice-max-size 1400 rtp://192.168.0.101:20500

白名单

-protocol_whitelist file,udp,rtp

人脸的方案

ffmpeg -rtsp_transport tcp -i "rtsp://192.168.201.153:554/user=admin&password=admin&channel=1&stream=0.sdp?" -f mpegts -codec:v mpeg1video -s 1280x720 -b:v 800k -r 25 -bf 0 -q 4 -an http://192.168.201.21:3001/126/1280*720

yuv 转 rgb

ffmpeg -s 960x400 -pix_fmt yuv420p -i  rawVideo_960x400.yuv  -pix_fmt rgb24  rawVideo.rgb

ffmpeg wasm success on ffmpeg-4.0.2/ remove protocol and network

source /home/yangkai/emsdk/emsdk_env.sh
emconfigure ./configure --prefix=/home/yangkai/ffmpegemcc --cc="emcc" --cxx="em++" --ar="emar" --enable-cross-compile --target-os=none --arch=x86_32 --cpu=generic --disable-asm --disable-ffprobe --disable-ffplay --disable-doc --disable-ffmpeg --disable-pthreads --disable-w32threads --disable-network --disable-devices --disable-sdl2 --disable-hwaccels --disable-parsers --disable-bsfs --disable-debug --disable-protocols --disable-indevs --disable-outdevs --disable-iconv --disable-bzlib --disable-armv5te --disable-decoders --enable-decoder=h264 --enable-decoder=hevc --enable-decoder=aac --disable-encoders --disable-demuxers --enable-demuxer=mpegts --disable-muxers

srs config

configure summary:      --x86-x64        --prefix=/usr/local/srs --with-hls --with-hds --with-dvr --without-nginx --with-ssl --without-ffmpeg --with-transcode --with-ingest --with-stat --with-http-callback --with-http-server --without-stream-caster --with-http-api --with-librtmp --without-research --with-utest --without-gperf --without-gmc --without-gmp --without-gcp --without-gprof --without-arm-ubuntu12 --without-mips-ubuntu12 --log-trace

裁剪视频

ffmpeg -i v.mp4 -strict -2 -vf crop=1210:488:100:100 v_out.mp4

1210:488是输出后的视频大小
100:100是从左上角开始的偏移x和y量

加strict是为了使用aac音频

切分文件命令

split -a 4 -d -b 1536000 oceans.rgba frame
-a 4: 后缀有4个宽度
-d 数字为结尾,mac不支持,仅仅linux支持
-b 大小
frame 后缀 
frame0000
frame0001

拼接视频

ffmpeg -re -i input1.mp4 \
         -re -i input2.mp4 \
         -re -i input3.mp4 \
         -re -i input4.mp4 \
         -filter_complex "nullsrc=size=640x480 [base];\
         [0:v] setpts=PTS-STARTPTS, scale=320x240 [upperleft]; \
         [1:v] setpts=PTS-STARTPTS, scale=320x240 [upperright];\
         [2:v] setpts=PTS-STARTPTS, scale=320x240 [lowerleft];\
         [3:v] setpts=PTS-STARTPTS, scale=320x240[lowerright];\
         [base][upperleft] overlay=shortest=1 [tmp1];\
         [tmp1][upperright] overlay=shortest=1:x=320 [tmp2];\
         [tmp2][lowerleft] overlay=shortest=1:y=240 [tmp3];\
         [tmp3][lowerright] overlay=shortest=1:x=320:y=240" -c:v libx264 output.flv

你可能感兴趣的:(ffmpeg命令(持续更新))