Clear Filters
Clear Filters

動画ファイルから画像ファイルに変換

10 views (last 30 days)
舞美
舞美 on 19 Oct 2023
Commented: Dyuman Joshi on 25 Oct 2023
動画ファイルから画像ファイルに変換し、JPGファイルとして保存したいのですが、動画のファイルが大きいせいかエラーが出てしまいます。(以下参照)
この場合どのように工夫したら良いかわからず困っています。教えていただきたいです。
要求された 304x720x3x151582 (92.7GB) 配列は、最大配列サイズの基本設定
(8.0GB) を超えています。これにより、MATLAB は反応しなくなる可能性があります。
  2 Comments
Hiroshi Iwamura
Hiroshi Iwamura on 19 Oct 2023
右側の「参考」に
「動画ファイルを画像ファイルに」
が出ていると思いますのでそれを見てみてください。
Dyuman Joshi
Dyuman Joshi on 25 Oct 2023
Can you share the code that generated this error message when you ran it?

Sign in to comment.

Answers (1)

Jaynik
Jaynik on 23 Oct 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 Comments
Jaynik
Jaynik on 25 Oct 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
Dyuman Joshi on 25 Oct 2023
Yes, and you read the frame using read, so once again, there is no need to use getframe().
And your answer still does not recognize the problem OP is facing, let alone address it.

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!