@@ -147,8 +147,8 @@ std::vector<float> resampleAudio(const std::vector<float>& inputAudio, int input
147147 return {};
148148 }
149149
150- const int chunkSize = 4096 ;
151- const int numChannels = 2 ;
150+ constexpr int chunkSize = 4096 ;
151+ constexpr int numChannels = 2 ;
152152
153153 int maxOutputSamples = av_rescale_rnd (chunkSize, targetSampleRate, inputSampleRate, AV_ROUND_UP);
154154 std::vector<float > outputAudio;
@@ -193,13 +193,18 @@ namespace ffmpeg {
193193
194194 std::vector<float > raw = readAudioFile (audioFile.string ().c_str (), 44100 , AV_SAMPLE_FMT_FLTP, &inputAudioParams);
195195
196- mixVideoRaw (std::move ( videoFile) , raw, std::move ( outputMp4File), inputAudioParams. sample_rate );
196+ mixVideoRaw (videoFile, raw, outputMp4File);
197197
198198 avformat_close_input (&wavFormatContext);
199199 }
200200
201- void AudioMixer::mixVideoRaw (std::filesystem::path videoFile, const std::vector<float >& raw, std::filesystem::path outputMp4File, uint32_t sampleRate) {
202- const int frameSize = 1024 ;
201+ void AudioMixer::mixVideoRaw (std::filesystem::path videoFile, const std::vector<float >& raw, std::filesystem::path outputMp4File, uint32_t ) {
202+ mixVideoRaw (videoFile, raw, outputMp4File);
203+ }
204+
205+ void AudioMixer::mixVideoRaw (const std::filesystem::path& videoFile, const std::vector<float >& raw, const std::filesystem::path &outputMp4File) {
206+ constexpr int frameSize = 1024 ;
207+ constexpr uint32_t sampleRate = 44100 ;
203208
204209 AVFormatContext* videoFormatContext = nullptr ;
205210 if (avformat_open_input (&videoFormatContext, videoFile.string ().c_str (), nullptr , nullptr ) < 0 ) {
@@ -349,18 +354,17 @@ namespace ffmpeg {
349354 continue ;
350355 }
351356
352- AVPacket audioPacket;
353- av_init_packet (&audioPacket);
354- audioPacket.data = nullptr ;
355- audioPacket.size = 0 ;
357+ AVPacket* audioPacket = av_packet_alloc ();
358+ audioPacket->data = nullptr ;
359+ audioPacket->size = 0 ;
356360
357361 while (true ) {
358- int ret = avcodec_receive_packet (audio_codec_context_encoder, & audioPacket);
362+ int ret = avcodec_receive_packet (audio_codec_context_encoder, audioPacket);
359363 if (ret == 0 ) {
360- av_packet_rescale_ts (& audioPacket, audio_codec_context_encoder->time_base , outputAudioStream->time_base );
361- audioPacket. stream_index = 1 ;
362- av_interleaved_write_frame (outputFormatContext, & audioPacket);
363- av_packet_unref (& audioPacket);
364+ av_packet_rescale_ts (audioPacket, audio_codec_context_encoder->time_base , outputAudioStream->time_base );
365+ audioPacket-> stream_index = 1 ;
366+ av_interleaved_write_frame (outputFormatContext, audioPacket);
367+ av_packet_unref (audioPacket);
364368 } else if (ret == AVERROR (EAGAIN) || ret == AVERROR_EOF)
365369 break ;
366370 else {
0 commit comments