diff --git a/libvideogfx/graphics/fileio/ffmpeg.cc b/libvideogfx/graphics/fileio/ffmpeg.cc index 42034b6..2beb32c 100644 --- libvideogfx/graphics/fileio/ffmpeg.cc +++ libvideogfx/graphics/fileio/ffmpeg.cc @@ -135,17 +135,21 @@ namespace videogfx // alloc frame storage - frame = avcodec_alloc_frame(); + //frame = avcodec_alloc_frame(); + frame = av_frame_alloc(); if (frame==NULL) return false; - frameRGB = avcodec_alloc_frame(); + //frameRGB = avcodec_alloc_frame(); + frameRGB = av_frame_alloc(); if (frameRGB==NULL) return false; - int nBytesPerFrame = avpicture_get_size(PIX_FMT_RGB24, codecCtx->width, codecCtx->height); + //int nBytesPerFrame = avpicture_get_size(PIX_FMT_RGB24, codecCtx->width, codecCtx->height); + int nBytesPerFrame = avpicture_get_size(AV_PIX_FMT_RGB24, codecCtx->width, codecCtx->height); buffer = static_cast(av_malloc(nBytesPerFrame)); - avpicture_fill(reinterpret_cast(frameRGB), buffer, PIX_FMT_RGB24, codecCtx->width, codecCtx->height); + //avpicture_fill(reinterpret_cast(frameRGB), buffer, PIX_FMT_RGB24, codecCtx->width, codecCtx->height); + avpicture_fill(reinterpret_cast(frameRGB), buffer, AV_PIX_FMT_RGB24, codecCtx->width, codecCtx->height); // preload first frame @@ -239,7 +243,8 @@ namespace videogfx struct SwsContext* swsContext = sws_getContext(codecCtx->width, codecCtx->height, codecCtx->pix_fmt, - codecCtx->width, codecCtx->height, PIX_FMT_RGB24, SWS_POINT, NULL, NULL, NULL); + //codecCtx->width, codecCtx->height, PIX_FMT_RGB24, SWS_POINT, NULL, NULL, NULL); + codecCtx->width, codecCtx->height, AV_PIX_FMT_RGB24, SWS_POINT, NULL, NULL, NULL); sws_scale(swsContext, frame->data, frame->linesize, 0, codecCtx->height, frameRGB->data, frameRGB->linesize); --- libvideogfx/graphics/fileio/ffmpeg_writer.cc.orig 2014-01-22 03:07:21.000000000 -0800 +++ libvideogfx/graphics/fileio/ffmpeg_writer.cc 2019-03-12 18:39:46.000000000 -0700 @@ -59,19 +59,23 @@ #define av_guess_format guess_format #endif +#define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER +#define FF_MIN_BUFFER_SIZE AV_INPUT_BUFFER_MIN_SIZE +#define AVFMT_RAWPICTURE 0x0020 + #include namespace videogfx { -static AVFrame *allocPicture(enum PixelFormat pix_fmt, int width, int height) +static AVFrame *allocPicture(enum AVPixelFormat pix_fmt, int width, int height) { AVFrame *picture; uint8_t *picture_buf; int size; - picture = avcodec_alloc_frame(); + picture = av_frame_alloc(); if (!picture) return NULL; size = avpicture_get_size(pix_fmt, width, height); @@ -174,7 +178,7 @@ c->time_base.den = d/g; c->time_base.num = n/g; c->gop_size = 25; - c->pix_fmt = PIX_FMT_YUV420P; + c->pix_fmt = AV_PIX_FMT_YUV420P; if(oc->oformat->flags & AVFMT_GLOBALHEADER) c->flags |= CODEC_FLAG_GLOBAL_HEADER; @@ -208,8 +212,8 @@ } tmp_picture = NULL; - if (c->pix_fmt != PIX_FMT_YUV420P) { - tmp_picture = allocPicture(PIX_FMT_YUV420P, c->width, c->height); + if (c->pix_fmt != AV_PIX_FMT_YUV420P) { + tmp_picture = allocPicture(AV_PIX_FMT_YUV420P, c->width, c->height); if (!tmp_picture) { std::cerr << "could not allocate picture\n"; return -1; @@ -233,7 +237,7 @@ st->id = 1; AVCodecContext *c; c = st->codec; - c->codec_id = CODEC_ID_MP3; //fmt->audio_codec; + c->codec_id = AV_CODEC_ID_MP3; //fmt->audio_codec; c->codec_type = AVMEDIA_TYPE_AUDIO; c->sample_fmt = AV_SAMPLE_FMT_S16; c->bit_rate = bitrate; @@ -265,7 +269,7 @@ audio_outbuf_size = FF_MIN_BUFFER_SIZE; audio_outbuf = (uint8_t*)av_malloc(audio_outbuf_size); audio_input_frame_size = c->frame_size; - + samples = (int16_t*)av_malloc(audio_input_frame_size * 2 * c->channels); nBufferedSamples=0; @@ -309,10 +313,10 @@ c = st->codec; - if (c->pix_fmt != PIX_FMT_YUV420P) { + if (c->pix_fmt != AV_PIX_FMT_YUV420P) { if (img_convert_ctx == NULL) { img_convert_ctx = sws_getContext(c->width, c->height, - PIX_FMT_YUV420P, + AV_PIX_FMT_YUV420P, c->width, c->height, c->pix_fmt, SWS_BICUBIC, NULL, NULL, NULL); @@ -340,6 +344,9 @@ ret = av_interleaved_write_frame(oc, &pkt); } else { + + // TODO: FFMPEG API for avcodec_encode_video2() has changed +#if 0 out_size = avcodec_encode_video(c, video_outbuf, video_outbuf_size, picture); if (out_size > 0) { AVPacket pkt; @@ -357,6 +364,9 @@ } else { ret = 0; } +#else + assert(false); +#endif } if (ret != 0) { std::cerr << "error writing video\n"; @@ -448,11 +458,13 @@ void FFMPEG_Writer::encodeAudioFrame(const int16* p) { + // TODO: FFMPEG API for avcodec_encode_audio2() has changed +#if 0 AVPacket pkt; av_init_packet(&pkt); AVCodecContext *c = audioStream->codec; - + pkt.size= avcodec_encode_audio(c, audio_outbuf, audio_outbuf_size, p); if (c->coded_frame && c->coded_frame->pts != AV_NOPTS_VALUE) @@ -465,6 +477,9 @@ std::cerr << "cannot write audio\n"; assert(false); } +#else + assert(false); +#endif } @@ -512,7 +527,7 @@ av_init_packet(&pkt); c = st->codec; - + bool cont = fillAudio(samples, audio_input_frame_size, c->channels); if (!cont) return false;