Live video streaming via ffplay

Introduction

In this guide, you will learn how to test all of the Eagle Eye Networks livestreaming formats.

Prerequisites

  1. You have FFmpeg downloaded and installed.

FFmpeg is a versatile, open-source multimedia framework that allows users to decode, encode, transcode, stream, filter, and play various audio and video formats. It includes a command line tool, libraries, and a programming interface, making it suitable for both developers and end users. Widely adopted by numerous applications, FFmpeg enables powerful processing and manipulation of multimedia files, while supporting a vast range of codecs and container formats.

Learn more here

  1. You have the latest version of Python downloaded.

Download from here

Procedure

  1. After making sure FFmpeg is installed, obtain an access token as described here.
  2. Retrieve different streaming URLs from the /api/v3.0/feeds endpoint using the /feeds API.
    The steaming formats include the following:
  • Multipart preview
  • Multipart main
  • RTSP Over TCP
  • RTSP Over UDP
  • RTSPS
  • HLS
  • FLV
  • MP4
  1. 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()


  1. 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.