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

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.

Related

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.

Processing very huge video files in 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.

Information about video.MultimediaFileWriter

I have used video.MultimediaFileWriter to write frames from input AVI video file to an output AVI video file. After the output file is created the size of the output file is very large. I have used VideoCompressor's provided in MATLAB options. For example: for an input video size of 3.42MB after using compression techniques provided by MATLAB the output video size is 98.5MB.
Can anyone tell me how to bring the output AVI file to size of the input file?
The creation of videos using H.264 was added in R2012a. Older versions support the less efficient codecs MJPEG and DV, which probably explain your large files. However, this is not a major problem because you can recompress your videos using free tools, such as VirtualDub and x264. Here is a tutorial.

How do you use afconvert to convert from wav to aac caf WITHOUT RESAMPLING

I'm making an Iphone game, we need to use a compressed format for sound, and we want to be able to loop SEAMLESSLY back to a specific sample in the audio file (so there is an intro, then it loops back to an offset)
currently THE ONLY export process I have found that will allow seamless looping (reports the right priming and padding frame numbers, no clicking when looping ect) is using apple's afconvert to a aac format in a caf file.
but when we try and encode to lower bitrates, it automatically re samples the sound! we do NOT want to have the sound re sampled, every other encoder I have encountered has an option to set the output sample rate, but I can't find it for this one.
on another note, if anyone has had any luck with seamless looping of a compressed file format using audio queues, let me know.
currently I'm working off the information found at:
http://developer.apple.com/mac/library/qa/qa2009/qa1636.html
note that this DID work PERFECTLY when I left the bitrate for the encode at default (~128kbs) but when I set it to 32kbps - with the -b option - it resampled, and looping clicks now.
It needs to be at least 48kbps. 32kbps will downsample to a lower sample rate.
I think you are confusing sample rate (typical values: 32kHz, 44.1kHz, 48kHz) and bit rate (typical values: 128kbps, 160kbps, 192kbps).
For a bit rate, 32kbps is extremely low. Sound will have bad quality at this bit rate. You probably intended to set the sample rate to 32kHz instead, which is also not outright typical, but makes more sense.
When compressing to AAC and uncompressing back to WAV, you will not get the same audio file back, because in AAC, the audio data is represented in a completely different format than in raw wave. E.g. you can have shifts by few microseconds, which are necessary to convert to the compressed format. You can not completely get around this with any highly compressed format.
The clicking sound originates from the sudden change between two samples which are played in direct succession. This is likely taking place because the offset to which you jump back in your loop does not end up to be at exactly the same position in the AAC file as it was in the WAV file (as explained above, there can shifts by microseconds).
You will not get around these slight changes when compressing. Instead, you have to compensate for them after compression by adjusting the offset. That means you have to open the compressed sound file in an audio editor, e.g. Audacity, and manually find another offset close to the original one, which is suitable for looping.
How to find an offset which is suitable for looping?
Zoom in to the waveform's end. Look at how the waveform looks there. Then zoom in to the waveform at the original offset and search in its neighbourhood for an offset at which the waveform connects seamlessly to the end of the waveform.
For an example how this shoud look like, open the uncompressed audio file in the audio editor and examine the end of the waveform and the offset there.