How to convert 4K mp4 video into frames?

35 ビュー (過去 30 日間)
Vimal Raj
Vimal Raj 2021 年 1 月 8 日
コメント済み: Vimal Raj 2021 年 1 月 20 日
How do i convert 4K video into frames..
video recorded in gopro camera and stored in mp4 format.

採用された回答

Nitin Kapgate
Nitin Kapgate 2021 年 1 月 11 日
編集済み: Nitin Kapgate 2021 年 1 月 11 日
You can refer to the code snippet below which demonstrates extraction of frames and export of the frames to a folder:
% import the in-built video file, replace 'xylophone.mp4' with your file name
vidObj = VideoReader('xylophone.mp4');
% read the total number of frames
frames = vidObj.NumFrames;
% file format of the frames to be saved in
imageFormat ='.png';
% create a new folder for frames
mkdir frames
% reading and writing the frames
for x = 1 : frames
% converting integer to string
frameIndex = num2str(x);
% concatenating 2 strings to get indexed frame name
frameName = strcat(frameIndex, imageFormat);
% read x'th frame from video
vidFrame = read(vidObj, x);
cd frames
% exporting the frames to the folder
imwrite(vidFrame, frameName);
cd ..
end
You can refer to the documentation for read function here.
  5 件のコメント
Nitin Kapgate
Nitin Kapgate 2021 年 1 月 19 日
I understand that the error "Failed to Initialize internal resources" pops up when trying to use the 'VideoReader' function.
There could be various reasons behind this error which are listed as follows:
  1. The required codec is missing for the particular video file. Determine whether the codec is installed on the computer.
  2. The video file contains an audio stream (eg. AC-3) not supported by the API (QTKit, in AC-3 case) used by VideoReader. The only workaround is to re-encode the audio stream in the file into a different format such as MPEG-4/AAC and then try to read the file.
  3. Sometimes, VideoReader cannot open a video file for reading on Windows platforms. This might occur if you have installed a third-party codec that overrides your system settings. Uninstall the codec and try opening the video file in MATLAB again.
The supported container formats and codecs link explains supported codecs in detail. Go through the troubleshooting section to determine if that could be a possibility in this particular case.
Vimal Raj
Vimal Raj 2021 年 1 月 20 日
Thank you sir... Thank you soo Much. it works..
One more clarification sir, after convering the format, the quality seems tobe lowered than the original video.
The reason why i go for 4K is its quality only. but, after conversion process, the video and frames look like a compressed one (diminished colors). Size of the video also reduced to half of the original.
Any way to rectify that sir.. Also, at the end of frame conversion, again getting this error sir
>> gopro4k
Error using pngwritec
PNG library failed: Write Error.
Error in writepng (line 280)
pngwritec(data, map, filename, colortype, bitdepth, ...
Error in imwrite (line 546)
feval(fmt_s.write, data, map, filename, paramPairs{:});
Error in gopro4k (line 27)
imwrite(vidFrame, frameName );
An error was encountered while saving the command history

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by