動画ファイルから画像ファイルに変換
Mostrar comentarios más antiguos
動画ファイルから画像ファイルに変換し、JPGファイルとして保存したいのですが、動画のファイルが大きいせいかエラーが出てしまいます。(以下参照)
この場合どのように工夫したら良いかわからず困っています。教えていただきたいです。
要求された 304x720x3x151582 (92.7GB) 配列は、最大配列サイズの基本設定
(8.0GB) を超えています。これにより、MATLAB は反応しなくなる可能性があります。
2 comentarios
Hiroshi Iwamura
el 19 de Oct. de 2023
右側の「参考」に
「動画ファイルを画像ファイルに」
が出ていると思いますのでそれを見てみてください。
Dyuman Joshi
el 25 de Oct. de 2023
Can you share the code that generated this error message when you ran it?
Respuestas (1)
Jaynik
el 23 de Oct. de 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 comentarios
Dyuman Joshi
el 23 de Oct. de 2023
Editada: Dyuman Joshi
el 23 de Oct. de 2023
1 - This answer does not address the problem OP is facing.
2 - Displaying image for each frame is like adding fuel to the fire.
3 - You can directly write the frame using imwrite(), there is no need to use getframe()
Jaynik
el 25 de Oct. de 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
el 25 de Oct. de 2023
And your answer still does not recognize the problem OP is facing, let alone address it.
Categorías
Más información sobre オーディオとビデオ en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!