[Libav-user] Updating dvbcut c++ code to avcodec_decode_audio4 or current.

David Timms dtimms at iinet.net.au
Fri Oct 21 00:19:18 EEST 2016


Hi, I've been working through C11, deprecation and other warnings in the
dvbcut (mpeg2 video splitter GUI) code. The last is avcodec_decode_audio.

Original loop:
======
	if (sd->getitemlistsize() > 1) {
	  if (!avcodec_open(s->codec,
			    avcodec_find_decoder(s->codec->codec_id))) {
	    int16_t samples[AVCODEC_MAX_AUDIO_FRAME_SIZE/sizeof(int16_t)];
	    int frame_size=sizeof(samples);
	    //fprintf(stderr, "** decode audio size=%d\n", sd->inbytes());
#if LIBAVCODEC_VERSION_INT >= ((52<<16)+(0<<8)+0)
	    avcodec_decode_audio2
#else
	    avcodec_decode_audio
#endif
	      (s->codec,samples,&frame_size,
	       (uint8_t*) sd->getdata(),sd->inbytes());
	    avcodec_close(s->codec);
	  }
	  break;
	}
=====
In my updated code below, I've left the function headers/deprecation as
comments to assist. This doesn't compile. And I'll be tackling it
further, but I would welcome any help about whether I'm going in the
correct direction ?

Also, an example of using: the alternates to (soon to be deprecated)
avcodec_decode_audio4 would be useful, if you  know of one ?

The .orig and my current attempt (in full) at:
http://members.iinet.net.au/~timmsy/dvbcut/ffmpeg3/

Thanks, David.

=========
new code:
	if (sd->getitemlistsize() > 1) {
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53, 8, 0)
/*
int avcodec_open (AVCodecContext * avctx, AVCodec * codec)
Deprecated: use avcodec_open2(): doxygen/0.7/
int avcodec_open2(AVCodecContext * avctx, const AVCodec * codec,
AVDictionary ** options) 	
*/
          AVDictionary *codec_options = NULL;
	  if (avcodec_open2(s->codec,
			    avcodec_find_decoder(s->codec->codec_id), &codec_options) == 0) {
#else
	  if (!avcodec_open(s->codec,
			    avcodec_find_decoder(s->codec->codec_id))) {
#endif

#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53, 40, 0)
/*
AVCODEC_MAX_AUDIO_FRAME_SIZE is deprecated.
*/
#define MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio
	    int16_t samples[MAX_AUDIO_FRAME_SIZE/sizeof(int16_t)];
#else
	    int16_t samples[AVCODEC_MAX_AUDIO_FRAME_SIZE/sizeof(int16_t)];
#endif
	    int frame_size=sizeof(samples);
	    //fprintf(stderr, "** decode audio size=%d\n", sd->inbytes());

#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(157, 24, 0)
/*
int avcodec_decode_audio (AVCodecContext * avctx, int16_t * samples,
                         int * frame_size_ptr, uint8_t * buf, int buf_size);
Deprecated: Use avcodec_decode_audio2() instead.
int avcodec_decode_audio2(AVCodecContext * avctx, int16_t * samples,
                         int * frame_size_ptr, uint8_t * buf, int buf_size);
Deprecated: Use avcodec_decode_audio3() instead.
int avcodec_decode_audio3(AVCodecContext * avctx, int16_t * samples,
                         int * frame_size_ptr, AVPacket * avpkt) 	
Deprecated: Use avcodec_decode_audio4 instead.
int avcodec_decode_audio4 (AVCodecContext *avctx, AVFrame *frame,
                         int * got_frame_ptr, const AVPacket * avpkt)
Deprecated:
    Use avcodec_send_packet() and avcodec_receive_frame():
int avcodec_send_packet(AVCodecContext * avctx, const AVPacket * avpkt)
int avcodec_receive_frame(AVCodecContext * avctx, AVFrame * frame) 	
*/
            avcodec_decode_audio4(s->codec, samples, &frame_size, &avpkt);
#elif LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 24, 0)
            AVPacket avpkt;
            av_init_packet(&avpkt);
            avpkt.data = (uint8_t*)sd->getdata();
            avpkt.size = sd->inbytes();
            // HACK for CorePNG to decode as normal PNG by default
            avpkt.flags = AV_PKT_FLAG_KEY;
            avcodec_decode_audio4(s->codec, samples, &frame_size, &avpkt);
#elif LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 23, 0)
	    avcodec_decode_audio2(s->codec, samples, &frame_size,
	                          (uint8_t*) sd->getdata(), sd->inbytes());
#else
	    avcodec_decode_audio(s->codec, samples, &frame_size,
	                         (uint8_t*) sd->getdata(), sd->inbytes());
#endif
	    avcodec_close(s->codec);
	  }
	  break;
	}
      }
    }

====


More information about the Libav-user mailing list