From 3d4a357f952dd6ab85e4ac065472d7814365ab84 Mon Sep 17 00:00:00 2001 From: Darrell Walisser Date: Fri, 26 Jan 2018 12:13:54 -0500 Subject: [PATCH] Update for FFmpeg 3.5 --- src/FFmpeg.cpp | 2 ++ src/FFmpeg.h | 19 +++++++++++++++++++ src/export/ExportFFmpeg.cpp | 9 +++++---- src/export/ExportFFmpegDialogs.cpp | 10 ++++++++++ src/import/ImportFFmpeg.cpp | 17 +++++++++++------ 5 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/FFmpeg.cpp b/src/FFmpeg.cpp index 4521a95c3..dbd62c7d1 100644 --- a/src/FFmpeg.cpp +++ b/src/FFmpeg.cpp @@ -883,6 +883,7 @@ bool FFmpegLibs::InitLibs(const wxString &libpath_format, bool WXUNUSED(showerr) FFMPEG_INITDYN(avcodec, avcodec_find_encoder); FFMPEG_INITDYN(avcodec, avcodec_find_encoder_by_name); FFMPEG_INITDYN(avcodec, avcodec_find_decoder); + FFMPEG_INITDYN(avcodec, avcodec_get_name); FFMPEG_INITDYN(avcodec, avcodec_open2); FFMPEG_INITDYN(avcodec, avcodec_decode_audio4); FFMPEG_INITDYN(avcodec, avcodec_encode_audio2); @@ -913,6 +914,7 @@ bool FFmpegLibs::InitLibs(const wxString &libpath_format, bool WXUNUSED(showerr) FFMPEG_INITALT(avutil, av_frame_alloc, avcodec, avcodec_alloc_frame); FFMPEG_INITALT(avutil, av_frame_free, avcodec, avcodec_free_frame); FFMPEG_INITDYN(avutil, av_samples_get_buffer_size); + FFMPEG_INITDYN(avutil, av_get_default_channel_layout); wxLogMessage(wxT("All symbols loaded successfully. Initializing the library.")); #endif diff --git a/src/FFmpeg.h b/src/FFmpeg.h index 30fb2fcc9..6b8da4a71 100644 --- a/src/FFmpeg.h +++ b/src/FFmpeg.h @@ -128,6 +128,13 @@ extern "C" { } #endif #endif + + #if LIBAVCODEC_VERSION_MAJOR < 58 + #define AV_CODEC_FLAG_QSCALE CODEC_FLAG_QSCALE + #define AV_CODEC_FLAG_GLOBAL_HEADER CODEC_FLAG_GLOBAL_HEADER + #define AV_CODEC_CAP_SMALL_LAST_FRAME CODEC_CAP_SMALL_LAST_FRAME + #endif + } #endif @@ -535,6 +542,12 @@ extern "C" { (void *ptr), (ptr) ); + FFMPEG_FUNCTION_WITH_RETURN( + int64_t, + av_get_default_channel_layout, + (int nb_channels), + (nb_channels) + ); // // libavcodec @@ -563,6 +576,12 @@ extern "C" { (enum AVCodecID id), (id) ); + FFMPEG_FUNCTION_WITH_RETURN( + const char*, + avcodec_get_name, + (enum AVCodecID id), + (id) + ); FFMPEG_FUNCTION_WITH_RETURN( unsigned int, av_codec_get_tag, diff --git a/src/export/ExportFFmpeg.cpp b/src/export/ExportFFmpeg.cpp index 0e81fc4c3..c9a45c4e2 100644 --- a/src/export/ExportFFmpeg.cpp +++ b/src/export/ExportFFmpeg.cpp @@ -465,12 +465,13 @@ bool ExportFFmpeg::InitCodecs(AudacityProject *project) if (mEncAudioCodecCtx->global_quality >= 0) { - mEncAudioCodecCtx->flags |= CODEC_FLAG_QSCALE; + mEncAudioCodecCtx->flags |= AV_CODEC_FLAG_QSCALE; } else mEncAudioCodecCtx->global_quality = 0; mEncAudioCodecCtx->global_quality = mEncAudioCodecCtx->global_quality * FF_QP2LAMBDA; mEncAudioCodecCtx->sample_rate = mSampleRate; mEncAudioCodecCtx->channels = mChannels; + mEncAudioCodecCtx->channel_layout = av_get_default_channel_layout(mChannels); mEncAudioCodecCtx->time_base.num = 1; mEncAudioCodecCtx->time_base.den = mEncAudioCodecCtx->sample_rate; mEncAudioCodecCtx->sample_fmt = AV_SAMPLE_FMT_S16; @@ -519,8 +520,8 @@ bool ExportFFmpeg::InitCodecs(AudacityProject *project) if (mEncFormatCtx->oformat->flags & AVFMT_GLOBALHEADER) { - mEncAudioCodecCtx->flags |= CODEC_FLAG_GLOBAL_HEADER; - mEncFormatCtx->flags |= CODEC_FLAG_GLOBAL_HEADER; + mEncAudioCodecCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; + mEncFormatCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; } // Open the codec. @@ -689,7 +690,7 @@ bool ExportFFmpeg::Finalize() // Or if frame_size is 1, then it's some kind of PCM codec, they don't have frames and will be fine with the samples // Otherwise we'll send a full frame of audio + silence padding to ensure all audio is encoded int frame_size = default_frame_size; - if (mEncAudioCodecCtx->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME || + if (mEncAudioCodecCtx->codec->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME || frame_size == 1) frame_size = nFifoBytes / (mEncAudioCodecCtx->channels * sizeof(int16_t)); diff --git a/src/export/ExportFFmpegDialogs.cpp b/src/export/ExportFFmpegDialogs.cpp index 16f64ee81..c1d813228 100644 --- a/src/export/ExportFFmpegDialogs.cpp +++ b/src/export/ExportFFmpegDialogs.cpp @@ -931,7 +931,9 @@ CompatibilityEntry ExportFFmpegOptions::CompatibilityList[] = { wxT("asf"), AV_CODEC_ID_ADPCM_G726 }, { wxT("asf"), AV_CODEC_ID_MP2 }, { wxT("asf"), AV_CODEC_ID_MP3 }, +#if LIBAVCODEC_VERSION_MAJOR < 58 { wxT("asf"), AV_CODEC_ID_VOXWARE }, +#endif { wxT("asf"), AV_CODEC_ID_AAC }, { wxT("asf"), AV_CODEC_ID_WMAV1 }, { wxT("asf"), AV_CODEC_ID_WMAV2 }, @@ -965,7 +967,9 @@ CompatibilityEntry ExportFFmpegOptions::CompatibilityList[] = { wxT("avi"), AV_CODEC_ID_ADPCM_G726 }, { wxT("avi"), AV_CODEC_ID_MP2 }, { wxT("avi"), AV_CODEC_ID_MP3 }, +#if LIBAVCODEC_VERSION_MAJOR < 58 { wxT("avi"), AV_CODEC_ID_VOXWARE }, +#endif { wxT("avi"), AV_CODEC_ID_AAC }, { wxT("avi"), AV_CODEC_ID_WMAV1 }, { wxT("avi"), AV_CODEC_ID_WMAV2 }, @@ -1012,7 +1016,9 @@ CompatibilityEntry ExportFFmpegOptions::CompatibilityList[] = { wxT("matroska"), AV_CODEC_ID_ADPCM_G726 }, { wxT("matroska"), AV_CODEC_ID_MP2 }, { wxT("matroska"), AV_CODEC_ID_MP3 }, +#if LIBAVCODEC_VERSION_MAJOR < 58 { wxT("matroska"), AV_CODEC_ID_VOXWARE }, +#endif { wxT("matroska"), AV_CODEC_ID_AAC }, { wxT("matroska"), AV_CODEC_ID_WMAV1 }, { wxT("matroska"), AV_CODEC_ID_WMAV2 }, @@ -1118,7 +1124,9 @@ CompatibilityEntry ExportFFmpegOptions::CompatibilityList[] = { wxT("nut"), AV_CODEC_ID_ADPCM_G726 }, { wxT("nut"), AV_CODEC_ID_MP2 }, { wxT("nut"), AV_CODEC_ID_MP3 }, + #if LIBAVCODEC_VERSION_MAJOR < 58 { wxT("nut"), AV_CODEC_ID_VOXWARE }, + #endif { wxT("nut"), AV_CODEC_ID_AAC }, { wxT("nut"), AV_CODEC_ID_WMAV1 }, { wxT("nut"), AV_CODEC_ID_WMAV2 }, @@ -1166,7 +1174,9 @@ CompatibilityEntry ExportFFmpegOptions::CompatibilityList[] = { wxT("wav"), AV_CODEC_ID_ADPCM_G726 }, { wxT("wav"), AV_CODEC_ID_MP2 }, { wxT("wav"), AV_CODEC_ID_MP3 }, +#if LIBAVCODEC_VERSION_MAJOR < 58 { wxT("wav"), AV_CODEC_ID_VOXWARE }, +#endif { wxT("wav"), AV_CODEC_ID_AAC }, { wxT("wav"), AV_CODEC_ID_WMAV1 }, { wxT("wav"), AV_CODEC_ID_WMAV2 }, diff --git a/src/import/ImportFFmpeg.cpp b/src/import/ImportFFmpeg.cpp index c044c8d13..132d9a8bd 100644 --- a/src/import/ImportFFmpeg.cpp +++ b/src/import/ImportFFmpeg.cpp @@ -404,23 +404,27 @@ bool FFmpegImportFileHandle::InitCodecs() sc->m_stream = mFormatContext->streams[i]; sc->m_codecCtx = sc->m_stream->codec; - AVCodec *codec = avcodec_find_decoder(sc->m_codecCtx->codec_id); + const AVCodecID id = sc->m_codecCtx->codec_id; + const char* name = avcodec_get_name(id); + const AVCodec *codec = avcodec_find_decoder(id); + if (codec == NULL) { - wxLogError(wxT("FFmpeg : avcodec_find_decoder() failed. Index[%02d], Codec[%02x - %s]"),i,sc->m_codecCtx->codec_id,sc->m_codecCtx->codec_name); + wxLogError(wxT("FFmpeg : avcodec_find_decoder() failed. Index[%02d], Codec[%02x - %s]"),i,id,name); //FFmpeg can't decode this stream, skip it continue; } + if (codec->type != sc->m_codecCtx->codec_type) { - wxLogError(wxT("FFmpeg : Codec type mismatch, skipping. Index[%02d], Codec[%02x - %s]"),i,sc->m_codecCtx->codec_id,sc->m_codecCtx->codec_name); + wxLogError(wxT("FFmpeg : Codec type mismatch, skipping. Index[%02d], Codec[%02x - %s]"),i,id,name); //Non-audio codec reported as audio? Nevertheless, we don't need THIS. continue; } if (avcodec_open2(sc->m_codecCtx, codec, NULL) < 0) { - wxLogError(wxT("FFmpeg : avcodec_open() failed. Index[%02d], Codec[%02x - %s]"),i,sc->m_codecCtx->codec_id,sc->m_codecCtx->codec_name); + wxLogError(wxT("FFmpeg : avcodec_open() failed. Index[%02d], Codec[%02x - %s]"),i,id,name); //Can't open decoder - skip this stream continue; } @@ -434,7 +438,7 @@ bool FFmpegImportFileHandle::InitCodecs() duration = mFormatContext->duration / AV_TIME_BASE; wxString bitrate = wxT(""); if (sc->m_codecCtx->bit_rate > 0) - bitrate.Printf(wxT("%d"),sc->m_codecCtx->bit_rate); + bitrate.Printf(wxT("%d"),(int)sc->m_codecCtx->bit_rate); else bitrate.Printf(wxT("?")); @@ -444,7 +448,8 @@ bool FFmpegImportFileHandle::InitCodecs() { lang.FromUTF8(tag->value); } - strinfo.Printf(_("Index[%02x] Codec[%s], Language[%s], Bitrate[%s], Channels[%d], Duration[%d]"),sc->m_stream->id,codec->name,lang,bitrate,sc->m_stream->codec->channels, duration); + strinfo.Printf(_("Index[%02x] Codec[%s], Language[%s], Bitrate[%s], Channels[%d], Duration[%d]"), + sc->m_stream->id,codec->name,lang,bitrate,(int)sc->m_stream->codec->channels,(int)duration); mStreamInfo.Add(strinfo); mScs->get()[mNumStreams++] = std::move(sc); }