diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-02-26 01:43:43 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-02-26 01:43:43 +0100 |
commit | 97e0a6ad1b5204bc919d4d852b0b8a2c0c10a611 (patch) | |
tree | ca17cf585375b38c49130cc51fce8c3e680c1c63 /src | |
parent | 55d66cf6940012454d119014ced1ce080ff3c0c5 (diff) |
Do not add audio track if not recording audio
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/main.cpp b/src/main.cpp index c7b9f71..ecc178a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -689,6 +689,8 @@ int main(int argc, char **argv) { } } + Arg &audio_input_arg = args["-a"]; + uint32_t region_x = 0; uint32_t region_y = 0; uint32_t region_width = 0; @@ -892,21 +894,25 @@ int main(int argc, char **argv) { return 1; } - AVCodecContext *audio_codec_context; - AVStream *audio_stream = add_audio_stream(av_format_context, &audio_codec_context, fps); - if (!audio_stream) { - fprintf(stderr, "Error: Failed to create audio stream\n"); - return 1; - } - AVBufferRef *device_ctx; CUgraphicsResource cuda_graphics_resource; open_video(video_codec_context, window_pixmap, &device_ctx, &cuda_graphics_resource); - avcodec_parameters_from_context(video_stream->codecpar, video_codec_context); - AVFrame *audio_frame = open_audio(audio_codec_context); - avcodec_parameters_from_context(audio_stream->codecpar, audio_codec_context); + + AVCodecContext *audio_codec_context; + AVStream *audio_stream; + AVFrame *audio_frame; + if(audio_input_arg.value) { + audio_stream = add_audio_stream(av_format_context, &audio_codec_context, fps); + if (!audio_stream) { + fprintf(stderr, "Error: Failed to create audio stream\n"); + return 1; + } + + audio_frame = open_audio(audio_codec_context); + avcodec_parameters_from_context(audio_stream->codecpar, audio_codec_context); + } //av_dump_format(av_format_context, 0, filename, 1); @@ -1016,7 +1022,6 @@ int main(int argc, char **argv) { bool frames_erased = false; SoundDevice sound_device; - Arg &audio_input_arg = args["-a"]; if(audio_input_arg.value) { if(sound_device_get_by_name(&sound_device, audio_input_arg.value, audio_codec_context->channels, audio_codec_context->frame_size) != 0) { fprintf(stderr, "failed to get 'pulse' sound device\n"); @@ -1027,7 +1032,7 @@ int main(int argc, char **argv) { uint8_t *audio_frame_buf = (uint8_t *)av_malloc(audio_buffer_size); avcodec_fill_audio_frame(audio_frame, audio_codec_context->channels, audio_codec_context->sample_fmt, (const uint8_t*)audio_frame_buf, audio_buffer_size, 1); - audio_thread = std::thread([record_start_time, replay_buffer_size_secs, &frame_data_queue, &frames_erased, audio_codec_context, &frame_count](AVFormatContext *av_format_context, AVStream *audio_stream, uint8_t *audio_frame_buf, SoundDevice *sound_device, AVFrame *audio_frame, std::mutex *write_output_mutex) mutable { + audio_thread = std::thread([record_start_time, replay_buffer_size_secs, &frame_data_queue, &frames_erased, audio_codec_context](AVFormatContext *av_format_context, AVStream *audio_stream, uint8_t *audio_frame_buf, SoundDevice *sound_device, AVFrame *audio_frame, std::mutex *write_output_mutex) mutable { SwrContext *swr = swr_alloc(); if(!swr) { |