Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for deprecated calls in ffmpeg 7.1 #56

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ jobs:
- {os: windows-latest, r: '4.2'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-24.04, r: 'release'}
- {os: ubuntu-22.04, r: 'oldrel-1'}
- {os: ubuntu-20.04, r: 'oldrel-3'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: av
Type: Package
Title: Working with Audio and Video in R
Version: 0.9.2
Version: 0.9.3
Authors@R: person("Jeroen", "Ooms", role = c("aut", "cre"), email = "[email protected]",
comment = c(ORCID = "0000-0002-4035-0289"))
Description: Bindings to 'FFmpeg' <http://www.ffmpeg.org/> AV library for working with
Expand Down
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.9.3
- Fixes for ffmpeg 7.1
- Cleanup configure script

0.9.1
- Fixes for ffmpeg-7
- Remove redunant and deprecated calls to avcodec_close()
Expand Down
21 changes: 2 additions & 19 deletions configure
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Anticonf (tm) script by Jeroen Ooms (2020)
# Anticonf (tm) script by Jeroen Ooms (2024)
# This script will query 'pkg-config' for the required cflags and ldflags.
# If pkg-config is unavailable or does not find the library, try setting
# INCLUDE_DIR and LIB_DIR manually via e.g:
Expand All @@ -13,19 +13,6 @@ PKG_BREW_NAME="ffmpeg"
PKG_TEST_HEADER="<libavfilter/version.h>"
PKG_LIBS="-lavfilter"

# Check if FFmpeg is too old
pkg-config ${PKG_CONFIG_NAME} --max-version=5.99 2>/dev/null
if [ $? -eq 0 ]; then
echo "ERROR: Your version of FFmpeg is too old! Need at least FFmpeg (>= 3.2)" 1>&2
if [ "`lsb_release -c 2>/dev/null | grep xenial`" ]; then
echo "On Ubuntu Trusty/Xenial use our PPA: " 2>/dev/null
echo " sudo add-apt-repository -y ppa:cran/ffmpeg-3" 2>/dev/null
echo " sudo apt-get update" 2>/dev/null
echo " sudo apt-get dist-upgrade" 2>/dev/null
fi
exit 1
fi

# FFMPEG 3 and 4 include libavfilter 6.0
pkg-config ${PKG_CONFIG_NAME} --atleast-version=6 2>/dev/null
if [ $? -eq 0 ]; then
Expand Down Expand Up @@ -68,14 +55,10 @@ echo "#include $PKG_TEST_HEADER" | ${CXX} -E ${CPPFLAGS} ${PKG_CFLAGS} ${CXXFLAG
if [ $? -ne 0 ]; then
echo "-----------------------------[ ANTICONF ]----------------------------------"
echo "Configuration failed to find the $PKG_CONFIG_NAME library. Try installing:"
echo " * deb: $PKG_DEB_NAME (Debian, Ubuntu 18.04 and up)"
echo " * deb: $PKG_DEB_NAME (Debian, Ubuntu)"
echo " * rpm: $PKG_RPM_NAME (Fedora, CentOS, RHEL)"
echo " * csw: $PKG_CSW_NAME (Solaris)"
echo " * brew: $PKG_BREW_NAME (MacOS)"
echo "For Ubuntu Trusty (14.04) and Xenial (16.04) use this PPA:"
echo " sudo add-apt-repository -y ppa:cran/ffmpeg-3"
echo " sudo apt-get update"
echo " sudo apt-get install -y $PKG_DEB_NAME"
echo "If $PKG_CONFIG_NAME is already installed, check that 'pkg-config' is in your"
echo "PATH and PKG_CONFIG_PATH contains a $PKG_CONFIG_NAME.pc file. If pkg-config"
echo "is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:"
Expand Down
5 changes: 5 additions & 0 deletions src/avcompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
#if LIBAVUTIL_VERSION_MAJOR > 58 || (LIBAVUTIL_VERSION_MAJOR == 58 && LIBAVUTIL_VERSION_MINOR >= 29)
#define NEW_FFT_TX_API
#endif

/* Old FFT API was marked deprecated in ffmpeg 7.1 */
#if LIBAVUTIL_VERSION_MAJOR > 59 || (LIBAVUTIL_VERSION_MAJOR == 59 && LIBAVUTIL_VERSION_MINOR >= 39)
#define NEW_DEFAULT_CODEC_API
#endif
31 changes: 27 additions & 4 deletions src/formats.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@
#include <libavformat/version.h>
#include <libavfilter/avfilter.h>
#include <libavutil/pixdesc.h>
#include "avcompat.h"

enum AVPixelFormat get_default_pix_fmt(const AVCodec *codec){
#ifdef NEW_DEFAULT_CODEC_API
const enum AVPixelFormat *p = NULL;
if(avcodec_get_supported_config(NULL, codec, AV_CODEC_CONFIG_PIX_FORMAT, 0, (const void **) &p, NULL) < 0 || p == NULL)
return AV_PIX_FMT_NONE;
return *p;
#else
return codec->pix_fmts ? codec->pix_fmts[0] : AV_PIX_FMT_NONE;
#endif
}

enum AVSampleFormat get_default_sample_fmt(const AVCodec *codec){
#ifdef NEW_DEFAULT_CODEC_API
const enum AVSampleFormat *p = NULL;
if(avcodec_get_supported_config(NULL, codec, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, (const void **) &p, NULL) < 0 || p == NULL)
return AV_SAMPLE_FMT_NONE;
return *p;
#else
return codec->sample_fmts ? codec->sample_fmts[0] : AV_SAMPLE_FMT_NONE;
#endif
}

static SEXP safe_string(const char *x){
if(x == NULL)
Expand Down Expand Up @@ -43,10 +66,10 @@ SEXP R_list_codecs(void){
SET_STRING_ELT(name, i, safe_string(codec->name));
SET_STRING_ELT(desc, i, safe_string(codec->long_name));
LOGICAL(enc)[i] = av_codec_is_encoder(codec);
if(codec->type == AVMEDIA_TYPE_AUDIO && codec->sample_fmts){
SET_STRING_ELT(fmt, i, safe_string(av_get_sample_fmt_name(codec->sample_fmts[0])));
} else if(codec->type == AVMEDIA_TYPE_VIDEO && codec->pix_fmts){
SET_STRING_ELT(fmt, i, safe_string(av_get_pix_fmt_name(codec->pix_fmts[0])));
if(codec->type == AVMEDIA_TYPE_AUDIO){
SET_STRING_ELT(fmt, i, safe_string(av_get_sample_fmt_name(get_default_sample_fmt(codec))));
} else if(codec->type == AVMEDIA_TYPE_VIDEO){
SET_STRING_ELT(fmt, i, safe_string(av_get_pix_fmt_name(get_default_pix_fmt(codec))));
}
i++;
}
Expand Down
9 changes: 6 additions & 3 deletions src/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include <Rinternals.h>
#include "avcompat.h"

enum AVPixelFormat get_default_pix_fmt(const AVCodec *codec);
enum AVSampleFormat get_default_sample_fmt(const AVCodec *codec);

int total_open_handles = 0;

typedef struct {
Expand Down Expand Up @@ -321,7 +324,7 @@ static void add_video_output(output_container *output, int width, int height){
//video_encoder->gop_size = 25; //one keyframe every 25 frames

/* Try to use codec preferred pixel format, otherwise default to YUV420 */
video_encoder->pix_fmt = output->codec->pix_fmts ? output->codec->pix_fmts[0] : AV_PIX_FMT_YUV420P;
video_encoder->pix_fmt = get_default_pix_fmt(output->codec);
if (output->muxer->oformat->flags & AVFMT_GLOBALHEADER)
video_encoder->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;

Expand Down Expand Up @@ -356,7 +359,7 @@ static void add_audio_output(output_container *container){
#endif
audio_encoder->sample_rate = container->sample_rate ? container->sample_rate : audio_decoder->sample_rate;
audio_encoder->bit_rate = container->bit_rate ? container->bit_rate : audio_decoder->bit_rate;
audio_encoder->sample_fmt = output_codec->sample_fmts[0];
audio_encoder->sample_fmt = get_default_sample_fmt(output_codec);
audio_encoder->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;

/* Add the audio_stream to the muxer */
Expand Down Expand Up @@ -529,7 +532,7 @@ static int encode_output_frames(output_container *output){
* a copy of that frame when we finalize the video.
*/
static int feed_to_filter(AVFrame * image, output_container *output){
enum AVPixelFormat pix_fmt = output->codec->pix_fmts ? output->codec->pix_fmts[0] : AV_PIX_FMT_YUV420P;
enum AVPixelFormat pix_fmt = get_default_pix_fmt(output->codec);
static AVFrame *previous = NULL;
if(previous == NULL)
previous = av_frame_alloc();
Expand Down
Loading