Skip to content

Commit 73ab09f

Browse files
naushirdavidplowman
authored andcommitted
libav: Add option to choose the audio source (alsa/pulseaudio)
Add a new command line arguement (--audio-source) to allow the user to select between an alsa or pulseaudio source device. Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
1 parent 51bfa73 commit 73ab09f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

core/video_options.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,14 @@ struct VideoOptions : public Options
6868
("audio-codec", value<std::string>(&audio_codec)->default_value("aac"),
6969
"Sets the libav audio codec to use.\n"
7070
"To list available codecs, run the \"ffmpeg -codecs\" command.")
71+
("audio-source", value<std::string>(&audio_source)->default_value("pulse"),
72+
"Audio source to record from. Valid options are \"pulse\" and \"alsa\"")
7173
("audio-device", value<std::string>(&audio_device)->default_value("default"),
72-
"Audio device to record from. To list the available devices, use the following command:\n"
73-
"pactl list | grep -A2 'Source #' | grep 'Name: '")
74+
"Audio device to record from. To list the available devices,\n"
75+
"for pulseaudio, use the following command:\n"
76+
"\"pactl list | grep -A2 'Source #' | grep 'Name: '\"\n"
77+
"or for alsa, use the following command:\n"
78+
"\"arecord -L\"")
7479
("audio-bitrate", value<uint32_t>(&audio_bitrate)->default_value(32768),
7580
"Set the audio bitrate for encoding, in bits/second.")
7681
("audio-samplerate", value<uint32_t>(&audio_samplerate)->default_value(0),
@@ -93,6 +98,7 @@ struct VideoOptions : public Options
9398
bool libav_audio;
9499
std::string audio_codec;
95100
std::string audio_device;
101+
std::string audio_source;
96102
uint32_t audio_bitrate;
97103
uint32_t audio_samplerate;
98104
int32_t av_sync;

encoder/libav_encoder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ void LibAvEncoder::initVideoCodec(VideoOptions const *options, StreamInfo const
140140
void LibAvEncoder::initAudioInCodec(VideoOptions const *options, StreamInfo const &info)
141141
{
142142
#if LIBAVUTIL_VERSION_MAJOR < 58
143-
AVInputFormat *input_fmt = (AVInputFormat *)av_find_input_format("pulse");
143+
AVInputFormat *input_fmt = (AVInputFormat *)av_find_input_format(options->audio_source.c_str());
144144
#else
145-
const AVInputFormat *input_fmt = (AVInputFormat *)av_find_input_format("pulse");
145+
const AVInputFormat *input_fmt = (AVInputFormat *)av_find_input_format(options->audio_source.c_str());
146146
#endif
147147

148148
assert(in_fmt_ctx_ == nullptr);
@@ -438,7 +438,7 @@ void LibAvEncoder::videoThread()
438438

439439
void LibAvEncoder::audioThread()
440440
{
441-
constexpr AVSampleFormat required_fmt = AV_SAMPLE_FMT_FLTP;
441+
const AVSampleFormat required_fmt = codec_ctx_[AudioOut]->sample_fmt;
442442
// Amount of time to pre-record audio into the fifo before the first video frame.
443443
constexpr std::chrono::milliseconds pre_record_time(10);
444444

0 commit comments

Comments
 (0)