只推音频 ffmpeg -re -i ``"输入源"`` -acodec ``copy`` -vcodec ``copy`` -vn -f flv -y ``"输出原"

Tip

  1. ffplay -protocol_whitelist "file,http,https,tcp,tls" output.m3u8

解决Protocol ‘http’ not on whitelist ‘file,crypto’!

rtmp推流

  1. 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推播流

  1. ffplay -probesize 32000 -sync ext 'srt://0.0.0.0:5001?mode=listener'
  2. ffmpeg -re -i /Users/gaoshen/Movies/sully_low.mp4 -bsf:a aac_adtstoasc -c copy -f mpegts "srt://127.0.0.1:5001"

编译shared

  1. ./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() 只需要初始化一次,如果参数发生了变化,需要再次重新初始化

  1. /**
  2. * Gets the delay the next input sample will experience relative to the next output sample.
  3. *
  4. * Swresample can buffer data if more input has been provided than available
  5. * output space, also converting between sample rates needs a delay.
  6. * This function returns the sum of all such delays.
  7. * The exact delay is not necessarily an integer value in either input or
  8. * output sample rate. Especially when downsampling by a large value, the
  9. * output sample rate may be a poor choice to represent the delay, similarly
  10. * for upsampling and the input sample rate.
  11. *
  12. * @param s swr context
  13. * @param base timebase in which the returned delay will be:
  14. * @li if it's set to 1 the returned delay is in seconds
  15. * @li if it's set to 1000 the returned delay is in milliseconds
  16. * @li if it's set to the input sample rate then the returned
  17. * delay is in input samples
  18. * @li if it's set to the output sample rate then the returned
  19. * delay is in output samples
  20. * @li if it's the least common multiple of in_sample_rate and
  21. * out_sample_rate then an exact rounding-free delay will be
  22. * returned
  23. * @returns the delay in 1 / @c base units.
  24. */
  25. int64_t swr_get_delay(struct SwrContext *s, int64_t base);

添加时间

  1. 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。