Handle ffmpeg5 channel deprecations

pull/3735/head
Isaac Connor 2023-06-19 10:57:13 -04:00
parent 2aa5de8d51
commit 070b70c26b
3 changed files with 50 additions and 3 deletions

View File

@ -100,7 +100,12 @@ public:
unsigned long long ImageSize() const { return imagesize; }
unsigned int Bytes() const { return bytes; };
int getFrequency() { return mAudioStream ? mAudioStream->codecpar->sample_rate : -1; }
int getChannels() { return mAudioStream ? mAudioStream->codecpar->channels : -1; }
int getChannels() {
#if LIBAVUTIL_VERSION_CHECK(57, 28, 100, 28, 0)
return mAudioStream ? mAudioStream->codecpar->ch_layout.nb_channels : -1; }
#else
return mAudioStream ? mAudioStream->codecpar->channels : -1; }
#endif
virtual int Brightness( int/*p_brightness*/=-1 ) { return -1; }
virtual int Hue( int/*p_hue*/=-1 ) { return -1; }

View File

@ -147,6 +147,18 @@ void zm_dump_stream_format(AVFormatContext *ic, int i, int index, int is_output)
void zm_dump_codec(const AVCodecContext *codec);
void zm_dump_codecpar(const AVCodecParameters *par);
#if LIBAVUTIL_VERSION_CHECK(57, 28, 100, 28, 0)
#define zm_dump_frame(frame, text) Debug(1, "%s: format %d %s sample_rate %" PRIu32 " nb_samples %d" \
" layout %" PRIu64 " pts %" PRId64, \
text, \
frame->format, \
av_get_sample_fmt_name((AVSampleFormat)frame->format), \
frame->sample_rate, \
frame->nb_samples, \
frame->ch_layout.u.mask, \
frame->pts \
);
#else
#define zm_dump_frame(frame, text) Debug(1, "%s: format %d %s sample_rate %" PRIu32 " nb_samples %d" \
" layout %" PRIu64 " pts %" PRId64, \
text, \
@ -157,6 +169,7 @@ void zm_dump_codecpar(const AVCodecParameters *par);
frame->channel_layout, \
frame->pts \
);
#endif
#define zm_dump_video_frame(frame, text) Debug(1, "%s: format %d %s %dx%d linesize:%dx%d pts: %" PRId64 " keyframe: %d", \
text, \

View File

@ -496,7 +496,11 @@ bool VideoStore::open() {
av_make_error_string(ret).c_str());
}
#if LIBAVUTIL_VERSION_CHECK(57, 28, 100, 28, 0)
if (audio_out_ctx->ch_layout.nb_channels > 1) {
#else
if (audio_out_ctx->channels > 1) {
#endif
Warning("Audio isn't mono, changing it.");
audio_out_ctx->channels = 1;
} else {
@ -896,6 +900,16 @@ bool VideoStore::setup_resampler() {
Error("Could not allocate FIFO");
return false;
}
#if LIBAVUTIL_VERSION_CHECK(57, 28, 100, 28, 0)
resample_ctx = swr_alloc_set_opts2(nullptr,
&audio_out_ctx->ch_layout,
audio_out_ctx->sample_fmt,
audio_out_ctx->sample_rate,
&audio_in_ctx->ch_layout,
audio_in_ctx->sample_fmt,
audio_in_ctx->sample_rate,
0, nullptr);
#else
resample_ctx = swr_alloc_set_opts(nullptr,
audio_out_ctx->channel_layout,
audio_out_ctx->sample_fmt,
@ -904,6 +918,7 @@ bool VideoStore::setup_resampler() {
audio_in_ctx->sample_fmt,
audio_in_ctx->sample_rate,
0, nullptr);
#endif
if (!resample_ctx) {
Error("Could not allocate resample context");
return false;
@ -917,14 +932,23 @@ bool VideoStore::setup_resampler() {
out_frame->nb_samples = audio_out_ctx->frame_size;
out_frame->format = audio_out_ctx->sample_fmt;
#if LIBAVUTIL_VERSION_CHECK(57, 28, 100, 28, 0)
out_frame->ch_layout = audio_out_ctx->ch_layout,
#else
out_frame->channels = audio_out_ctx->channels;
out_frame->channel_layout = audio_out_ctx->channel_layout;
#endif
out_frame->sample_rate = audio_out_ctx->sample_rate;
// The codec gives us the frame size, in samples, we calculate the size of the
// samples buffer in bytes
unsigned int audioSampleBuffer_size = av_samples_get_buffer_size(
nullptr, audio_out_ctx->channels,
nullptr,
#if LIBAVUTIL_VERSION_CHECK(57, 28, 100, 28, 0)
audio_out_ctx->ch_layout.nb_channels,
#else
audio_out_ctx->channels,
#endif
audio_out_ctx->frame_size,
audio_out_ctx->sample_fmt, 0);
converted_in_samples = reinterpret_cast<uint8_t *>(av_malloc(audioSampleBuffer_size));
@ -938,7 +962,12 @@ bool VideoStore::setup_resampler() {
// Setup the data pointers in the AVFrame
if (avcodec_fill_audio_frame(
out_frame.get(), audio_out_ctx->channels,
out_frame.get(),
#if LIBAVUTIL_VERSION_CHECK(57, 28, 100, 28, 0)
audio_out_ctx->ch_layout.nb_channels,
#else
audio_out_ctx->channels,
#endif
audio_out_ctx->sample_fmt,
(const uint8_t *)converted_in_samples,
audioSampleBuffer_size, 0) < 0) {