avformat_free_context和avformat_close_input

avformat_free_context 和 avformat_close_input 都是用于释放 FFmpeg 中 AVFormatContext 结构体占用的资源,不过二者有些区别。

  • avformat_free_context: 该函数会释放 AVFormatContext 及其内部包含的所有资源,包括已经打开的音视频文件和网络流等。在使用该函数时,需要首先调用 avformat_close_input 关闭 AVFormatContext 的输入流。
  • avformat_close_input: 该函数仅仅关闭 AVFormatContext 的输入流,但不会释放 AVFormatContext 占用的内存空间。如果你想要完全释放 AVFormatContext 资源,则应当接着调用 avformat_free_context 函数。

一般来说,在使用完 FFmpeg 中的音视频解码、编码、封装、解封装等功能后,需要先调用 avformat_close_input 关闭输入流,并检查是否出现错误;然后再根据实际情况选择是否调用 avformat_free_context 来释放资源。

posted @ 2024-12-30 21:15  rainbow70626  阅读(183)  评论(0)    收藏  举报