動画ファイルから画像ファイルに変換
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
動画ファイルから画像ファイルに変換し、JPGファイルとして保存したいのですが、動画のファイルが大きいせいかエラーが出てしまいます。(以下参照)
この場合どのように工夫したら良いかわからず困っています。教えていただきたいです。
要求された 304x720x3x151582 (92.7GB) 配列は、最大配列サイズの基本設定
(8.0GB) を超えています。これにより、MATLAB は反応しなくなる可能性があります。
2 Commenti
Dyuman Joshi
il 25 Ott 2023
Can you share the code that generated this error message when you ran it?
Risposte (1)
Jaynik
il 23 Ott 2023
Hi 舞美,
私は日本語がネイティブではないので、この質問に英語で答えてみます。 ご理解のほどよろしくお願いいたします。
I understand that you want to convert a video file into ‘jpg’ files and assume that you want to save the individual frames from the videos as images. You can use the “VideoReader” class for performing this task. Following is a sample code that performs the task:
v = VideoReader('your_video_file.mp4');
numberOfFrames = v.NumFrames;
for frame = 1: numberOfFrames
% Extract the frame
thisFrame = read(v, frame);
% Display it
image(thisFrame);
drawnow;
outputBaseFileName = sprintf('Frame %4.4d.jpg', frame);
outputFullFileName = fullfile('./', outputBaseFileName);
frameWithText = getframe(gca);
imwrite(frameWithText.cdata, outputFullFileName, 'jpg');
end
For larger videos, you can consider processing the video in smaller chunks or frames. Additionally, using video compression techniques or converting the video to a lower resolution or different format can help reduce the file size and make it more manageable for processing.
You can read more about the “VideoReader” class here:
Hope this helps!
3 Commenti
Jaynik
il 25 Ott 2023
Using "imwrite" after reading the frame would be better for larger files. The given code is just a sample to get frames and should be edited as per the use case.
Dyuman Joshi
il 25 Ott 2023
And your answer still does not recognize the problem OP is facing, let alone address it.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!