+ if (audio_frame.len > 0) {
+ // FFmpegCapture takes care of this for us.
+ assert(audio_format.num_channels == 2);
+ assert(audio_format.sample_rate == OUTPUT_FREQUENCY);
+
+ // TODO: Reduce some duplication against AudioMixer here.
+ size_t num_samples = audio_frame.len / (audio_format.bits_per_sample / 8);
+ vector<float> float_samples;
+ float_samples.resize(num_samples);
+ if (audio_format.bits_per_sample == 16) {
+ const int16_t *src = (const int16_t *)audio_frame.data;
+ float *dst = &float_samples[0];
+ for (size_t i = 0; i < num_samples; ++i) {
+ *dst++ = le16toh(*src++) * (1.0f / 32768.0f);
+ }
+ } else if (audio_format.bits_per_sample == 32) {
+ const int32_t *src = (const int32_t *)audio_frame.data;
+ float *dst = &float_samples[0];
+ for (size_t i = 0; i < num_samples; ++i) {
+ *dst++ = le32toh(*src++) * (1.0f / 2147483648.0f);
+ }
+ } else {
+ assert(false);
+ }
+ audio_pts = av_rescale_q(audio_pts, audio_timebase, AVRational{ 1, TIMEBASE });
+ audio_encoder->encode_audio(float_samples, audio_pts);
+ }