動画ファイルから画像ファイルに変換
조회 수: 3 (최근 30일)
이전 댓글 표시
動画ファイルから画像ファイルに変換し、JPGファイルとして保存したいのですが、動画のファイルが大きいせいかエラーが出てしまいます。(以下参照)
この場合どのように工夫したら良いかわからず困っています。教えていただきたいです。
要求された 304x720x3x151582 (92.7GB) 配列は、最大配列サイズの基本設定
(8.0GB) を超えています。これにより、MATLAB は反応しなくなる可能性があります。
댓글 수: 2
Dyuman Joshi
2023년 10월 25일
Can you share the code that generated this error message when you ran it?
답변 (1개)
Jaynik
2023년 10월 23일
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
Jaynik
2023년 10월 25일
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
2023년 10월 25일
And your answer still does not recognize the problem OP is facing, let alone address it.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!