I have attached a speaker at the Aout pin on the ameba82 board. and the “PlayMP3” example is working and i am able to play the audio.now I want to play a sound like “recording start” and “recording stop” whenever i start and stop the video recording using a button press. I am recording video with audio. It works when i only record video without audio but when i record video with audio, I receive the following error.
hi @saud_shafiq, may i know did you test with this example in Arduino environment SingleVideoWithAudio on recording + audio to see the outcome first before you combine with SDCardPlayMP3. Here are the example guide document. Thanks.
hi @KaiFai_Y
yes, I did. to clear things up. I am using a button to capture images and videos. I used “Dual video with Audio” for reference and everything works 1 channel is used for videos and 1 channel is for snapshots. Now in the next phase,I am adding a speaker that will alert the user that video recording is started or stopped. Individually everything is working fine. Problem arise in the integration. alert still plays but video recording is not recorded. if i use only video and disable video’s audio,then everything works fine. But I need video with audio and alerts on the speaker.
Hi @saud_shafiq,would you mind sharing your integration code?
Having the actual code would make it much easier for me to reproduce the issue and give accurate assistance. Thank you.
#include "speaker_ops.h"
#include "alert_sounds.h"
extern "C" {
#include "helix_mp3_drv.h"
}
void image_capture_sound(void)
{
audio_play_binary_array((uint8_t*)shutter_mp3,shutter_mp3_len,0xAF);
}
void video_recording_started_voice(void)
{
audio_play_binary_array((uint8_t*)recording_start_mp3,recording_start_mp3_len,0xAF);
}
void video_record_stop_voice(void)
{
audio_play_binary_array((uint8_t*)recording_stop_mp3,recording_stop_mp3_len,0xAF);
}
#ifndef _SPEAKER_OPS_H
#define _SPEAKER_OPS_H
void forkLifter_distance_alert_voice(void);
void fall_detection_alert_voice(void);
void image_capture_sound(void);
void video_recording_started_voice(void);
void video_record_stop_voice(void);
#endif
#include "camera_ops.h"
#include "Base64.h"
#include "StreamIO.h"
#include "VideoStream.h"
#include "MP4Recording.h"
#include "AudioStream.h"
#include "AudioEncoder.h"
#include "AmebaFatFS.h"
#include "rtc_ops.h"
#include "speaker_ops.h"
extern AmebaFatFS fs;
extern dateTime_t dt;
char filename[40] = "";
char image_filename[40] = "";
#define CHANNELV 1
#define CHANNELS 0
VideoSetting configV(CHANNELV);
VideoSetting configS(VIDEO_FHD, CAM_FPS, VIDEO_JPEG, 1);
AudioSetting configA(0);
Audio audio;
AAC aac;
MP4Recording mp4;
StreamIO audioStreamer(1, 1); // 1 Input Audio -> 1 Output AAC
StreamIO avMixStreamer(2, 1); // 2 Input Video + Audio -> 1 Output MP4
Error_Camera_e cam_err;
Error_Camera_e ameba_camera_init(void)
{
Camera.configVideoChannel(CHANNELV, configV);
Camera.configVideoChannel(CHANNELS, configS);
Camera.videoInit();
// Configure audio peripheral for audio data output
audio.configAudio(configA);
audio.begin();
// Configure AAC audio encoder
aac.configAudio(configA);
aac.begin();
// Configure MP4 with identical video format information
// Configure MP4 recording settings
mp4.configVideo(configV);
mp4.configAudio(configA, CODEC_AAC);
mp4.setRecordingDuration(36000);
mp4.setRecordingFileCount(1);
// mp4.setRecordingDataType(STORAGE_VIDEO);
// Configure StreamIO object to stream data from audio channel to AAC encoder
audioStreamer.registerInput(audio);
audioStreamer.registerOutput(aac);
if (audioStreamer.begin() != 0) {
// Serial.println("StreamIO link start failed");
return ERR_AUIDO_STREAMER;
}
// Configure StreamIO object to stream data from video channel and AAC encoder to MP4 recording
avMixStreamer.registerInput1(Camera.getStream(CHANNELV));
avMixStreamer.registerInput2(aac);
avMixStreamer.registerOutput(mp4);
if (avMixStreamer.begin() != 0) {
// Serial.println("StreamIO link start failed");
return ERR_AV_MIXER;
}
Camera.channelBegin(CHANNELS);
Camera.channelBegin(CHANNELV);
delay(1000);
return ERR_OK;
}
void capture_and_save_image(void) {
get_dateTime();
uint32_t img_addr = 0;
uint32_t img_len = 0;
snprintf(image_filename, sizeof(image_filename), "cameraImage_%hu_%hhu_%hhu_%hhu_%hhu_%hhu.jpg", dt.yy, dt.mm, dt.dd, dt.h, dt.m, dt.s);
File file = fs.open(String(fs.getRootPath()) + String(image_filename));
// delay(1000);
Camera.getImage(CHANNELS, &img_addr, &img_len);
file.write((uint8_t *)img_addr, img_len);
file.close();
}
void start_recording(void)
{
if(!mp4.getRecordingState())
{
snprintf(filename, sizeof(filename), "cameraRecord_%hu_%hhu_%hhu_%hhu_%hhu_%hhu", dt.yy, dt.mm, dt.dd, dt.h, dt.m, dt.s);
mp4.setRecordingFileName(filename);
mp4.begin();
}
}
void stop_recording(void)
{
if(mp4.getRecordingState())
{
mp4.end();
}
}
#ifndef _CAMERA_OPS_H
#define _CAMERA_OPS_H
typedef enum{
ERR_OK=0,
ERR_AUIDO_STREAMER,
ERR_AV_MIXER,
}Error_Camera_e;
Error_Camera_e ameba_camera_init(void) ;
void capture_and_save_image(void);
void start_recording(void);
void stop_recording(void);
#endif
Hi @saud_shafiq ,
May I know if this is for a project or a product, and perhaps share a brief description? This will help us assist you more effectively.
Thank you!
This is for a project. like a helmet camera. when I see something record worthy, I will press the button to capture image,take video(video is with audio), take snapshots while recording video. a speaker is used to alert the user that recording has started or stopped. Thats it
Hi @saud_shafiq ,
You may refer to this example and patch it to your SDK to try out Recording MP4 with MP3 prompts played.
You may take this example as a reference while integrating it into your project.
As MP4 recording for audio and MP3 shares the same SPORT interface, which can lead to unstable recording. Therefore, audio modules should be deinit before MP3 is played.
Hi @saud_shafiq
You can try out the example with SDK 4.1.0 latest prerelease version using https://github.com/Ameba-AIoT/ameba-arduino-pro2/raw/dev/Arduino_package/package_realtek_amebapro2_early_index.json.
Example guide: MP4 Recording with MP3 Prompts — Ameba Arduino AIoT Documentation v1.1 documentation