Convert Array of Base64 Strings to Audio file - c++

I am using a ESP32 with a inmp441 device to send audio via bluetooth. The esp is sending float values converted to std::strings so they can be read as Base64 over bluetooth. I am able to receive the Base64 values and I store them in an array like so
base64Array = ['LTMwMi4xMjUwMDA=','MzkyLjM3NTAwMA==','MTY3My4zNzUwMDA=', ...]
Here is my questions, to create an audio file like mp3 or wav, do I need to encode all of the Base64 string in the array back to ASCII then concatenate them together and then decode them back to Base64 to get one long Base64 string. Or can I write every Base64 value in the array to a file (creating a new line for each value) and save that as an audio file?
I am using react native to create an app and need the bluetooth device recording functionality.

Related

How to write ROS AudioData message into wav file?

I'm using ReSpeaker Mic Array v2.0 on my robot, I used the following git repo: https://github.com/furushchev/respeaker_ros.git to capture the audio received by the speaker. I subscribed to it's raw audio ros topic /audio which is just byte array data(http://docs.ros.org/noetic/api/audio_common_msgs/html/msg/AudioData.html)
How can I write the AudioData message's uint8[] data into a wav file in C++? I would like to play the wav file by other means afterwards.
I saw that in ros audio_common library example it uses gstreamer to do the writing, but I'm quite confused after reading the code(https://github.com/ros-drivers/audio_common/blob/master/audio_capture/src/audio_capture.cpp)
Example that you saw is using Gstremaer's alsasrc to capture audio from mic in this line
_source = gst_element_factory_make("alsasrc", "source");
So Gstreamer's pipeline is internally handling/capturing audio byte array and, in case of input parameters dst_type=="filesink" and format=="wave", encoding it with
_filter = gst_element_factory_make("wavenc", "filter");
and creating .wav file with
_sink = gst_element_factory_make("filesink", "sink");
On the other hand, running that code with input parameters dst_type=="appsink" and format=="wave" actually captures audio bytes again but, instead of writing to file, publishes them on ros topic /audio.
If you cannot (from any reason) use this code with input parameters dst_type=="filesink" and format=="wave", I suppose you will need to use Gstreamer's appsrc element and feed it with bytes from your AudioData message. In that case, the rest of Gstreamer pipeline for encoding and writing to file should remain the same as in the example.

Write H.264 stream in buffer to a streamable mp4 using ffmpeg

I wrote code to create H.264 stream, which has a loop to generate H.264 encoded frame.
while(true) {
...
x264_encoder_encode(encoder, &buffer, &i_buffer, &pic_in, &pic_out);
...
/*TODO: Write one frame in the buffer to a streamable mp4 file*/
}
Every single time, an H.264 encoded frame is generated and stored in the buffer. How can I write it into a streamable mp4 file directly through the buffer?
I spent lots of time searching for the solution. All I can find is to read stream from a file using
avformat_open_input(&fmtCtx, in_filename, 0, 0)
Is there any way to read directly from buffer without a file?
MP4 is actually not streamable. So in other words, you can't do it at all. I ran in that very problem.
The reason why it won't work is because when you open an mp4 file, you have to have all sorts of parameters, which by default get saved at the end of the file. When you create an MP4, you can always forcibly save that info at the start. However, to know what those parameters are, you need all the data. And without those parameters, the software trying to load the mp4 fails very early on. This is true for some other formats such as webm videos and .m4a or .wav for audio.
What you have to do is stream the actual H.264, possibly using RTSP or a format of your own if you're in control of both sides.

Set audio format in liblvc

How can I set the format of an audio in libvlc?
there is a function in libvlc for it but I don't know how to use it[from here]:
LIBVLC_API void libvlc_audio_set_format ( libvlc_media_player_t * mp,
const char * format,
unsigned rate,
unsigned channels
)
Set decoded audio format.
This only works in combination with libvlc_audio_set_callbacks(), and
is mutually exclusive with libvlc_audio_set_format_callbacks().
Parameters mp the media player format a four-characters string
identifying the sample format (e.g. "S16N" or "FL32") rate sample rate
(expressed in Hz) channels channels count Version LibVLC 2.0.0 or
later
How can I set the format of audio file, for example a wav file?
This API is for raw, decoded audio, which is typically forwarded to speakers or re-encoded to store it.
This API is NOT to export audio as files (unless you implement that yourself in your app, that is). To convert files, see the stream output MRL command-line syntax, as there is currently no designated libvlc API available for use-case.

Encoding video on H.263 to send over RTP

I'm developing an application to send video over RTP to a client that can play only H.263 (1996) and H263+ (1998).
To do this i've encoded the video using libav following these steps: (this is only part of the code)
av_register_all();
avformat_network_init();
Fmt = av_guess_format("rtp", NULL, NULL);
...
st = add_video_stream(FmtCtx, CODEC_ID_H263);
...
avio_open(&FmtCtx->pb, rtp_url, URL_WRONLY)
To finally enter a loop where i encode the video, the problem is that the stream generated by this program is encoded in H.263-2000 (or H.263++) which the other side cannot undertand, even though i use CODEC_ID_H263 or CODEC_ID_H263P in the initialization the same thing happens.
Is it possible to encode in those old H.263 versions using libav? i havent managed to do it not even using ffmpeg commands. The stream is always h.263-2000 (PT=96)

Decode PCM audio data with g722 codec

I'm developing a call recorder for VoIP audio, the audio is encoded by using a g722 codec in a CISCO environment.
Well, I have extracted the data from the RTPs frames and I have decoded this pcm data as follow:
unsigned int payloadSize = htons(udpHdr->len) - (CONSTANT::UDP_HDR_SIZE + CONSTANT::RTP_HDR_SIZE);
char * payload = (char*)rtpHdr + CONSTANT::RTP_HDR_SIZE;
unsigned short m_payloadType = rtpHdr->pt;
//decode_state is initialize like :g722_decode_init(NULL, 64000, G722_SAMPLE_RATE_8000);
outBuffSize = g722_decode(decode_state, decompressed, (const uint8_t*)payload, payloadSize);
I store in a file this decode data (and all frames of the same flow, equal sscr) and when try to hear the audio, I only hear noise.
I think this problem is for the compressed algorithm used CISCO.
The behaviour of the decoded function is correct.
Any suggestion?