Hi mari,
I understand that you are trying to get a plot of an MP4 file but are facing the error: “Error using plot - Data must be numeric, datetime, duration or an array convertible to double”. This error occurs because “file = VideoReader('video.mp4')” creates a “VideoReader” object, not numeric data. The “plot” function requires numeric or time-series data, but file is an object, causing the issue.
To resolve this error, I am assuming that you are either looking to plot pixel intensities over time or visualize audio signals over time, as these are the most relevant aspects when plotting an MP4 file.
For plotting pixel intensities over time:
- Use the “VideoReader” function to extract frames.
- Convert frames to grayscale using “rgb2gray” function.
- Compute the mean intensity for each frame.
- Plot the mean intensity over time to visualize brightness changes.
Kindly refer to the following code for the same:
video = VideoReader('video.mp4');
numFrames = video.NumFrames;
frameRate = video.FrameRate;
t = (0:numFrames-1) / frameRate;
frameIntensities = zeros(1, numFrames);
grayFrame = rgb2gray(frame);
frameIntensities(k) = mean(grayFrame(:));
plot(t, frameIntensities, 'LineWidth', 1.5);
title('Video Frame Intensity Over Time');
ylabel('Average Intensity');
Alternatively, for plotting audio signals of an MP4 file over time:
- Extract audio from the MP4 file using “audioread” function.
- Generate a time vector based on the sampling rate.
- Plot the audio signal over time.
Kindly refer to the following code for the same:
[audioData, Fs] = audioread('video.mp4');
t = (0:length(audioData)-1) / Fs;
title('Original Signal in Time Domain')
For further reference on the MATLAB functions used here, please refer to the documentation below:
Cheers & Happy Coding!