mirror of
https://github.com/ggerganov/whisper.cpp.git
synced 2025-06-20 01:38:04 +02:00
examples : fix deprecated FFmpeg functions (#3073)
* Fix deprecated FFmpeg functions and free packet * avcodec_free_context
This commit is contained in:
parent
50fda73f4c
commit
f9b2dfdd8c
@ -194,7 +194,7 @@ static int decode_audio(struct audio_buffer *audio_buf, s16 **data, int *size)
|
||||
AVIOContext *avio_ctx;
|
||||
AVStream *stream;
|
||||
AVCodecContext *codec;
|
||||
AVPacket packet;
|
||||
AVPacket *packet;
|
||||
AVFrame *frame;
|
||||
struct SwrContext *swr;
|
||||
u8 *avio_ctx_buffer;
|
||||
@ -279,7 +279,11 @@ static int decode_audio(struct audio_buffer *audio_buf, s16 **data, int *size)
|
||||
return -1;
|
||||
}
|
||||
|
||||
av_init_packet(&packet);
|
||||
packet=av_packet_alloc();
|
||||
if (!packet) {
|
||||
LOG("Error allocating the packet\n");
|
||||
return -1;
|
||||
}
|
||||
frame = av_frame_alloc();
|
||||
if (!frame) {
|
||||
LOG("Error allocating the frame\n");
|
||||
@ -289,8 +293,8 @@ static int decode_audio(struct audio_buffer *audio_buf, s16 **data, int *size)
|
||||
/* iterate through frames */
|
||||
*data = NULL;
|
||||
*size = 0;
|
||||
while (av_read_frame(fmt_ctx, &packet) >= 0) {
|
||||
avcodec_send_packet(codec, &packet);
|
||||
while (av_read_frame(fmt_ctx, packet) >= 0) {
|
||||
avcodec_send_packet(codec, packet);
|
||||
|
||||
err = avcodec_receive_frame(codec, frame);
|
||||
if (err == AVERROR(EAGAIN))
|
||||
@ -301,10 +305,11 @@ static int decode_audio(struct audio_buffer *audio_buf, s16 **data, int *size)
|
||||
/* Flush any remaining conversion buffers... */
|
||||
convert_frame(swr, codec, frame, data, size, true);
|
||||
|
||||
av_packet_free(&packet);
|
||||
av_frame_free(&frame);
|
||||
swr_free(&swr);
|
||||
//avio_context_free(); // todo?
|
||||
avcodec_close(codec);
|
||||
avcodec_free_context(&codec);
|
||||
avformat_close_input(&fmt_ctx);
|
||||
avformat_free_context(fmt_ctx);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user