From 63946512aa9d58ddb68ed8f508a6ec066cf4a69f Mon Sep 17 00:00:00 2001 From: Fancy code <258828110.@qq.com> Date: Mon, 8 Jul 2024 11:23:22 +0800 Subject: [PATCH] Improve:audio encoder. --- CMakeLists.txt | 6 ++---- utils/MediaBase/src/FfmpegEncoder.cpp | 7 +++++-- utils/MediaBase/src/FfmpegMuxStreamV2.cpp | 1 - utils/MediaBase/src/FfmpegMuxStreamV2.h | 9 +++++++++ utils/MediaBase/src/FfmpegOutputStream.cpp | 11 ----------- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d368b34..8977d6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,10 +102,8 @@ if ("${CLANG_TIDY_SUPPORT}" MATCHES "true") message(FATAL_ERROR "You set support clang-tidy, but clang-tidy not found. Check path ${LLVM_PATH}/build/bin, weather clang-tidy exist. How to install tools? -See ${IPC_SDK_PATH}/doc/clang-tidy_user_guide.md -How to disable clang-tidy tool? -Modify: set(CLANG_TIDY_SUPPORT \"false\") -See:${IPC_SDK_PATH}/builde/global_config.cmake") +Execute : make compile_llvm (in the project root directory) +Or see ${CMAKE_SOURCE_DIR_IPCSDK}/doc/clang-tidy_user_guide.md") endif() endif() # find the clang-format tools diff --git a/utils/MediaBase/src/FfmpegEncoder.cpp b/utils/MediaBase/src/FfmpegEncoder.cpp index 1962242..9918c83 100644 --- a/utils/MediaBase/src/FfmpegEncoder.cpp +++ b/utils/MediaBase/src/FfmpegEncoder.cpp @@ -71,7 +71,8 @@ bool FfmpegEncoder::Init(int &outputFlags) switch (mCodec->type) { case AVMEDIA_TYPE_AUDIO: mCodecCtx->sample_fmt = mCodec->sample_fmts ? mCodec->sample_fmts[0] : AV_SAMPLE_FMT_FLTP; - mCodecCtx->bit_rate = 64000; + // mCodecCtx->bit_rate = 64000; + mCodecCtx->bit_rate = 24000; mCodecCtx->sample_rate = 44100; if (mCodec->supported_samplerates) { mCodecCtx->sample_rate = mCodec->supported_samplerates[0]; @@ -81,7 +82,9 @@ bool FfmpegEncoder::Init(int &outputFlags) } } mCodecCtx->sample_rate = 8000; - av_channel_layout_copy(&mCodecCtx->ch_layout, &src); + mCodecCtx->ch_layout.nb_channels = 1; + av_channel_layout_default(&mCodecCtx->ch_layout, 1); + // av_channel_layout_copy(&mCodecCtx->ch_layout, &src); break; case AVMEDIA_TYPE_VIDEO: diff --git a/utils/MediaBase/src/FfmpegMuxStreamV2.cpp b/utils/MediaBase/src/FfmpegMuxStreamV2.cpp index fbc736d..ec61fd2 100644 --- a/utils/MediaBase/src/FfmpegMuxStreamV2.cpp +++ b/utils/MediaBase/src/FfmpegMuxStreamV2.cpp @@ -84,7 +84,6 @@ void FfmpegMuxStreamV2::GetStreamData(const void *data, const size_t &size, cons return; } } - LogInfo("Write frame size: %zu.\n", size); if (streamInfo.mType == STREAM_TYPE_VIDEO_H264 && mVideoStream) { mVideoStream->WriteSourceData(data, size); } diff --git a/utils/MediaBase/src/FfmpegMuxStreamV2.h b/utils/MediaBase/src/FfmpegMuxStreamV2.h index 3d429de..2cf715d 100644 --- a/utils/MediaBase/src/FfmpegMuxStreamV2.h +++ b/utils/MediaBase/src/FfmpegMuxStreamV2.h @@ -54,6 +54,15 @@ private: void GetAVPacketDataCallback(AVPacket *pkt); private: + /** + * @brief Add media streams (audio streams or video streams) to the output file. If the input stream data needs to + * be encoded or decoded, set the matching encoder/decoder parameters as needed.The AV_CODEC_ID_NONE parameter means + * that no codec needs to be set. + * @param outputFormat + * @param encodecId + * @param decodecId + * @return std::shared_ptr + */ static std::shared_ptr AddStream(AVFormatContext *outputFormat, enum AVCodecID encodecId, enum AVCodecID decodecId); diff --git a/utils/MediaBase/src/FfmpegOutputStream.cpp b/utils/MediaBase/src/FfmpegOutputStream.cpp index ca8620c..a1103ab 100644 --- a/utils/MediaBase/src/FfmpegOutputStream.cpp +++ b/utils/MediaBase/src/FfmpegOutputStream.cpp @@ -65,11 +65,6 @@ bool FfmpegOutputStream::Init(AVFormatContext *outputFormat) } else { mStream->time_base = (AVRational){1, 15}; - // int ret = avcodec_parameters_copy(mStream->codecpar, in_codecpar); - // if (ret < 0) { - // LogError("Failed to copy codec parameters\n"); - // return false; - // } mStream->codecpar->codec_id = AV_CODEC_ID_H264; mStream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; mStream->codecpar->width = 1920; @@ -79,12 +74,6 @@ bool FfmpegOutputStream::Init(AVFormatContext *outputFormat) mStream->codecpar->codec_tag = 0; mStream->codecpar->extradata = nullptr; mStream->codecpar->extradata_size = 0; - // mEncoder = std::make_shared(AV_CODEC_ID_MPEG4); - // mEncoder->Init(outputFormat->flags); - // mStream->time_base = mEncoder->GetTimeBase(); - // mEncoder->OpenEncoder(nullptr, mStream); - // mEncoder->UnInit(); - // mEncoder.reset(); } return true; }