chatGPT答: |
8v6.cn |
FFmpeg是一个开源的跨平台视频和音频处理工具,它提供了多种接口来进行音视频编解码、格式转换、流媒体处理等操作。随着时间的推移,FFmpeg的接口也在不断地演进和更新,下面是一些新版和旧版接口替换大全:
1. AVCodecContext -> AVCodecParameters
AVCodecContext是旧版中用于描述编解码器上下文信息的结构体,而AVCodecParameters则是新版中用于描述编解码器参数信息的结构体。在新版中使用AVCodecParameters可以更加方便地对编解码器进行配置。
2. avcodec_decode_audio4() -> avcodec_send_packet() + avcodec_receive_frame()
avcodec_decode_audio4()函数在旧版本中被广泛使用来进行音频解码操作,但在新版本中已经被废弃。取而代之的是avcodec_send_packet()函数用于发送数据包,并通过avcodec_receive_frame()函数获取输出帧。
3. av_register_all() -> avformat_network_init()
av_register_all()函数在旧版本中用于注册所有可用的文件格式和编解码器,在新版本中已经被废弃。取而代之的是avformat_network_init()函数用于初始化网络相关组件。
4. AVFrame.data[] -> AVFrame.buf[]
AVFrame.data[]数组在旧版本中表示存储图像或声音数据指针数组,在新版本中已经被废弃。取而代之的是AVFrame.buf[]数组表示存储数据缓冲区指针数组。
5. sws_scale() -> sws_scale2()
sws_scale2()函数与sws_scale()功能类似,在实现上有所不同,并且支持更多参数选项。
6. av_rescale_q_rnd(AV_TIME_BASE_Q, ...) -> av_rescale_q(...)
av_rescale_q_rnd(AV_TIME_BASE_Q, ...) 函数将时间戳从微秒转换为基本时间单位(如秒),并四舍五入到最近整数值。 在新版ffmpeg库里面该方法已经过时了,请使用以下代码:
int64_t pts = ...;
int64_t time_base_num = ...;
int64_t time_base_den = ...;
pts = (pts * time_base_num + (time_base_den / 2)) / time_base_den;
7. deprecated pixel formats: PIX_FMT_*, replaced by AV_PIX_FMT_*
PIX_FMT_* 常量定义了许多像素格式(例如YUV420P)常量值,在最近几个ffmpeg库里面这些常量都过时了,请改为使用以下代码:
enum AVPixelFormat pix_fmt; // 新方式
pix_fmt = AV_PIX_FMT_YUV420P;
8.avpicture_fill()/get_buffer()/free_buffer(), replaced by the new video API.
这三个方法都属于过去式了,请改为使用以下代码:
// Allocate a buffer for the output image.
uint8_t *buffer;
int num_bytes;
num_bytes=av_image_get_buffer_size(pix_fmt,width,height,1);
buffer=(uint8_t *)malloc(num_bytes*sizeof(uint8_t));
if(buffer==NULL){
printf("Could not allocate buffer\n");
exit(1);
}
// Wrap this buffer around an FFmpeg frame.
AVFrame *frame=0;
frame=av_frame_alloc();
if(frame==NULL){
printf("Could not allocate video frame\n");
exit(1);
}
ret=av_image_fill_arrays(frame->data,frame->linesize,
buffer,pix_fmt,width,height,1);
9.av_read_frame(), replaced by the new demuxing API.
这个方法也属于过去式,请改为使用以下代码:
while(av_read_frame(fmt_ctx,&pkt)>=0){
...
// Free the packet that was allocated by libavformat.
if(pkt.data!=NULL)
av_packet_unref(&pkt);
}
总结:以上就是ffmpeg 中一些比较重要且常见API 的替换大全列表,如果你正在升级 ffmpeg 版本或者学习 ffmpeg 编程建议参考此列表以免出现错误调试困难问题!
|