public:it:ffmpeg

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录 前一修订版
后一修订版
前一修订版
public:it:ffmpeg [2023/07/13 18:09] – [常用指令] oakfirepublic:it:ffmpeg [2024/12/27 13:40] (当前版本) – [Tips] oakfire
行 2: 行 2:
   * Official site:[[https://ffmpeg.org/|ffmpeg.org]]   * Official site:[[https://ffmpeg.org/|ffmpeg.org]]
   * 静态编译下载:[[https://johnvansickle.com/ffmpeg/]]   * 静态编译下载:[[https://johnvansickle.com/ffmpeg/]]
 +  * ffmpeg 原理:[[https://ffmpeg.xianwaizhiyin.net/]]
  
 ===== FFmpeg使用===== ===== FFmpeg使用=====
行 41: 行 42:
   * rtsp 推流,使用 [[https://github.com/bluenviron/mediamtx|mediamtx]] 在8554端口建立rtsp 服务,此时可用 ffmpeg 推流:<code bash>ffmpeg -re -stream_loop -1 -i input.mp4 -vcodec copy -vbsf h264_mp4toannexb -f rtsp -rtsp_transport tcp rtsp://192.168.0.165:8554/chn_name</code>   * rtsp 推流,使用 [[https://github.com/bluenviron/mediamtx|mediamtx]] 在8554端口建立rtsp 服务,此时可用 ffmpeg 推流:<code bash>ffmpeg -re -stream_loop -1 -i input.mp4 -vcodec copy -vbsf h264_mp4toannexb -f rtsp -rtsp_transport tcp rtsp://192.168.0.165:8554/chn_name</code>
   * 按比例缩放并补边:<code bash>ffmpeg -i input704x576.mp4 -vf "scale=384:216:force_original_aspect_ratio=decrease,pad=384:216:-1:-1:color=green" output.mp4</code>   * 按比例缩放并补边:<code bash>ffmpeg -i input704x576.mp4 -vf "scale=384:216:force_original_aspect_ratio=decrease,pad=384:216:-1:-1:color=green" output.mp4</code>
 +  * 低延时播放测试:<code bash>ffplay -v debug -x 640 -y 380 https://192.168.0.151:6161/dev0.flv   -fflags nobuffer -analyzeduration 1000000</code>
 ===== FFmpeg编程 ===== ===== FFmpeg编程 =====
 ==== 硬解 ==== ==== 硬解 ====
行 86: 行 88:
     pFormatCtx->flags = AVFMT_FLAG_NOBUFFER;     pFormatCtx->flags = AVFMT_FLAG_NOBUFFER;
     int ret = avformat_open_input(&pFormatCtx, ...);</code>     int ret = avformat_open_input(&pFormatCtx, ...);</code>
-  * ''avformat_open_input'' 默认是阻塞的,如果是 tcp 连接,可设置 ''listen_timeout''(单位秒) 或者 ''stimeout''(单位微秒) 来达到超时处理;如果是 udp 连接,则可以设置中断回调 ''pFormatCtx->interrupt_callback''+  * ''avformat_open_input'' 默认是阻塞的,如果是 tcp 连接,<del>可设置 ''listen_timeout''(单位秒) 或者 ''stimeout''(单位微秒) 来达到超时处理</del>, 参考官网具体协议文档来设置tcp超时,比如 rtsp:  https://ffmpeg.org/ffmpeg-protocols.html#rtsp;如果是 udp 连接,则可以设置中断回调 ''pFormatCtx->interrupt_callback''
   * 关于视频流初始解析时间:   * 关于视频流初始解析时间:
     * ''avformat_find_stream_info'' 的返回时间和 ''pFormatCtx->probesize'' 与 ''pFormatCtx->max_analyze_duration'' 相关,哪个先达到就返回。     * ''avformat_find_stream_info'' 的返回时间和 ''pFormatCtx->probesize'' 与 ''pFormatCtx->max_analyze_duration'' 相关,哪个先达到就返回。
行 102: 行 104:
     * ''avcodec_flush_buffers'' 可直接清除解码器缓存帧,用于 seek 操作或切换流操作。     * ''avcodec_flush_buffers'' 可直接清除解码器缓存帧,用于 seek 操作或切换流操作。
   * ffmpeg 在 android 上解码音频:[[https://medium.com/@donturner/using-ffmpeg-for-faster-audio-decoding-967894e94e71|using-ffmpeg-for-faster-audio-decoding]]   * ffmpeg 在 android 上解码音频:[[https://medium.com/@donturner/using-ffmpeg-for-faster-audio-decoding-967894e94e71|using-ffmpeg-for-faster-audio-decoding]]
 +  * ''avformat_open_input'' 会自动 free 第四个非空参数 ''*options'', 并把找不到的选项重新申请内存并返还给 ''*options'',所有需要手动判断 ''*options'' 是否非空并释放, 否则内存泄露
  
  
  • public/it/ffmpeg.1689242949.txt.gz
  • 最后更改: 2023/07/13 18:09
  • oakfire