matlab使用avifile制作视频、VideoReader读取视频和movie函数将图片以视频方式播放

系统环境:matlab2012a+win7

一 、avifile制作视频:

clc;clear;close all;
f_str=1;f_end=630; % 起始和结束帧
r_path='图片读取路径';

video_name='video‘; %你想制作的视频名称

aviobj=avifile(video_name); %此时你可以看见在当前文件夹下创建了一个avi视频文件(是空的)
aviobj.Quality = 60; % 视频质量,0-100之间,数值越大视频字节也越大
aviobj.Fps = 20; %创建视频的帧率
aviobj.compression='None'; %可选的压缩方式有:  'Indeo3'(默认), 'Indeo5', 'Cinepak', 'MSVC', 'RLE' or 'None'.

for i=f_str:f_end
    pic=imread([r_path,int2str(i),'.jpg']); %从你指定的文件夹读取图片
 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
你可以使用C#中的Screen类来截取屏幕,然后使用AVIFile库将截取的屏幕帧保存为AVI格式的视频文件。以下是一个简单的示例代码: ```csharp using System; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices; namespace ScreenRecorder { public partial class Form1 : Form { [DllImport("user32.dll")] static extern IntPtr GetDesktopWindow(); [DllImport("user32.dll")] static extern IntPtr GetWindowDC(IntPtr hWnd); [DllImport("user32.dll")] static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC); [DllImport("avifil32.dll")] static extern void AVIFileInit(); [DllImport("avifil32.dll")] static extern void AVIFileExit(); [DllImport("avifil32.dll")] static extern int AVIFileOpenW(ref IntPtr ppfile, [MarshalAs(UnmanagedType.LPWStr)]string szFile, int uMode, int pclsidHandler); [DllImport("avifil32.dll")] static extern int AVIFileCreateStream(IntPtr pfile, out IntPtr ppavi, ref AVISTREAMINFOW psi); [DllImport("avifil32.dll")] static extern int AVIStreamSetFormat(IntPtr avi, int lPos, ref BITMAPINFOHEADER lpFormat, int cbFormat); [DllImport("avifil32.dll")] static extern int AVIStreamWrite(IntPtr pavi, int lStart, int lSamples, IntPtr lpBuffer, int cbBuffer, int dwFlags, int dummy1, int dummy2); [DllImport("avifil32.dll")] static extern int AVIStreamRelease(IntPtr pavi); [DllImport("avifil32.dll")] static extern int AVIFileRelease(IntPtr pfile); [StructLayout(LayoutKind.Sequential, Pack = 1)] struct BITMAPINFOHEADER { public int biSize; public int biWidth; public int biHeight; public short biPlanes; public short biBitCount; public int biCompression; public int biSizeImage; public int biXPelsPerMeter; public int biYPelsPerMeter; public int biClrUsed; public int biClrImportant; } [StructLayout(LayoutKind.Sequential, Pack = 1)] struct AVISTREAMINFOW { public int fccType; public int fccHandler; public int dwFlags; public int dwCaps; public short wPriority; public short wLanguage; public int dwScale; public int dwRate; public int dwStart; public int dwLength; public int dwInitialFrames; public int dwSuggestedBufferSize; public int dwQuality; public int dwSampleSize; public short left; public short top; public short right; public short bottom; } IntPtr aviFile = IntPtr.Zero; IntPtr aviStream = IntPtr.Zero; BITMAPINFOHEADER bih = new BITMAPINFOHEADER(); public Form1() { InitializeComponent(); } private void btnStart_Click(object sender, EventArgs e) { AVIFileInit(); // 打开AVI文件 AVIFileOpenW(ref aviFile, "test.avi", 4097, 0); // 设置流格式 bih.biSize = Marshal.SizeOf(typeof(BITMAPINFOHEADER)); bih.biWidth = Screen.PrimaryScreen.Bounds.Width; bih.biHeight = Screen.PrimaryScreen.Bounds.Height; bih.biPlanes = 1; bih.biBitCount = 24; bih.biCompression = 0; bih.biSizeImage = bih.biWidth * bih.biHeight * 3; AVISTREAMINFOW strhdr = new AVISTREAMINFOW(); strhdr.fccType = 1935960438; strhdr.fccHandler = 0; strhdr.dwFlags = 0; strhdr.dwCaps = 0; strhdr.wPriority = 0; strhdr.wLanguage = 0; strhdr.dwScale = 1; strhdr.dwRate = 25; strhdr.dwStart = 0; strhdr.dwLength = 0; strhdr.dwInitialFrames = 0; strhdr.dwSuggestedBufferSize = bih.biSizeImage; strhdr.dwQuality = -1; strhdr.dwSampleSize = 0; strhdr.left = 0; strhdr.top = 0; strhdr.right = (short)bih.biWidth; strhdr.bottom = (short)bih.biHeight; AVIFileCreateStream(aviFile, out aviStream, ref strhdr); AVIStreamSetFormat(aviStream, 0, ref bih, bih.biSize); timer1.Start(); } private void btnStop_Click(object sender, EventArgs e) { timer1.Stop(); AVIStreamRelease(aviStream); AVIFileRelease(aviFile); AVIFileExit(); } private void timer1_Tick(object sender, EventArgs e) { IntPtr hdcSrc = GetWindowDC(GetDesktopWindow()); IntPtr hdcDest = bih.biHeight < 0 ? CreateCompatibleDC(hdcSrc) : CreateCompatibleDC(IntPtr.Zero); IntPtr hBitmap = CreateCompatibleBitmap(hdcSrc, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); IntPtr hOld = SelectObject(hdcDest, hBitmap); BitBlt(hdcDest, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, hdcSrc, 0, 0, 13369376); AVIStreamWrite(aviStream, timer1.Interval * timer1.TickCount, 1, hBitmap, bih.biSizeImage, 0, 0, 0); SelectObject(hdcDest, hOld); DeleteObject(hBitmap); DeleteDC(hdcDest); ReleaseDC(IntPtr.Zero, hdcSrc); } } } ``` 在上面的代码中,我们使用了Windows API函数来截取屏幕,然后使用AVIFile库将帧写入AVI文件。你可以修改代码来控制录制的区域、帧率和保存的文件名等参数。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值