Get http media stream from Axis Camera #636
-
Hi, I would like to use python (on windows pc) to obtain specified time duration (e.g. one min) media stream using http from Axis Camera. The reference link for Vapix document : https://www.axis.com/vapix-library/subjects/t10175981/section/t10188469/display?section=t10188469-t10188469 I am opting for the above guide as i can have mp4 container for the video captured . I am aware of Export api which can support mkv format. Thanks in advance . |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
This automatically generated reply acts as a friendly reminder. Answers to your questions will most often come from the community, from developers like yourself. You will, from time to time, find that Axis employees answers some of the questions, but this is not a guarantee. Think of the discussion forum as a complement to other support channels, not a replacement to any of them. If your question remains unanswered for a period of time, please revisit it to see whether it can be improved by following the guidelines listed in Axis support guidelines. |
Beta Was this translation helpful? Give feedback.
-
Hi @vmithani , http://root:pass@<IP Address>/axis-cgi/media.cgi?resolution=1920x1080&fps=30&videocodec=h264&container=mp4 |
Beta Was this translation helpful? Give feedback.
-
if you just want to display the video, you can also try http://ip/axis-cgi/mjpg/video.cgi |
Beta Was this translation helpful? Give feedback.
-
HI @vmithani , Using "/axis-cgi/media.cgi?resolution=1920x1080&fps=30&videocodec=h264&container=mp4" with "ffmpeg.exe" in the same folder.import os
import requests
import subprocess
import time
def capture_video(url, duration, output_file):
# Start capturing the video stream
command = f'ffmpeg -i "{url}" -t {duration} -c:v copy -c:a copy "{output_file}"'
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Wait for the specified duration
time.sleep(duration)
# Terminate the ffmpeg process
process.terminate()
if __name__ == "__main__":
# URL of the Axis Camera stream
camera_url = "http://root:pass@10.176.12.50/axis-cgi/media.cgi?resolution=1920x1080&fps=30&videocodec=h264&container=mp4"
# Duration of the video capture in seconds (e.g., 60 seconds for 1 minute)
capture_duration = 60
# Output file path
output_file = "captured_video.mp4"
# Capture the video
capture_video(camera_url, capture_duration, output_file)
Using "/axis-cgi/media.cgi" with "ffmpeg.exe" in the same folderimport os
import requests
import subprocess
import time
def capture_video(url, duration, output_file):
# Start capturing the video stream
command = f'ffmpeg -i "{url}" -t {duration} -c:v copy -c:a copy "{output_file}"'
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Wait for the specified duration
time.sleep(duration)
# Terminate the ffmpeg process
process.terminate()
if __name__ == "__main__":
# URL of the Axis Camera stream
camera_url = "http://root:pass@10.176.12.50/axis-cgi/mjpg/video.cgi"
# Duration of the video capture in seconds (e.g., 60 seconds for 1 minute)
capture_duration = 60
# Output file path
output_file = "captured_video_mjpg.mp4"
# Capture the video
capture_video(camera_url, capture_duration, output_file)
Using "opencv-python-headless"# pip install opencv-python-headless
# This script uses opencv-python to capture the video stream from the provided URL and save it to an MP4 file.
# Make sure you have a suitable codec installed on your system to write MP4 files.
import cv2
import requests
import numpy as np
import time
def capture_video(url, duration, output_file):
# Open the video stream
cap = cv2.VideoCapture(url)
# Check if the video stream is opened successfully
if not cap.isOpened():
print("Error: Unable to open video stream.")
return
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter(output_file, fourcc, 30.0, (1920, 1080))
# Start time
start_time = time.time()
# Capture video for the specified duration
while cap.isOpened() and time.time() - start_time < duration:
ret, frame = cap.read()
if ret:
# Write the frame to the output file
out.write(frame)
else:
break
# Release everything if job is finished
cap.release()
out.release()
if __name__ == "__main__":
# URL of the Axis Camera stream
camera_url = "http://root:pass@10.176.12.50/axis-cgi/media.cgi?resolution=1920x1080&fps=30&videocodec=h264&container=mp4"
# Duration of the video capture in seconds (e.g., 60 seconds for 1 minute)
capture_duration = 60
# Output file path
output_file = "captured_video_with_opencv_python_headless.mp4"
# Capture the video
capture_video(camera_url, capture_duration, output_file)
|
Beta Was this translation helpful? Give feedback.
HI @vmithani ,
Adding Python code samples which I have tested with AXIS P1367 Network Camera (AXIS OS version 10.12.166)
Using "/axis-cgi/media.cgi?resolution=1920x1080&fps=30&videocodec=h264&container=mp4" with "ffmpeg.exe" in the same folder.