From 5f9508434f655f3b506b02a8f938f3e8a4ffca95 Mon Sep 17 00:00:00 2001 From: Mike Solar Date: Wed, 18 Jun 2025 08:54:06 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=9B=BE=E8=A7=A3=E5=86=B3=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ app/codec/encoder.cpp | 2 +- app/codec/encoder.h | 2 +- app/codec/ffmpeg/ffmpegdecoder.cpp | 42 ++++++++++++++++-------------- app/codec/ffmpeg/ffmpegdecoder.h | 2 +- app/codec/ffmpeg/ffmpegencoder.cpp | 15 +++++------ ext/core | 2 +- 7 files changed, 35 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index b10c5cddf..709591a14 100644 --- a/.gitignore +++ b/.gitignore @@ -98,3 +98,5 @@ compile_flags.txt *creator.user* *_qmlcache.qrc +.idea/ +.idea \ No newline at end of file diff --git a/app/codec/encoder.cpp b/app/codec/encoder.cpp index 810cdcd1b..dce8a3a18 100644 --- a/app/codec/encoder.cpp +++ b/app/codec/encoder.cpp @@ -256,7 +256,7 @@ void EncodingParams::Save(QXmlStreamWriter *writer) const if (audio_enabled_) { writer->writeTextElement(QStringLiteral("codec"), QString::number(audio_codec_)); writer->writeTextElement(QStringLiteral("samplerate"), QString::number(audio_params_.sample_rate())); - writer->writeTextElement(QStringLiteral("channellayout"), QString::number(audio_params_.channel_layout())); + writer->writeTextElement(QStringLiteral("channellayout"), QString::number()); writer->writeTextElement(QStringLiteral("format"), QString::fromStdString(audio_params_.format().to_string())); writer->writeTextElement(QStringLiteral("bitrate"), QString::number(audio_bit_rate_)); } diff --git a/app/codec/encoder.h b/app/codec/encoder.h index 65702a36f..c5554f699 100644 --- a/app/codec/encoder.h +++ b/app/codec/encoder.h @@ -33,7 +33,7 @@ #include "render/colortransform.h" #include "render/subtitleparams.h" #include "render/videoparams.h" - +//这个代码也许是创建工程文件用的?还是导出编码视频用的? namespace olive { class Encoder; diff --git a/app/codec/ffmpeg/ffmpegdecoder.cpp b/app/codec/ffmpeg/ffmpegdecoder.cpp index 938ff3f22..59bba7ade 100644 --- a/app/codec/ffmpeg/ffmpegdecoder.cpp +++ b/app/codec/ffmpeg/ffmpegdecoder.cpp @@ -439,9 +439,9 @@ FootageDescription FFmpegDecoder::Probe(const QString &filename, CancelAtom *can } else if (avstream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { // Create an audio stream object - uint64_t channel_layout = avstream->codecpar->channel_layout; - if (!channel_layout) { - channel_layout = static_cast(av_get_default_channel_layout(avstream->codecpar->channels)); + AVChannelLayout channel_layout = avstream->codecpar->ch_layout; + if (!channel_layout.nb_channels==0) { + av_channel_layout_default(&channel_layout,avstream->codecpar->ch_layout.nb_channels); } if (avstream->duration == AV_NOPTS_VALUE || duration_guessed_from_bitrate) { @@ -551,22 +551,23 @@ bool FFmpegDecoder::ConformAudioInternal(const QVector &filenames, cons instance_.Seek(0); // Handle NULL channel layout - uint64_t channel_layout = ValidateChannelLayout(instance_.avstream()); - if (!channel_layout) { + AVChannelLayout channel_layout = ValidateChannelLayout(instance_.avstream()); + if (!av_channel_layout_check(&channel_layout)) { qCritical() << "Failed to determine channel layout of audio file, could not conform"; return false; } - // Create resampling context - SwrContext* resampler = swr_alloc_set_opts(nullptr, - params.channel_layout(), - FFmpegUtils::GetFFmpegSampleFormat(params.format()), - params.sample_rate(), - channel_layout, - static_cast(instance_.avstream()->codecpar->format), - instance_.avstream()->codecpar->sample_rate, - 0, - nullptr); + AVChannelLayout layout=params.channel_layout(); + SwrContext* resampler; + swr_alloc_set_opts2(&resampler, + &layout, + FFmpegUtils::GetFFmpegSampleFormat(params.format()), + params.sample_rate(), + &channel_layout, + static_cast(instance_.avstream()->codecpar->format), + instance_.avstream()->codecpar->sample_rate, + 0, + nullptr); swr_init(resampler); @@ -689,13 +690,14 @@ int FFmpegDecoder::GetNativeChannelCount(AVPixelFormat pix_fmt) } } -uint64_t FFmpegDecoder::ValidateChannelLayout(AVStream* stream) +AVChannelLayout FFmpegDecoder::ValidateChannelLayout(AVStream* stream) { - if (stream->codecpar->channel_layout) { - return stream->codecpar->channel_layout; + if (av_channel_layout_check(&stream->codecpar->ch_layout)) { + return stream->codecpar->ch_layout; } - - return av_get_default_channel_layout(stream->codecpar->channels); + AVChannelLayout layout; + av_channel_layout_default(&layout,stream->codecpar->ch_layout.nb_channels); + return layout; } const char *FFmpegDecoder::GetInterlacingModeInFFmpeg(VideoParams::Interlacing interlacing) diff --git a/app/codec/ffmpeg/ffmpegdecoder.h b/app/codec/ffmpeg/ffmpegdecoder.h index bc3723374..52be8154f 100644 --- a/app/codec/ffmpeg/ffmpegdecoder.h +++ b/app/codec/ffmpeg/ffmpegdecoder.h @@ -139,7 +139,7 @@ private: static PixelFormat GetNativePixelFormat(AVPixelFormat pix_fmt); static int GetNativeChannelCount(AVPixelFormat pix_fmt); - static uint64_t ValidateChannelLayout(AVStream *stream); + static AVChannelLayout ValidateChannelLayout(AVStream *stream); static const char* GetInterlacingModeInFFmpeg(VideoParams::Interlacing interlacing); diff --git a/app/codec/ffmpeg/ffmpegencoder.cpp b/app/codec/ffmpeg/ffmpegencoder.cpp index f5ca225a4..fbe6f33a0 100644 --- a/app/codec/ffmpeg/ffmpegencoder.cpp +++ b/app/codec/ffmpeg/ffmpegencoder.cpp @@ -349,7 +349,7 @@ bool FFmpegEncoder::WriteAudioData(const AudioParams &audio_params, const uint8_ av_samples_copy(audio_frame_->data, output_data, audio_frame_offset_, i, copy_length, - audio_frame_->channels, static_cast(audio_frame_->format)); + audio_frame_->ch_layout.nb_channels, static_cast(audio_frame_->format)); audio_frame_offset_ += copy_length; i += copy_length; @@ -690,8 +690,7 @@ bool FFmpegEncoder::InitializeStream(AVMediaType type, AVStream** stream_ptr, AV // Assume audio stream codec_ctx->sample_rate = params().audio_params().sample_rate(); - codec_ctx->channel_layout = params().audio_params().channel_layout(); - codec_ctx->channels = av_get_channel_layout_nb_channels(codec_ctx->channel_layout); + codec_ctx->ch_layout = params().audio_params().channel_layout(); codec_ctx->sample_fmt = FFmpegUtils::GetFFmpegSampleFormat(params().audio_params().format()); codec_ctx->time_base = {1, codec_ctx->sample_rate}; @@ -827,13 +826,13 @@ bool FFmpegEncoder::InitializeResampleContext(const AudioParams &audio) if (audio_resample_ctx_) { return true; } - + AVChannelLayout layout=audio.channel_layout(); // Create resample context - audio_resample_ctx_ = swr_alloc_set_opts(nullptr, - static_cast(audio_codec_ctx_->channel_layout), + swr_alloc_set_opts2(&audio_resample_ctx_, + &audio_codec_ctx_->ch_layout, audio_codec_ctx_->sample_fmt, audio_codec_ctx_->sample_rate, - static_cast(audio.channel_layout()), + &layout, FFmpegUtils::GetFFmpegSampleFormat(audio.format()), audio.sample_rate(), 0, @@ -865,7 +864,7 @@ bool FFmpegEncoder::InitializeResampleContext(const AudioParams &audio) return false; } - audio_frame_->channel_layout = audio_codec_ctx_->channel_layout; + audio_frame_->ch_layout = audio_codec_ctx_->ch_layout; audio_frame_->format = audio_codec_ctx_->sample_fmt; audio_frame_->nb_samples = audio_max_samples_; diff --git a/ext/core b/ext/core index 277792824..8b3a97284 160000 --- a/ext/core +++ b/ext/core @@ -1 +1 @@ -Subproject commit 277792824801495e868580ca86f6e7a1b53e4779 +Subproject commit 8b3a972841b6ea444d48f91da330f203f70d9cba