Testing with FFmpeg
Introduction
In this guide, you will learn how to use FFmpeg to test the livestreaming formats supported by the Eagle Eye Networks Media API. These formats include protocols such as RTSP, HLS, and MultiPart, each serving different use cases—from low-latency monitoring to scalable playback in browsers and mobile apps.
FFmpeg offers a simple command-line tool to verify that your Eagle Eye video streams function properly before integrating them into an application. By running a few simple commands, you can:
- Validate that a camera’s live stream is accessible through the API.
- Inspect details about codecs, bitrates, and container formats.
- Troubleshoot connectivity issues by checking stream response and metadata.
- Quickly preview media output without needing to write client code.
Prerequisites
- You have FFmpeg downloaded and installed.
Learn more here
- You have the latest version of Python downloaded.
Download from here
Procedure
- After making sure FFmpeg is installed, obtain an access token as described here.
- Retrieve different streaming URLs from the
/api/v3.0/feeds
endpoint using the /feeds API.
The streaming formats include the following:
- Multipart preview
- Multipart main
- RTSP Over TCP
- RTSP Over UDP
- RTSPS
- HLS
- FLV
- MP4
- Run the following Python script in your IDE or in a terminal shell:
import os
import subprocess
def print_menu():
# Display menu with streaming protocol options
print("Select an option (enter the corresponding number):")
print("1- Multipart preview")
print("2- Multipart full")
print("3 - RTSP Over TCP")
print("4 - RTSP Over UDP")
print("5 - RTSPS")
print("6 - HLS")
print("7 - FLV")
print("8 - MP4")
print("0 - Exit")
def execute_command(choice, token, url):
# Execute the appropriate FFplay command based on user's choice
commands = [
"ffplay -headers \"Authorization: Bearer {1}\" \"{0}\"",
"ffplay -headers \"Authorization: Bearer {1}\" -f h264 \"{0}&flavor=ffmpeg\"",
"ffplay -rtsp_transport tcp \"{}&access_token={}\"",
"ffplay -rtsp_transport udp \"{}&access_token={}\"",
"ffplay \"{}&access_token={}\"",
"ffplay -headers \"Authorization: Bearer {1}\" \"{0}\"",
"ffplay -headers \"Authorization: Bearer {1}\" \"{0}\"",
"ffplay -headers \"Authorization: Bearer {1}\" \"{0}\""
]
cmd = commands[choice - 1].format(url,token)
subprocess.run(cmd, shell=True)
def main():
# Main loop: display menu, take input, execute command or exit
while True:
print_menu()
choice = int(input())
if choice == 0:
break
elif 1 <= choice <= 8:
token = input("Enter the token: ")
url = input("Enter the URL: ")
execute_command(choice, token, url)
else:
print("Invalid input. Please enter a number between 0 and 7.")
if __name__ == "__main__":
main()
- Provide an access token and a streaming URL respectively in response to the questions.
Result: After a few seconds, a window opens and FFmpeg starts playing the live video.
Tip
You can directly test the streaming URLs in the OS terminals too. For example, for playing the RTSP stream you can run the following command in a terminal:
ffplay -rtsp_transport tcp "{RTSP-URL}&access_token={access-token}
Note that the FFmpeg bin folder path needs to be defined in the environment variable to be able to call the
ffplay
command in any directory.
Updated 1 day ago