gpt4 book ai didi

c# - 如何从数码相机中获取录制的视频?

转载 作者:行者123 更新时间:2023-11-30 18:44:41 26 4
gpt4 key购买 nike

谁能提供通过 Windows Media Encoder 从摄像头获取录制视频的 C# 代码?

最佳答案

您使用的是 Windows Media 编码器 SDK 吗?

来自SDK的帮助文件:

using System;
using WMEncoderLib;
class EncodeFile
{
static void Main()
{
try
{
// Create a WMEncoder object.
WMEncoder Encoder = new WMEncoder();

// Retrieve the source group collection.
IWMEncSourceGroupCollection SrcGrpColl = Encoder.SourceGroupCollection;

// Add a source group to the collection.
IWMEncSourceGroup SrcGrp = SrcGrpColl.Add("SG_1");

// Add a video and audio source to the source group.
IWMEncSource SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO);
SrcAud.SetInput("C:\\Inputfile.mpg", "", "");

IWMEncVideoSource2 SrcVid = (IWMEncVideoSource2)SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO);
SrcVid.SetInput("C:\\Inputfile.mpg", "", "");

// Crop 2 pixels from each edge of the video image.
SrcVid.CroppingBottomMargin = 2;
SrcVid.CroppingTopMargin = 2;
SrcVid.CroppingLeftMargin = 2;
SrcVid.CroppingRightMargin = 2;

// Specify a file object in which to save encoded content.
IWMEncFile File = Encoder.File;
File.LocalFileName = "C:\\OutputFile.wmv";

// Choose a profile from the collection.
IWMEncProfileCollection ProColl = Encoder.ProfileCollection;
IWMEncProfile Pro;
for (int i = 0; i < ProColl.Count; i++)
{
Pro = ProColl.Item(i);
if (Pro.Name == "Windows Media Video 8 for Local Area Network (384 Kbps)")
{
SrcGrp.set_Profile(Pro);
break;
}
}

// Fill in the description object members.
IWMEncDisplayInfo Descr = Encoder.DisplayInfo;
Descr.Author = "Author name";
Descr.Copyright = "Copyright information";
Descr.Description = "Text description of encoded content";
Descr.Rating = "Rating information";
Descr.Title = "Title of encoded content";

// Add an attribute to the collection.
IWMEncAttributes Attr = Encoder.Attributes;
Attr.Add ("URL", "IP address");

// Start the encoding process.
// Wait until the encoding process stops before exiting the application.
Encoder.PrepareToEncode(true);
Encoder.Start();
Console.WriteLine("Press Enter when the file has been encoded.");
Console.ReadLine(); // Press Enter after the file has been encoded.
}
catch (Exception e)
{
// TODO: Handle exceptions.
}
}
}

您可以使用 WIA 从相机获取原始文件,然后调用编码器 API。

关于c# - 如何从数码相机中获取录制的视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2409004/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com