一、流程圖
二、代碼解釋
- avcodec_find_encoder:
根據指定的AVCodecID查找注冊的編碼器。 - avcodec_alloc_context3:
為AVCodecContext分配內存。() - avcodec_open2:
打開編碼器。 - avcodec_send_frame:
將AVFrame?壓縮數據給編碼器。 - avcodec_receive_packet:
獲取到編碼后的AVPacket數據,收到的packet需要??釋放內存。 - av_frame_get_buffer:
為?頻或視頻幀分配新的buffer。在調?這個函數之前,必須在AVFame上設
置好以下屬性:format(視頻為像素格式,?頻為樣本格式)、nb_samples(樣本個數,針對?頻)、
channel_layout(通道類型,針對?頻)、width/height(寬?,針對視頻)。 - av_frame_make_writable:
確保AVFrame是可寫的,使?av_frame_make_writable()的問題是,在
最壞的情況下,它會在您使?encode再次更改整個輸?frame之前復制它. 如果frame不可寫,
av_frame_make_writable()將分配新的緩沖區,并復制這個輸?input frame數據,避免和編碼器需
要緩存該幀時造成沖突。 - av_samples_fill_arrays
填充?頻幀
三、結構體介紹
AVCodecContext
1、核心功能
-
編解碼器管理
存儲與特定編解碼器(如 H.264、AAC)相關的參數和狀態,包括編解碼器類型(codec_type
)、編解碼器 ID(codec_id
)等。通過avcodec_alloc_conte