Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HLS and YouTube Live support. #60

Merged
merged 8 commits into from
Nov 19, 2024
Merged

Conversation

tyler-romero
Copy link
Member

Add support for HTTP Live Streaming (HLS) and YouTube Live videos (which is just HLS under the hood).

Also do some general cleanup:

  1. remove unused imports
  2. clean up motion detection documentation
  3. support optional extra dependency installation
  4. move from python 3.7 -> python 3.9 (oldest version that is not out of service)


def _apply_camera_specific_options(self, options: dict) -> None:
if options.get("resolution"):
camera_name = self.config.get("name", "Unnamed {self.type} Stream")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing an f for the f string

@timmarkhuff
Copy link
Contributor

I tried out the youtube live streamer and my experience is that it returns the same frame multiple times in a row, making it appear to be very low FPS. Here is what I tried:

import framegrab
import cv2
import time
import numpy as np

youtube_url = "https://www.youtube.com/watch?v=oJUvTVdTMyY"

config = {
    'name': 'My Youtube Grabber',
    'input_type': 'youtube_live',
    'id': {
        'youtube_url': youtube_url
    }
}

grabber = framegrab.FrameGrabber.create_grabber(config)

frame_prev = grabber.grab()
while  True:
    t1 = time.time()
    frame = grabber.grab()
    cv2.imshow('frame', frame)
    key = cv2.waitKey(1)
    t2 = time.time()
    
    elapsed_time = t2 - t1
    fps = 1 / elapsed_time
    print(f'FPS: {round(fps, 2)}')
    
    if np.array_equal(frame, frame_prev):
        print('same')
    else:
        print('different')
    frame_prev = frame.copy()

This is the output I saw:

FPS: 3.07
same
FPS: 2.53
different
FPS: 3.13
same
FPS: 3.67
same
FPS: 3.29
same
FPS: 3.72
same
FPS: 3.91
same
FPS: 3.26
same
FPS: 3.6
same
FPS: 3.24
same
FPS: 3.34
same
FPS: 3.32
same
FPS: 3.56
same
FPS: 3.14
same
FPS: 3.69
same
FPS: 4.19
same
FPS: 3.46
same
FPS: 3.13
same
FPS: 2.63
different
FPS: 3.59
same

@tyler-romero
Copy link
Member Author

Fixed the issue! Now hitting 40 FPS with keep_connection_open=True and getting different frames

Copy link
Contributor

@timmarkhuff timmarkhuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tyler-romero tyler-romero merged commit d86b2d2 into main Nov 19, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants