Close Menu
Techs Slash

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Snow Removal Vancouver: Do You Need Snow Removal Services to Reduce Winter Liability Before It Becomes a Problem?

    May 7, 2026

    Cricket Road Demo account verification guide for Bangladeshi players

    May 6, 2026

    Road Cricket Slot registration steps – Easy sign‑up guide for Indian players

    May 6, 2026
    Facebook X (Twitter) Instagram
    Techs Slash
    • Home
    • News
      • Tech
      • Crypto News
      • Cryptocurrency
    • Entertainment
      • Actors
      • ANGEL NUMBER
      • Baby Names
      • Beauty
      • beauty-fashion
      • facebook Bio
      • Fitness
      • Dubai Tour
    • Business
      • Business Names
    • Review
      • Software
      • Smartphones & Apps
    • CONTRIBUTION
    Facebook X (Twitter) Instagram
    Techs Slash
    Home»python»Python 3 FFMPEG Script to Build & Extract Facial Recognition From RTMP Live Streaming Video in Browser
    python

    Python 3 FFMPEG Script to Build & Extract Facial Recognition From RTMP Live Streaming Video in Browser

    Ranveer KumarBy Ranveer KumarOctober 1, 2022No Comments3 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email

    Warning: Trying to access array offset on value of type bool in /home/cadesimu/techsslash.com/wp-content/themes/smart-mag/partials/single/featured.php on line 78
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Python 3 FFMPEG Script to Build & Extract Facial Recognition From RTMP Live Streaming Video in Browser

    import syssys.path.append('/home/raiy/.local/lib/python3.7/site-packages')  # Path for import following libs import cv2import face_recognitionimport numpy as npfrom datetime import datetimeimport time def extractFaces(media_path, filename, output_path):    cap = cv2.VideoCapture(media_path + filename)    extracted, face_areas = [], []    process_this_frame = True    num_of_captured = 0     while True:        try:            ret, frame = cap.read()            #cv2.imshow(frame)            small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)        except:            break        rgb_small_frame = small_frame[:, :, ::-1]         if process_this_frame:            locations = face_recognition.face_locations(rgb_small_frame, number_of_times_to_upsample=3) # Only works when number_of_times_to_upsample = 3            captured = face_recognition.face_encodings(rgb_small_frame, locations)            for i, face in enumerate(captured):                top, right, bottom, left = locations[i]                area = (right-left)*(bottom-top)                matches = face_recognition.compare_faces(extracted, face)                if matches and any(matches):                    face_distances = face_recognition.face_distance(extracted, face)                    best = np.argmin(face_distances)                    if matches[best] and area >= face_areas[best]:                        extracted[best] = face                        face_areas[best] = area                        cv2.imwrite(output_path+ filename + '_' + str(best + 1) + '.jpg', frame[top*4:bottom*4, left*4:right*4]) # Save only the face                        #cv2.imwrite(output_path+ filename + '_' + str(best + 1) + '.jpg', frame)                                # Save the whole frame                else:                    extracted.append(face)                    face_areas.append(area)                    num_of_captured += 1                    cv2.imwrite(output_path + filename + '_' + str(num_of_captured) + '.jpg', frame[top*4:bottom*4, left*4:right*4])  # Save only the face                    #cv2.imwrite(output_path+ filename + '_' + str(num_of_captured) + '.jpg', frame)                                  # Save the whole frame         process_this_frame = not process_this_frame    return len(extracted)     if __name__ == '__main__':    media_path, filename, output_path = sys.argv[1:4]      #'/var/www/live/', 'android-04-Apr-20-13:52:31.flv', '/home/raiy/Desktop/face_test/results/'     with open(output_path + 'extractFaces.log', 'a') as f:        f.write(datetime.now().strftime("[%m-%d-%Y, %T]  "))        f.write('Start with video = {}\n'.format(media_path+filename))        results = extractFaces(media_path, filename, output_path)        f.write(datetime.now().strftime("[%m-%d-%Y, %T]  "))        f.write('Finished with {} extracted faces saved in {}\n'.format(results,  output_path))
    #user www-data;  # Default settinguser root;       # For exec_push command worker_processes auto;pid /run/nginx.pid;include /etc/nginx/modules-enabled/*.conf; events {worker_connections 768;# multi_accept on;} http { ### Basic Settings## sendfile on;tcp_nopush on;tcp_nodelay on;keepalive_timeout 65;types_hash_max_size 2048;# server_tokens off; # server_names_hash_bucket_size 64;# server_name_in_redirect off; include /etc/nginx/mime.types;default_type application/octet-stream; ### SSL Settings## ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLEssl_prefer_server_ciphers on; ### Logging Settings## access_log /var/log/nginx/access.log;error_log /var/log/nginx/error.log; ### Gzip Settings## gzip on; # gzip_vary on;# gzip_proxied any;# gzip_comp_level 6;# gzip_buffers 16 8k;# gzip_http_version 1.1;# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; ### Virtual Host Configs## include /etc/nginx/conf.d/*.conf;include /etc/nginx/sites-enabled/*; server {  # For Django_test     listen         5000;     server_name    127.0.0.1     charset UTF-8;     access_log      /var/log/nginx/Django_test_access.log;     error_log       /var/log/nginx/Django_test_error.log;     client_max_body_size 75M;   location / {         include uwsgi_params;         uwsgi_pass 127.0.0.1:8000;        uwsgi_read_timeout 2;     }}  # End for Django_test  server {    # For playbacklisten 8099;server_name _;#root /var/www/live;location /live {alias /var/www/live;expires max;} }  # End for HLS playback   }   # End for http  rtmp {     # For RTMP streamingserver {listen 1935;         # port to outside#server_name 127.0.0.1chunk_size 4096;#location /live {     # To Django server test# include uwsgi_params;# uwsgi_pass 127.0.0.1:8000;# uwsgi_read_timeout 2;#}  application live {   # Streaming on rtmp://[address_of_site]/live/[filename]live on;record all;record_path /var/www/live;  # Save streamed video torecord_suffix -%d-%b-%y-%T.flv;  # Save filename as current_time.flvexec_publish /home/raiy/Desktop/face_test/stream_analysis.sh $app $name;} application go {play /var/www/live;} }}   #mail {# # See sample authentication script at:# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript## # auth_http localhost/auth.php;# # pop3_capabilities "TOP" "USER";# # imap_capabilities "IMAP4rev1" "UIDPLUS";## server {# listen     localhost:110;# protocol   pop3;# proxy      on;# }## server {# listen     localhost:143;# protocol   imap;# proxy      on;# }#}
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Ranveer Kumar
    • Website

    Related Posts

    JSONDecodeError: Expecting value: line 1 column 1 (char 0)

    December 18, 2023

    Why does math.log result in ValueError: math domain error?

    December 17, 2023

    “inconsistent use of tabs and spaces in indentation” [duplicate]

    December 16, 2023
    Leave A Reply Cancel Reply

    Top Posts

    Sapne Me Nahane Ka Matlab

    March 18, 2024

    Sapne Me Nagn Stri Dekhna

    March 18, 2024

    Self Reliance: Release Date, Cast, Plot, Trailer, and More Information

    March 18, 2024

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    ABOUT TECHSSLASH

    Welcome to Techsslash! We're dedicated to providing you with the best of technology, finance, gaming, entertainment, lifestyle, health, and fitness news, all delivered with dependability.

    Our passion for tech and daily news drives us to create a booming online website where you can stay informed and entertained.

    Enjoy our content as much as we enjoy offering it to you

    Most Popular

    Sapne Me Nahane Ka Matlab

    March 18, 2024

    Sapne Me Nagn Stri Dekhna

    March 18, 2024

    Self Reliance: Release Date, Cast, Plot, Trailer, and More Information

    March 18, 2024
    CONTACT DETAILS

    Phone: +92-302-743-9438
    Email: contact@serpinsight.com

    Our Recommendation

    Here are some helpfull links for our user. hopefully you liked it.

    kakekmerah4d

    Techs Slash
    Facebook X (Twitter) Instagram Pinterest
    • Home
    • About us
    • contact us
    • Affiliate Disclosure
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • Write for us
    • Daman Game
    © 2026 Techsslash. All Rights Reserved

    Type above and press Enter to search. Press Esc to cancel.