11#include " audio_mixer.hpp"
22
33#include < iostream>
4+ #include < utility>
45
56extern " C" {
67 #include < libavcodec/avcodec.h>
@@ -87,15 +88,14 @@ std::vector<float> readAudioFile(const char *filename, int targetSampleRate, AVS
8788 std::vector<float > audioFrames;
8889
8990 float *convertBuffer[2 ];
90- convertBuffer[0 ] = ( float *) av_malloc (4096 * sizeof (float ));
91- convertBuffer[1 ] = ( float *) av_malloc (4096 * sizeof (float ));
91+ convertBuffer[0 ] = static_cast < float *>( av_malloc (4096 * sizeof (float ) ));
92+ convertBuffer[1 ] = static_cast < float *>( av_malloc (4096 * sizeof (float ) ));
9293
9394 while (av_read_frame (formatContext, &packet) >= 0 ) {
9495 if (packet.stream_index == audioStreamIndex && avcodec_send_packet (codecContext, &packet) == 0 ) {
9596 while (avcodec_receive_frame (codecContext, frame) == 0 ) {
96- int ret = swr_convert (swr, (uint8_t **)convertBuffer, 4096 ,
97- (const uint8_t **)frame->data ,
98- frame->nb_samples );
97+ int ret = swr_convert (swr, reinterpret_cast <uint8_t **>(convertBuffer), 4096 ,
98+ frame->data , frame->nb_samples );
9999 if (ret < 0 ) {
100100 char errbuf[AV_ERROR_MAX_STRING_SIZE];
101101 av_strerror (ret, errbuf, AV_ERROR_MAX_STRING_SIZE);
@@ -125,7 +125,7 @@ std::vector<float> readAudioFile(const char *filename, int targetSampleRate, AVS
125125
126126namespace ffmpeg {
127127 void AudioMixer::mixVideoAudio (std::filesystem::path videoFile, std::filesystem::path audioFile, std::filesystem::path outputMp4File) {
128- const int frameSize = 1024 ;
128+ constexpr int frameSize = 1024 ;
129129
130130 AVFormatContext* wavFormatContext = nullptr ;
131131 if (avformat_open_input (&wavFormatContext, audioFile.string ().c_str (), nullptr , nullptr ) < 0 ) {
@@ -137,7 +137,7 @@ namespace ffmpeg {
137137
138138 std::vector<float > raw = readAudioFile (audioFile.string ().c_str (), 44100 , AV_SAMPLE_FMT_FLTP, &inputAudioParams);
139139
140- mixVideoRaw (videoFile, raw, outputMp4File, inputAudioParams.sample_rate );
140+ mixVideoRaw (std::move ( videoFile) , raw, std::move ( outputMp4File) , inputAudioParams.sample_rate );
141141
142142 avformat_close_input (&wavFormatContext);
143143 }
@@ -182,8 +182,8 @@ namespace ffmpeg {
182182 geode::log::error (" Failed to create audio stream." );
183183 return ;
184184 }
185-
186- const int channels = 2 ;
185+
186+ constexpr int channels = 2 ;
187187
188188 outputAudioStream->codecpar ->codec_tag = 0 ;
189189 outputAudioStream->codecpar ->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -211,7 +211,7 @@ namespace ffmpeg {
211211 audio_codec_context_encoder->sample_rate = sampleRate;
212212 audio_codec_context_encoder->ch_layout = AV_CHANNEL_LAYOUT_STEREO;
213213 audio_codec_context_encoder->sample_fmt = AV_SAMPLE_FMT_FLTP;
214- audio_codec_context_encoder->time_base = AVRational{1 , ( int ) sampleRate};
214+ audio_codec_context_encoder->time_base = AVRational{1 , static_cast < int >( sampleRate) };
215215
216216 int ret = avcodec_open2 (audio_codec_context_encoder, audioCodec, nullptr );
217217 if (ret < 0 ) {
@@ -289,7 +289,7 @@ namespace ffmpeg {
289289
290290 AVPacket audioPacket;
291291 av_init_packet (&audioPacket);
292- audioPacket.data = NULL ;
292+ audioPacket.data = nullptr ;
293293 audioPacket.size = 0 ;
294294
295295 while (true ) {
0 commit comments