Start and end recording by ble AMB82 Mini

I have an amb82mini card, I modified the code of the record mp4 _ video only example as follows

#include "BLEDevice.h"
#include "StreamIO.h"
#include "VideoStream.h"
#include "MP4Recording.h"

#define UART_SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
#define CHARACTERISTIC_UUID_RX "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
#define CHARACTERISTIC_UUID_TX "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"

#define STRING_BUF_SIZE 100

BLEAdvertData foundDevice;
BLEAdvertData targetDevice;
BLEClient* client;
BLERemoteService* UartService;
BLERemoteCharacteristic* Rx;
BLERemoteCharacteristic* Tx;

#define CHANNEL 0
// // Default preset configurations for each video channel:
// // Channel 0 : 1920 x 1080 30FPS H264
// // Channel 1 : 1280 x 720  30FPS H264

VideoSetting config(CHANNEL);
MP4Recording mp4;
StreamIO videoStreamer(1, 1);  // 1 Input Video -> 1 Output RTSP

void scanCB(T_LE_CB_DATA* p_data) {
  foundDevice.parseScanInfo(p_data);
  if (foundDevice.hasName()) {
    if (foundDevice.getName() == String("UART Service")) {
      Serial.print("Found Ameba BLE Device at address ");
      Serial.println(foundDevice.getAddr().str());
      targetDevice = foundDevice;
    }
  }
}

void notificationCB(BLERemoteCharacteristic* chr, uint8_t* data, uint16_t len) {
  char msg[len + 1] = { 0 };
  memcpy(msg, data, len);
  Serial.print("Notification received for chr UUID: ");
  Serial.println(chr->getUUID().str());
  Serial.print("Received string: ");
  Serial.println(String(msg));

  // Vérifiez si le message de confirmation a été reçu
  if (String(msg) == "Record") {
    digitalWrite(LED_BUILTIN, HIGH);

    // Start data stream from video channel
    // Camera.channelBegin(CHANNEL);
    // Start recording MP4 data to SD card
    mp4.begin();
    delay(200);

    Serial.println("Message du serveur reçu. Envoi d'un message de confirmation au serveur.");
    // Envoyer un message de confirmation au serveur
    Rx->writeString("Start record");
  } else if (String(msg) == "Stop") {
    digitalWrite(LED_BUILTIN, LOW);
    // Start data stream from video channel
    Camera.channelEnd(CHANNEL);
    // Start recording MP4 data to SD card
    mp4.end();

    Serial.println("Message du serveur reçu. Envoi d'un message de confirmation au serveur.");
    // Envoyer un message de confirmation au serveur
    Rx->writeString("Stop record");
  }
}

void setup() {
  Serial.begin(115200);

  BLE.init();
  BLE.setScanCallback(scanCB);
  BLE.beginCentral(1);

  BLE.configScan()->startScan(2000);
  BLE.configConnection()->connect(targetDevice, 2000);
  delay(2000);
  int8_t connID = BLE.configConnection()->getConnId(targetDevice);
  if (!BLE.connected(connID)) {
    Serial.println("BLE not connected");
  } else {
    BLE.configClient();
    client = BLE.addClient(connID);
    client->discoverServices();
    Serial.print("Discovering services of connected device");
    do {
      Serial.print(".");
      delay(1000);
    } while (!(client->discoveryDone()));
    Serial.println();

    UartService = client->getService(UART_SERVICE_UUID);
    if (UartService != nullptr) {
      Tx = UartService->getCharacteristic(CHARACTERISTIC_UUID_TX);
      if (Tx != nullptr) {
        Serial.println("TX characteristic found");
        Tx->setBufferLen(STRING_BUF_SIZE);
        Tx->setNotifyCallback(notificationCB);
        Tx->enableNotifyIndicate();
      }
      Rx = UartService->getCharacteristic(CHARACTERISTIC_UUID_RX);
      if (Rx != nullptr) {
        Serial.println("RX characteristic found");
        Rx->setBufferLen(STRING_BUF_SIZE);
      }
    }

    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, LOW);

    // Configure camera video channel with video format information
    Camera.configVideoChannel(CHANNEL, config);
    Camera.videoInit();

    // Configure MP4 with identical video format information
    // Configure MP4 recording settings
    mp4.configVideo(config);
    mp4.setLoopRecording(1);
    mp4.setRecordingFileCount(1);
    mp4.setRecordingFileName("TestRecordingVideo");
    mp4.setRecordingDataType(STORAGE_VIDEO);    // Set MP4 to record video only

    // Configure StreamIO object to stream data from video channel to MP4 recording
    videoStreamer.registerInput(Camera.getStream(CHANNEL));
    videoStreamer.registerOutput(mp4);
    if (videoStreamer.begin() != 0) {
        Serial.println("StreamIO link start failed");
    }

        // Start data stream from video channel
    Camera.channelBegin(CHANNEL);
    Serial.println("channelBegin");
  }
}

void loop() {
  if (Serial.available()) {
    Rx->writeString(Serial.readString());
  }
  delay(100);
}

The video file is created, but it is empty. How to start recording and end it without setting mp4.setRecordingDuration()
Thanks

Hi @jerome,

Welcome to AmebaIoT Forum. :slight_smile:

setRecordingDuration API is needed to be called if you would like to modify the duration of each recorded file.

If this API is not called, the duration for each recorded file will be default set at 60 seconds. You may refer to MP4Recording.cpp, mp4Params.record_length.
image

You have to wait until you see the following log before you remove SD card from board. Else, your recorded file will be empty.