如何从数码相机获取录制的视频?

发布于 2024-08-24 19:30:35 字数 55 浏览 6 评论 0原文

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

Can anyone provide C# code for getting recorded video from camera via Windows Media Encoder?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

潇烟暮雨 2024-08-31 19:30:35

您使用的是 Windows Media Encoder 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从相机中获取RAW文件,然后调用编码器API。

Are you using the Windows Media Encoder SDK ?

From the help file of the 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.
        }
    }
}

You could use WIA to get the raw files from the camera, and then call the encoder API.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文