From 999400dc534d645c1e39ac1227e38566f318b0aa Mon Sep 17 00:00:00 2001 From: Squall Leonhart Date: Sun, 3 Nov 2024 21:58:15 +1100 Subject: [PATCH] dynamically set nb_samples by samplerate --- src/components/av_recording/av_recording.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/av_recording/av_recording.cpp b/src/components/av_recording/av_recording.cpp index 3070f84d..111b7587 100644 --- a/src/components/av_recording/av_recording.cpp +++ b/src/components/av_recording/av_recording.cpp @@ -143,19 +143,20 @@ recording::MediaRet recording::MediaRecorder::setup_audio_stream() aenc->channel_layout = AV_CH_LAYOUT_STEREO; aenc->channels = 2; #endif - aenc->time_base = { 1, aenc->sample_rate }; - ast->time_base = { 1, STREAM_FRAME_RATE }; - // open and use codec on stream + aenc->time_base = (AVRational){1, aenc->sample_rate}; + ast->time_base = (AVRational){1, STREAM_FRAME_RATE}; + + // Open and use codec on stream int nb_samples; if (avcodec_open2(aenc, acodec, NULL) < 0) return MRET_ERR_NOCODEC; if (avcodec_parameters_from_context(ast->codecpar, aenc) < 0) return MRET_ERR_BUFSIZE; - // number of samples per frame + + // Calculate number of samples per frame based on sample rate if (aenc->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE) { - //nb_samples = 10000; // can be any value, but we use our aud buffer size - nb_samples = 1470; + nb_samples = (int)(aenc->sample_rate / STREAM_FRAME_RATE); } else nb_samples = aenc->frame_size;