[Seconds to understand audio and video development] 09_ audio recording 02_ programming
Recording by programming The main steps to develop the recording function are: Register device Get input format object Open device Collect data Release resources There are 3 FFmpeg libraries that need to be used. extern “C” {// Device related API#include // Format related API #include // tool related API (such as error handling)#include } Register device During the running of the entire program, you only need to execute the code for registering the device once. // Initialize libavdevice and register all input and output devicesavdevice_register_all(); Get input format object Macro definition The format name and device name of Windows and Mac environments are both are different, so use conditional compilation to achieve cross-platform. //The format name and device name are temporarily fixed by macro definitions#ifdef Q_OS_WIN //The format name #define FMT_NAME “dshow” // device name #define DEVICE_NAME “audio=microphone array (Realtek(R) Audio)”#else #define FMT_NAME “avfoundation” #define DEVICE_NAME ” :0″#endif Core Code Get the input format object according to the format name, you need to Open the device with an input format object. AVInputFormat *fmt = av_find_input_format(FMT_NAME);if (!fmt) { // if the input format cannot be found qDebug () <<"Input format not found" <<FMT_NAME; return;} Open device // format context (later operate…