Processing very huge video files in Matlab - matlab

I am new to MATLAB, I have few videos of ~100GB each (10hrs duration). I want to calculate some features on every nth frame of the video. I have followed this code But my computer sleeps for just finding number of frames in one video. i.e.
nFrames = get(vidObj, 'NumberOfFrames');
Is there any faster way to process huge videos like I have as this seems to be very slow. Also I have tried looking in internet but didnt find any reasonable solution.
Thanks in advance.

Matlab is dogslow,so you can use ffmpeg instead. Your specific functionality being kept aside, you can extract individual images from a video using below command:
ffmpeg -i input.mp4 -vf fps=60 out%d.png
Ffmpeg video processing is way faster compared to Matlab video processing.

Related

Flutter FFMPEG Increases in processing time based on size of video even when only cutting the same size

I am by no means an expert with ffmpeg. But I'm finding it strange that the the time to create a gif and trim that section is increasing so much based on the size of the video since I am always grabbing only three seconds.
I am using flutter FFmpeg.
-ss 0:00:01.000000, -i /data/user/0/com.example.example/cache/image_picker1475407716366431469.mp4 -t, 0:00:03.000000 -avoid_negative_ts make_zero, -vf fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse, -loop 0
Is there a command to make sure that ffmpeg doesn't concentrate on the entire video, and only concentrates on the three seconds I am getting in -t, so that the time doesn't increase greatly based on the video size. Or is this just normal for ffmpeg. Does it have to parse the entire video, before creating the gif.
I found a solution for anyone else looking. For some reason its much faster to just trim the original video and then make a gif. So just running '-c:v copy ' on the original video and then running the above command cut the processing time on a 3 minute video down from 1 minute 40 seconds to 10 seconds.

How to pass a sequence of jpeg data from MATLAB to ffplay

I want to playback sensor data from different sensors in matlab synchronously. For most data I use updating plots. However, I have difficulties to find an efficient way to playback a sequence of jpeg data as video on screen (720p or 1080p).
One way i tried is to use the matlab function to convert the jpeg data to raw matlab images (https://nl.mathworks.com/help/robotics/ref/readimage.html) and then display it with the imshow function. This way is very slow and therefore not suitable.
Another way was to write the jpeg data to a file (fwrite) and using the matlab system command to execute ffplay:
ffplay -loglevel panic -framerate 30 -i output.jpg
This works for showing single .jpeg's, but is becoming tricky when I want to play a sequence of jpeg data as a movie. If I write all jpeg data sequentially to a file and run ffplay afterwards, I can playback the movie correctly. But what I want to playback on the fly (i.e. stream) and not wait until all data is written to the file before playback.
Is there a suitable way to share the jpeg data from matlab directly to ffplay in order to play a sequency of jpeg data on-the-fly? Any other suggestions to tackle this problem are also welcome.

Play an mp3 in Matlab

What I have
An mp3 file, 16kHz, 1 channel. Read like:
[data,Fs] = audioread('file.mp3');
This file is playable in Windows Media Player i.e., and works fine.
What I want
To play it inside matlab. After reading it, I've tried to play it, like:
soundsc(data);
However, it doesn't sound even near to how it should (neither using sound instead of soundsc).
The Problem then is..
How can I play this mp3 vector inside matlab? Is it even possible? Or do I need to convert it to other format so I can work with it? (wav I guess?)
You are missing the sample frequency. You need
soundsc(data, Fs)
If not present, the Fs argument defaults to 8192 Hz, which is not the correct one.
Also, note that if you don't need scaling you can use
sound(data, Fs)
which will run a little faster.

MATLAB avi file read

Is there a way to read .avi video file frame by frame using mmread or other function, similar to using videoReader, and readFrame functions?
I used mmread but it took a long time to read each frame as it read all the frames before the specified frame.
In general the media and movie reading in Matlab is cumbersome. I changed to python because of it. I would recommend to split the movie into single image files using tools like avconv or ffmpg and then work on the images, as the image manipulation toolbox is much faster.
If you want to go forward and backward through any movie, especially backwards is very slow. Very often it is implemented, by rewinding and than seeking out your frame, so basically to go from frame 100 to 99, Matlab rewinds to 0 and then seeks through the binary stuff to 99.

Executing VideoReader('movie.mp4') takes so long in Matlab

I am trying to read many video files from a database and process them. I am using Matlab and my problem is that when I want to read a 10 minutes long full HD video I should wait so much and my computer stops performing well. I use this command
VideoReader('movie.mp4')
I have seen that it takes 47 seconds to read a 30 seconds long video in the same format. I do not need to load all frames into my memory I just need 11 frames for each step of my process and really got stock here. Any help will be appreciated.
Also here is my output when I run this command
disp(videoObj);
output:
Summary of Multimedia Reader Object for 'movie.mp4'.
Video Parameters: 30.00 frames per second, RGB24 1280x720.
1482 total video frames available.
By the way I am running my code on Matlab R2014a and my OS is ubuntu 14.0.4.
Siavash,
The long loading time is because the entire file is scanned to determine the number of frames. This process is necessary to support frame indexed based access. In R2014b and higher, the frame counting during construction has been disabled. Additionally, you can seek to specific locations in the file using the CurrentTime property and use the hasFrame/readFrame methods for reading to avoid this performance penalty
Dinesh
I'm using version R2015b and I find the same slow processing of mp4 files with the VideoReader and readFrame functions. However, I find that those functions perform much faster on an avi file than an mp4, so I first convert the mp4 to avi using an independent program from https://www.ffmpeg.org. I don't know why there's such a difference in speed between the two...perhaps someone from MATLAB can provide some insight into that question.