Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Soundscapes community forum

Notifications
Clear all

Sonifying a video

David Sousa
(@david382)
Member Admin

There are many different ways to sonify a video. One possible manner is to map de average RGB values in each video frame to a frequency range or scale and atribute a different instrument to each color value. The following Python code exports the RGB data to a .csv file that can be uploaded to a software like TwoTone.

You just need to change the the file name 'file.mp4'.

import cv2
import csv

# Open the video file
cap = cv2.VideoCapture('file.mp4')

# Check if the video file is opened successfully
if not cap.isOpened():
    print("Error opening video file")
    exit()

# Create and open a CSV file for writing
with open('average_rgb_values.csv', mode='w', newline='') as file:
    writer = csv.writer(file)
    writer.writerow(['Frame Number', 'Average Red', 'Average Green', 'Average Blue'])

    while cap.isOpened():
        # Read a frame from the video
        ret, frame = cap.read()

        # If the frame was not read successfully, break the loop
        if not ret:
            break

        # Calculate the average RGB value for the frame
        average_color = cv2.mean(frame)

        # Write the average RGB value for the frame to the CSV file
        writer.writerow([int(cap.get(cv2.CAP_PROP_POS_FRAMES)), average_color[2], average_color[1], average_color[0]])

# Release the video capture object and close the video file
cap.release()
cv2.destroyAllWindows()

 

Quote
Topic starter Posted : 12/07/2024 7:46 am
paulprouse reacted
Share: