So i am trying to cut an mp4 file , and remove the last 20% I go from start :) and i have this code where 5833 is the last frame i want to write
videoFReader = vision.VideoFileReader('2018-07-30_21h52_48.mp4');
videoFWriter = vision.VideoFileWriter('myFile.avi','FrameRate',...
videoFReader.info.VideoFrameRate);
for i=1:5833
videoFrame = step(videoFReader);
step(videoFWriter,videoFrame);
end
I observed that : 1. My CPU is used around 25% (only one core from 8) 2. the process is very slow - the original file is 45 Mb but 5 minutes passed and is still at 80% done ..
Any workaround to make it faster (use GPU / or multi core ) ? For a professional product this is kinda of embarrassing :(

11 Kommentare

From the website:
Video Reading Performance on Windows Systems:To achieve better video reader performance on Windows for MP4 and MOV files, MATLAB uses the system's graphics hardware for decoding. However, in some cases using the graphics card for decoding can result in poorer performance depending on the specific graphics hardware on the system. If you notice slower video reader performance on your system, turn off the hardware acceleration by typing:
matlab.video.read.UseHardwareAcceleration('off')
Also, are you using an SSD or a HDD?
Can't use multicore as writing frames will go out of order. Also, what kind of compression are you using? The more you compress, the more time it should take.
Use profile to determine if it's reading or writing that's slow https://www.mathworks.com/help/matlab/ref/profile.html
profile on
trimVideo %run your code
profview
timo
timo am 31 Jul. 2018
Why isnt the mathworks function smart enough to toggle hw accel on/off ?...Yes I am using SSD... regarding multicore and out of order !?! Are yous serious ... Split the movie in 8 parts - the part to be cut .Each core will seek its position from pos1,, pos2 ... pos8 and write the output frames in temp1 , temp 2 ... temp 8 in PARALLEL . At the end merge the 8 pieces .... Simple yes :P ?
OCDER
OCDER am 31 Jul. 2018
Why isnt the mathworks function smart enough to toggle hw accel on/off?
Because it'll be like giving Mathworks full control over your computer. Border line to malware.
Yes I am using SSD.
Good! Disk write speed should be fast.
Split the movie in 8 parts - the part to be cut...
Suuure, you could do processing like this, but you only have 1 hard drive that stores a image frames in chunks. How are you going to write to disk in parallel chunks like that? You'll have to create 8 files, then reopen, join, and resave using a single core. Or corrupt your file due to RACE condition.
timo
timo am 31 Jul. 2018
Yes you can have 8 process working on 8 parts of file . If the memory is enough , this can be stored in memory , even if its not enough for sure you can write from 8 processes in parallel on the hard drive . When all process finish then the file is assembled -> no race condition . Dude do you have any clue what are you talking about ? -_-''
OCDER
OCDER am 31 Jul. 2018
Bearbeitet: OCDER am 31 Jul. 2018
You: "For a professional product (Matlab) this is kinda of embarrassing :("
I feel a lot of your posts are condescending towards Mathworks or the volunteers trying to help you... By all means, please do write to hard drive in parallel and ignore the our advice.
timo
timo am 31 Jul. 2018
I am just saying , dont try to give advice if you dont know what you are talking about lol .
OCDER
OCDER am 1 Aug. 2018
"Split the movie in 8 parts - the part to be cut .Each core will seek its position from pos1,, pos2 ... pos8 and write the output frames in temp1 , temp 2 ... temp 8 in PARALLEL . At the end merge the 8 pieces .... Simple yes :P ?"
Interesting. You should upload that multicore video writer as it seems you figured it out. Your code will be a huge success in FEX, and MATLAB's "embarrassing" slow code can finally be replaced by your fast code. We look forward to learning from you!
timo
timo am 1 Aug. 2018
Well i can make a demo where i have a file with 100000 integers. I make 5 processes who read the number in parallel and then write at the end the values merged . If you pay me 50 bucks i can make the demo . Do you need my email address for paypal :) ?
timo
timo am 1 Aug. 2018
Do you accept the challenge ? If i cannot do it i will pay u 50 bucks.
OCDER
OCDER am 1 Aug. 2018
Bearbeitet: OCDER am 1 Aug. 2018
I really do support your efforts to make a multithreaded video WRITER, not multithreaded video processor or reader. VideoWriter is slow for you and others, and you'll be doing yourself and others a favor. The multithreaded video writer would be great - just ignore my skepticism, as that comes from my ignorance.
"for sure you can write from 8 processes in parallel on the hard drive ." "Well i can make a demo where i have a file with..." "If i cannot do it..."
So can you or can you not do it???
"If you pay me 50 bucks i can make the demo... If i cannot do it i will pay u 50 bucks."
No. Why pay you 50 before you make something, and if you fail, you just return (or not return) 50? Sounds unfair.... Plus, it's maybe a violation of forum policy to request money for code/service.
"Content that you submit must be offered free of charge. You may not use the Site to sell or market your products or services to others."
Jan
Jan am 2 Aug. 2018
Let's keep the discussion on a professional level.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Jan
Jan am 2 Aug. 2018

0 Stimmen

Matlab is not the perfect tool for cropping MP4 files. Why not let a special tool like ffmpeg do this? See https://www.ffmpeg.org/

3 Kommentare

timo
timo am 2 Aug. 2018
Bearbeitet: Jan am 3 Aug. 2018
Finally a sane answer. Thank you and it worked
Dinesh Iyer
Dinesh Iyer am 3 Aug. 2018
In 18a, there have been performance improvements made to VideoWriter as per the release notes. Maybe you can give 18a a shot.
timo
timo am 3 Aug. 2018
Hello I have latest Matlab

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Version

R2018a

Tags

Gefragt:

am 30 Jul. 2018

Bearbeitet:

Jan
am 3 Aug. 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by