只推音频 ffmpeg -re -i ``"输入源"`` -acodec ``copy`` -vcodec ``copy`` -vn -f flv -y ``"输出原"
Tip
ffplay -protocol_whitelist "file,http,https,tcp,tls" output.m3u8
解决Protocol ‘http’ not on whitelist ‘file,crypto’!
rtmp推流
ffmpeg -re -i '/Users/gaoshen/Movies/Avengers.Infinity.War.2018.1080p.BluRay.x264-Replica[rarbg]/rep-avengersinfinitywar.2018.1080p.bluray.x264.mkv' -c:v copy -ar 44100 -f flv 'rtmp://video-center.alivecdn.com/gaoshen/worker?vhost=qt1.alivecdn.com&wm=1'
flv音频采样率最大44100所以要转下
SRT推播流
ffplay -probesize 32000 -sync ext 'srt://0.0.0.0:5001?mode=listener'
ffmpeg -re -i /Users/gaoshen/Movies/sully_low.mp4 -bsf:a aac_adtstoasc -c copy -f mpegts "srt://127.0.0.1:5001"
编译shared
./configure --disable-yasm --enable-shared
如果不—enable-shared 有些库比如opencv使用的时候在连接的时候重定位失败
MISC
- avcodec_decode_audio4 3.x已经弃用,建议用avcodec_receive_frame
- av_get_default_channel_layout 可以用来根据channel no获取默认layout
- PCM sample有两种类型的存储方式:平面(planar)和打包(packed),在planar中每一个通道独自占用一个存储平面;在packed中,所有通道的sample交织存储在同一个平面。但是,对于planar格式不知道具体的某一通道所在的平面;对于packed格式各个通道的数据是以怎么样的顺序交织存储的。这就需要借助于channel_layout。
NDI PCM resample后时间变慢的问题
最终发现是因为在每次resample的时候都调用了swr_init(), 这个方法的调用会重新计算之前累积的状态,比如swr_get_delay, 这样会导致一些PCM sample被丢弃,所以swr_init() 只需要初始化一次,如果参数发生了变化,需要再次重新初始化
/**
* Gets the delay the next input sample will experience relative to the next output sample.
*
* Swresample can buffer data if more input has been provided than available
* output space, also converting between sample rates needs a delay.
* This function returns the sum of all such delays.
* The exact delay is not necessarily an integer value in either input or
* output sample rate. Especially when downsampling by a large value, the
* output sample rate may be a poor choice to represent the delay, similarly
* for upsampling and the input sample rate.
*
* @param s swr context
* @param base timebase in which the returned delay will be:
* @li if it's set to 1 the returned delay is in seconds
* @li if it's set to 1000 the returned delay is in milliseconds
* @li if it's set to the input sample rate then the returned
* delay is in input samples
* @li if it's set to the output sample rate then the returned
* delay is in output samples
* @li if it's the least common multiple of in_sample_rate and
* out_sample_rate then an exact rounding-free delay will be
* returned
* @returns the delay in 1 / @c base units.
*/
int64_t swr_get_delay(struct SwrContext *s, int64_t base);
添加时间
ffmpeg -i ~/Movies/blur.mp4 -vf "drawtext='fontsize=90:text=%{localtime\:%a %b %d %Y %X}:fontcolor=white'" -c:a copy -f flv - | ffplay -
提高并行度
ffmpeg通过设置多线程可以提高并行度,这样带来的问题是帧间有很多参考,这些参考需要保存到buffer中,会导致延迟加大,一种办法是通过帧内并行来解决,也就是通过slice并行来解决
查看色域
ffprobe -show_frames |grep color
“color_range”: “tv” 或者 “pc”
“color_space”: “bt709” 或者 “bt601”, bt2020
其中tv代表:tv表示 limited,即narrow range。pc代表:pc表示full,即wide range。
例如查询结果为color_range=tv,color_space=bt709,则代表BT-709,NARROW。