Video capture issue

This is my code for video capture. I am using MAV_CMD_VIDEO_START_CAPTURE and MAV_CMD_VIDEO_STOP_CAPTURE mavlink commands:

from fastapi import FastAPI, HTTPException, status
from pymavlink import mavutil
import numpy as np
import cv2
import atexit

app = FastAPI()

# Connect to the MAVLink system
master = mavutil.mavlink_connection('udpin:localhost:14550')
print("Heartbeat from system (system %u component %u)" %
      (master.target_system, master.target_component))

# Initialize video-related variables
capturing = False
out = None

def start_stream():
    global capturing, out
    if not capturing:
        capturing = True
            master.target_system, master.target_component,
            mavutil.mavlink.MAV_CMD_VIDEO_START_CAPTURE, 0, 1, 0, 0, 0, 0, 0, 0

        out = cv2.VideoWriter("video_output.mp4", cv2.VideoWriter_fourcc(*'mp4v'), 30, (640, 480))

        return {"message": "Stream started"}
        raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Stream already started")

def stop_stream():
    global capturing, out
    if capturing:
        capturing = False
            master.target_system, master.target_component,
            mavutil.mavlink.MAV_CMD_VIDEO_STOP_CAPTURE, 0, 1, 0, 0, 0, 0, 0, 0

        if out:

        return {"message": "Stream stopped and saved"}
        raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="No active stream to stop")

def get_status():
    global capturing
    return {"stream_status": "capturing" if capturing else "stopped"}

def shutdown_event():
    global master

def capture_frames():
    while True:
        if capturing:
            msg = master.recv_match(type='DATA_STREAM', blocking=True, timeout=5)
            if msg and msg.stream_id == 0:
                video_data =
                frame = np.frombuffer(video_data, dtype=np.uint8).reshape(480, 640, 3)

# Start capturing frames in a separate thread
import threading
capture_thread = threading.Thread(target=capture_frames)


I am getting this output: {"message":"Stream started"} and Got COMMAND_ACK: VIDEO_START_CAPTURE: FAILED
Got COMMAND_ACK: VIDEO_STOP_CAPTURE: FAILED in ubuntu using mission planner …please could you give me suggestions guys

You do not explain which firmware version you are using, but I assume it is not ArduCopter 4.5.0-dev

Try that version.

I am using ArduCoperV4.5.0-dev (dc90fd57)

Please post a .param file as well.

Full Parameter list.param (23.3 KB)