Converting mpg video file to image file?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone,
I would like to find out is there a way to convert mpg video files to image files?
Thank you very much!
0 commentaires
Réponse acceptée
Walter Roberson
le 4 Oct 2011
2 commentaires
Walter Roberson
le 12 Déc 2011
No, do not change cdata to jpg, you will only confuse matters and it will have no benefit at all.
You do not need to imread() anything as you have already read the image in to mov(k). Using your variable names, A=mov(1).jpg is the replacement command instead of using imread().
I suggest you replace your existing reading code with
xyloObj = mmreader('20 cm view.mpg');
mov = read(xyloObj);
After which,
nFrames = size(mov,4);
ndigits = max(1,ceil(log10(nFrames+1)));
for k = 1 : nFrames
A = rgb2gray(mov(:,:,:,k));
imwrite(A, sprintf('mov%.0*d.gif',ndigits,k), 'gif');
end
The bit with nDigits and the odd format in the sprintf() are to calculate the number of decimal digits required to represent the highest frame number, and then to cause each individual frame number to be formatted with leading zeros. For example, you do not want mov9.gif to be followed by mov10.gif because if you do that, an alphabetic sort by file names would sort them as mov1.gif mov10.gif mov2.gif . So if the maximum frame number was (say) 3 digits you would instead want the files named mov009.gif mov010.gif so that numerically adjacent frames sort alphabetically next to each other.
You might notice that I left out the imread() of the following after you imwrite() it. Most of the time you do not want to read back in frames you just wrote out: about the only exception is when you are using a file format that has lossy compression (such as JPEG with default parameters) and it is important to you that you fetch the reconstructed (imprecise) data instead of the using the exact data that you already have in memory.
Plus de réponses (1)
Bjorn Gustavsson
le 12 Déc 2011
If you only want to convert the video frames to images I suggest that you use mplayer to do that part of the job:
Then you'll have the frames as images to continue your processing on.
0 commentaires
Voir également
Catégories
En savoir plus sur Convert Image Type dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!