Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0x9fff00/b12743fb93e67c19c28ec407894717b6 to your computer and use it in GitHub Desktop.
Save 0x9fff00/b12743fb93e67c19c28ec407894717b6 to your computer and use it in GitHub Desktop.
From 7fa3249c17a272ec4884c7867bf11cc1f914219e Mon Sep 17 00:00:00 2001
From: 0x9fff00 <0x9fff00+git@protonmail.ch>
Date: Wed, 6 Mar 2019 22:48:39 +0100
Subject: [PATCH] Fix compatibility with new versions of ffmpeg
---
configure.ac | 4 ++--
src/cimgffmpeg.cpp | 30 +++++++++++++++---------------
2 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/configure.ac b/configure.ac
index d20a139..55d6d27 100644
--- a/configure.ac
+++ b/configure.ac
@@ -122,9 +122,9 @@ fi])
AC_DEFUN([AC_CHECK_FFMPEG],
[
AC_MSG_CHECKING([whether FFmpeg is present])
-AC_CHECK_LIB([avcodec], [avcodec_alloc_frame], [], [AC_MSG_ERROR([
+AC_CHECK_LIB([avutil], [av_frame_alloc], [], [AC_MSG_ERROR([
-*** libavcodec not found.
+*** libavutil not found.
You need FFmpeg. Get it at <http://ffmpeg.org/>])])
AC_CHECK_LIB([avutil], [av_log_set_level], [], [AC_MSG_ERROR([
diff --git a/src/cimgffmpeg.cpp b/src/cimgffmpeg.cpp
index 7df0ff1..6ebd425 100644
--- a/src/cimgffmpeg.cpp
+++ b/src/cimgffmpeg.cpp
@@ -39,11 +39,11 @@ void vfinfo_close(VFInfo *vfinfo){
int ReadFrames(VFInfo *st_info, CImgList<uint8_t> *pFrameList, unsigned int low_index, unsigned int hi_index)
{
//target pixel format
- PixelFormat ffmpeg_pixfmt;
+ AVPixelFormat ffmpeg_pixfmt;
if (st_info->pixelformat == 0)
- ffmpeg_pixfmt = PIX_FMT_GRAY8;
+ ffmpeg_pixfmt = AV_PIX_FMT_GRAY8;
else
- ffmpeg_pixfmt = PIX_FMT_RGB24;
+ ffmpeg_pixfmt = AV_PIX_FMT_RGB24;
st_info->next_index = low_index;
@@ -100,12 +100,12 @@ int ReadFrames(VFInfo *st_info, CImgList<uint8_t> *pFrameList, unsigned int low_
AVFrame *pFrame;
// Allocate video frame
- pFrame=avcodec_alloc_frame();
+ pFrame=av_frame_alloc();
if (pFrame==NULL)
return -1;
// Allocate an AVFrame structure
- AVFrame *pConvertedFrame = avcodec_alloc_frame();
+ AVFrame *pConvertedFrame = av_frame_alloc();
if(pConvertedFrame==NULL)
return -1;
@@ -123,7 +123,7 @@ int ReadFrames(VFInfo *st_info, CImgList<uint8_t> *pFrameList, unsigned int low_
int size = 0;
- int channels = ffmpeg_pixfmt == PIX_FMT_GRAY8 ? 1 : 3;
+ int channels = ffmpeg_pixfmt == AV_PIX_FMT_GRAY8 ? 1 : 3;
AVPacket packet;
int result = 1;
@@ -189,11 +189,11 @@ int ReadFrames(VFInfo *st_info, CImgList<uint8_t> *pFrameList, unsigned int low_
int NextFrames(VFInfo *st_info, CImgList<uint8_t> *pFrameList)
{
- PixelFormat ffmpeg_pixfmt;
+ AVPixelFormat ffmpeg_pixfmt;
if (st_info->pixelformat == 0)
- ffmpeg_pixfmt = PIX_FMT_GRAY8;
+ ffmpeg_pixfmt = AV_PIX_FMT_GRAY8;
else
- ffmpeg_pixfmt = PIX_FMT_RGB24;
+ ffmpeg_pixfmt = AV_PIX_FMT_RGB24;
if (st_info->pFormatCtx == NULL)
{
@@ -254,10 +254,10 @@ int NextFrames(VFInfo *st_info, CImgList<uint8_t> *pFrameList)
AVFrame *pFrame;
// Allocate video frame
- pFrame=avcodec_alloc_frame();
+ pFrame=av_frame_alloc();
// Allocate an AVFrame structure
- AVFrame *pConvertedFrame = avcodec_alloc_frame();
+ AVFrame *pConvertedFrame = av_frame_alloc();
if(pConvertedFrame==NULL){
return -1;
}
@@ -287,7 +287,7 @@ int NextFrames(VFInfo *st_info, CImgList<uint8_t> *pFrameList)
break;
if(packet.stream_index == st_info->videoStream) {
- int channels = ffmpeg_pixfmt == PIX_FMT_GRAY8 ? 1 : 3;
+ int channels = ffmpeg_pixfmt == AV_PIX_FMT_GRAY8 ? 1 : 3;
AVPacket avpkt;
av_init_packet(&avpkt);
avpkt.data = packet.data;
@@ -344,7 +344,7 @@ int NextFrames(VFInfo *st_info, CImgList<uint8_t> *pFrameList)
int GetNumberStreams(const char *file)
{
- AVFormatContext *pFormatCtx;
+ AVFormatContext *pFormatCtx = NULL;
av_log_set_level(AV_LOG_QUIET);
av_register_all();
// Open video file
@@ -362,7 +362,7 @@ int GetNumberStreams(const char *file)
long GetNumberVideoFrames(const char *file)
{
long nb_frames = 0L;
- AVFormatContext *pFormatCtx;
+ AVFormatContext *pFormatCtx = NULL;
av_log_set_level(AV_LOG_QUIET);
av_register_all();
// Open video file
@@ -408,7 +408,7 @@ long GetNumberVideoFrames(const char *file)
float fps(const char *filename)
{
float result = 0;
- AVFormatContext *pFormatCtx;
+ AVFormatContext *pFormatCtx = NULL;
// Open video file
if (avformat_open_input(&pFormatCtx, filename, NULL, NULL))
--
2.21.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment