podre-henrique commited on
Commit
0aa41e8
·
unverified ·
1 Parent(s): 855927b

examples : fix deprecated FFmpeg functions (#3073)

Browse files

* Fix deprecated FFmpeg functions and free packet

* avcodec_free_context

Files changed (1) hide show
  1. examples/ffmpeg-transcode.cpp +10 -5
examples/ffmpeg-transcode.cpp CHANGED
@@ -194,7 +194,7 @@ static int decode_audio(struct audio_buffer *audio_buf, s16 **data, int *size)
194
  AVIOContext *avio_ctx;
195
  AVStream *stream;
196
  AVCodecContext *codec;
197
- AVPacket packet;
198
  AVFrame *frame;
199
  struct SwrContext *swr;
200
  u8 *avio_ctx_buffer;
@@ -279,7 +279,11 @@ static int decode_audio(struct audio_buffer *audio_buf, s16 **data, int *size)
279
  return -1;
280
  }
281
 
282
- av_init_packet(&packet);
 
 
 
 
283
  frame = av_frame_alloc();
284
  if (!frame) {
285
  LOG("Error allocating the frame\n");
@@ -289,8 +293,8 @@ static int decode_audio(struct audio_buffer *audio_buf, s16 **data, int *size)
289
  /* iterate through frames */
290
  *data = NULL;
291
  *size = 0;
292
- while (av_read_frame(fmt_ctx, &packet) >= 0) {
293
- avcodec_send_packet(codec, &packet);
294
 
295
  err = avcodec_receive_frame(codec, frame);
296
  if (err == AVERROR(EAGAIN))
@@ -301,10 +305,11 @@ static int decode_audio(struct audio_buffer *audio_buf, s16 **data, int *size)
301
  /* Flush any remaining conversion buffers... */
302
  convert_frame(swr, codec, frame, data, size, true);
303
 
 
304
  av_frame_free(&frame);
305
  swr_free(&swr);
306
  //avio_context_free(); // todo?
307
- avcodec_close(codec);
308
  avformat_close_input(&fmt_ctx);
309
  avformat_free_context(fmt_ctx);
310
 
 
194
  AVIOContext *avio_ctx;
195
  AVStream *stream;
196
  AVCodecContext *codec;
197
+ AVPacket *packet;
198
  AVFrame *frame;
199
  struct SwrContext *swr;
200
  u8 *avio_ctx_buffer;
 
279
  return -1;
280
  }
281
 
282
+ packet=av_packet_alloc();
283
+ if (!packet) {
284
+ LOG("Error allocating the packet\n");
285
+ return -1;
286
+ }
287
  frame = av_frame_alloc();
288
  if (!frame) {
289
  LOG("Error allocating the frame\n");
 
293
  /* iterate through frames */
294
  *data = NULL;
295
  *size = 0;
296
+ while (av_read_frame(fmt_ctx, packet) >= 0) {
297
+ avcodec_send_packet(codec, packet);
298
 
299
  err = avcodec_receive_frame(codec, frame);
300
  if (err == AVERROR(EAGAIN))
 
305
  /* Flush any remaining conversion buffers... */
306
  convert_frame(swr, codec, frame, data, size, true);
307
 
308
+ av_packet_free(&packet);
309
  av_frame_free(&frame);
310
  swr_free(&swr);
311
  //avio_context_free(); // todo?
312
+ avcodec_free_context(&codec);
313
  avformat_close_input(&fmt_ctx);
314
  avformat_free_context(fmt_ctx);
315