Conversion of pictures and videos to each other--matlab

Source: Internet
Author: User
First, the picture is converted to moive
function Im2movie (aviname, dirname)
% convert picture in catalog dirname to AVI movie (jpg image)
% aviname: AVI file name to save
% dirname: The path where the file is located, with no "/" at the end

t = CPUTime;
filename = Dir (strcat (dirname, '/*.jpg ')); % read file names in the directory
For i = 1:length (filename)
MOV (i) = Im2frame (Imread (strcat (dirname, '/', filename (i). name)));
End
Movie2avi (Mov,aviname);
E = cputime-t
Return



Second, Moive converted to pictures
Video compression format has a variety of, to use Aviread read in video, video compression format should be:
Videocompression: ' Cinepak '

Videocompression: ' FMP4 ' and videocompression: ' XVID '
FMP4 and XviD need to be converted to XviD first through dvid conversion software,
And then through the WinAVI conversion software converted to the ' Cinepak ' compression format;
and videocompression: ' Indeo5 ' can be converted directly via WinAVI conversion software to ' Cinepak ' compression format

Avi video converted to ' Cinepak ' compressed format, can be read through Aviread, and display related video information via Aviinfo
eg
>> aviinfo (' Kids.avi ')
Ans =
Filename: ' Kids.avi '
filesize:14548026
Filemoddate: ' 21-jul-2011 16:51:14 '
numframes:4488
Framespersecond:29.9700% frame rate
width:448
height:336
ImageType: ' TrueColor '
Videocompression: ' FMP4 '% compression format
quality:4.2950e+007
numcolormapentries:0
Audioformat: ' Format #80 '
audiorate:22050
Numaudiochannels:1




function Avi2im (aviname)
The role of this program is to convert AVI video into a frame of the image, Aviname for the video file name to be processed, in the form of AVI,
%avi video By default in the source directory, in this aviname do not write the specific path, as long as the correct file name is allowed,
The images converted into frames are also stored by default in the source directory.
%dirname is a new sub-folder, we will save the generated image to this folder
% an AVI video converted into a frame-by-frame program
% to provide you with a program to convert AVI video into frame sequence
% Usage: Create a source-named folder, put AVI video in,
% call Avi2im (' avi video name '), convert the frame sequence into the default place under the source folder.
% to install the appropriate decoder
Aviname=strcat (' source\ ', aviname);
Infoavi =aviinfo (aviname); % get technical information for AVI video
Frmnum=infoavi.numframes;
Mov=aviread (Aviname); % to install the appropriate decoder, you can convert the AVI file to a movie file
%mkdir (' C:\MATLAB7\work\source\traffic1 '); % New sub-folder to hold the resulting picture
For Frm=1:frmnum
mov =aviread (aviname,frm); % will read AVI video information into the frame
Imname=strcat (Aviname,int2str (frm), '. jpg '); % Edit the image name so that it can be stored in a subordinate folder without duplicate names
Imwrite (Mov.cdata,imname); % save image information to file for other handlers to use
End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.