python-onvif-zeep-async icon indicating copy to clipboard operation
python-onvif-zeep-async copied to clipboard

Asynchronous code doesn't work, but onvif2-zeep synchronous code does.

Open DiegoGO37 opened this issue 9 months ago • 4 comments

from onvif2 import ONVIFCamera
import subprocess
import os

ffmpeg_path = "/usr/bin/ffmpeg"
# Function to download recordings using ffmpeg
def download_recording(ffmpeg_path, recording_url, output_path):
    try:
        print(f"Downloading recording from: {recording_url}")
        # Use ffmpeg to download the video
        command = [
            ffmpeg_path, 
            "-i", recording_url, 
            '-vf', 'scale=1280: 720',
            output_path
        ]
        
        
        try:
            for i in command:
                print(i)
        except Exception as e:
            print('There was an error: {e}')
        
        subprocess.run(command, check=True)
        print(f"Recording saved to: {output_path}")
    except subprocess.CalledProcessError as e:
        print(f"Error during download: {e}")
    except Exception as ex:
        print(f"An error occurred: {ex}")

# ONVIF Camera Configuration
camera_ip = "192.168.1.108"
camera_port = 80
username = "admin"       
password = "admin1234"
output_dir = "/home/diego/recordings"

def onv_cam():
    try:
        # Ensure the output directory exists
        os.makedirs(output_dir, exist_ok=True)

        # Connect to the camera using onvif2-zeep
        camera = ONVIFCamera(
            host=camera_ip,
            port=camera_port,
            user=username,
            passwd=password,
            wsdl_dir='/home/diego/ippy_cameras/python-onvif2-zeep/wsdl'
        )

        # Access the Recording service
        recording_service = camera.create_recording_service()

        # Retrieve available recordings
        recordings = recording_service.GetRecordings()
        if not recordings:
            print("No recordings found on the camera.")
        else:
            # Iterate through available recordings
            for i, recording in enumerate(recordings):
                recording_token = recording.RecordingToken
                print(f"[{i + 1}] Recording Token: {recording_token}")

                # Get Replay URI for the recording
                replay_service = camera.create_replay_service()
                replay_uri_response = replay_service.GetReplayUri({
                    "RecordingToken": recording_token,
                    "StreamSetup": {
                        "Stream": "RTP-Unicast",
                        "Transport": {
                            "Protocol": "RTSP"
                        }
                    }
                })
                
                print(replay_uri_response)
                replay_uri = replay_uri_response
                print(f"Replay URI: {replay_uri}")

                # Save the recording to an output path
                output_filename = f"recording_{i + 1}.mp4"
                output_path = os.path.join(output_dir, output_filename)

                # Download the recording
                download_recording(ffmpeg_path, replay_uri, output_path)
    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == '__main__':
    onv_cam()

This code works, but, basically the same code maked with onvif-zeep-async doesn't. I receive the error "Device doesn`t support service: recording with namespace http://www.onvif.org/ver10/recording/wsdl"

DiegoGO37 avatar Feb 04 '25 15:02 DiegoGO37

Me too

Bojorges97 avatar Mar 04 '25 20:03 Bojorges97

+1

adrlog avatar Mar 04 '25 20:03 adrlog

+2

smathieson avatar Mar 04 '25 20:03 smathieson

+3

CesarinFokiu avatar Mar 04 '25 22:03 CesarinFokiu