vs中怎么改变原有视频的尺寸播放
时间: 2023-05-26 19:07:52 浏览: 103
1.打开Visual Studio,创建一个新的项目。
2. 在方案资源管理器中右键单击"资源"文件夹,然后选择"添加现有项"。
3. 选择要更改大小的视频文件,将其添加到项目中。
4. 在资源文件上单击右键,然后选择"属性"。
5. 在属性窗口中,将"生成操作"属性更改为"嵌入的资源"。
6. 点击"应用"并关闭属性窗口。
7. 在代码编辑器中,编写代码来更改视频大小。以下是一个例子:
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace VideoPlayer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Stream stream = this.GetType().Assembly.GetManifestResourceStream("VideoPlayer.Resources.video.mp4");
this.axWindowsMediaPlayer1.URL = stream.ToString();
this.axWindowsMediaPlayer1.settings.autostart = false;
this.axWindowsMediaPlayer1.settings.volume = 50;
ResizeVideo(640, 480);
}
private void ResizeVideo(int width, int height)
{
string path = Path.Combine(Path.GetTempPath(), "video.mp4");
Stream stream = this.GetType().Assembly.GetManifestResourceStream("VideoPlayer.Resources.video.mp4");
using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write))
{
stream.CopyTo(fs);
}
var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
ffMpeg.ConvertMedia(path, null, path, NReco.VideoConverter.Format.mp4, new NReco.VideoConverter.ConvertSettings
{
VideoFrameSize = string.Format("{0}x{1}", width, height),
VideoCodec = "libx264",
AudioCodec = "libmp3lame",
AudioSampleRate = 44100
});
stream = new FileStream(path, FileMode.Open, FileAccess.Read);
this.axWindowsMediaPlayer1.URL = stream.ToString();
File.Delete(path);
}
}
}
8. 运行应用程序,视频将以指定尺寸播放。