How to get higher FPS (change resolution from YUYV to MPEG)

Hi. The following code gives me 5FPS on 4k (on YUYV). I am trying to use MPEG instead (or at least increase the fps somehow).

Regards


aligned_faces =
with degirum_tools.Display(‘AI Camera’, show_fps = True) as output_display, degirum_tools.open_video_writer(‘fr_results_all_4k.mp4’,
w = 640, h = 480, fps = 60.0) as video_writer:
for detected_faces in degirum_tools.predict_stream(f_det_model, video_source):
if detected_faces.results:
for face in detected_faces.results:
landmarks = [landmark[‘landmark’] for landmark in face[‘landmarks’]]
aligned_face, _ = align_and_crop(detected_faces.image, landmarks)
face_embedding = f_rec_model(aligned_face).results[0][‘data’][0]
print(f’face embedding: {face_embedding}‘)
identities, similarity_scores = identify_faces([face_embedding], tbl, field_name, metric_type, top_k)
print(f’identities: {identities}, similarity scores: {similarity_scores}’)
identity = identities[0]
if identity and identity != ‘Unknown’:
print(f’identity: {identity}‘)
face[‘label’] = identities[0]
face[‘score’] = similarity_scores[0]
if identity == ‘MOM’: identity = ‘roza’
suspect_info = PersonInformation(last_name=suspect_last_name(identity))
print(f’suspect info: {suspect_info}’)
if suspect_info:
print(f’suspect_info: {suspect_info}‘)
suspect_upload = upload_suspect_single(suspect_info)
print(f’suspect upload response: {suspect_upload}’)

            aligned_faces.append(aligned_face) 
    video_writer.write(detected_faces.image)
    output_display.show(detected_faces)

Hi @svafadar19 ,

First, I would recommend to determine, what is the bottleneck in your code.

I would start with the very simple case, when you do only video decoding:

t = degirum_tools.Timer()
n = 0
for frame in video_source:
    n += 1
print(f"Decoding FPS={n/t()}")

Then I would add display:

with degirum_tools.Display(‘AI Camera’, show_fps = True) as output_display:
    t = degirum_tools.Timer()
    n = 0
    for frame in video_source:
       output_display.show(frame)
        n += 1
    print(f"Decoding+Display FPS={n/t()}")

Then I would add file saving (encoding):

with degirum_tools.Display(‘AI Camera’, show_fps = True) as output_display, degirum_tools.open_video_writer(‘fr_results_all_4k.mp4’, w = 640, h = 480, fps = 60.0) as video_writer:
    t = degirum_tools.Timer()
    n = 0
    for frame in video_source:
       output_display.show(frame)
       video_writer.write(detected_faces.image)
        n += 1
    print(f"Decoding+Display+Saving FPS={n/t()}")

Then add other steps one by one and monitor for FPS. You will quickly find, which step is the bottleneck (and I believe it is not an inference, but most likely video display and video saving).