简体   繁体   English

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

[英]How do I get recorded video from a digital camera?

任何人都可以提供C#代码,通过Windows Media Encoder从相机获取录制的视频吗?

Are you using the Windows Media Encoder SDK ? 您使用的是Windows Media Encoder SDK吗?

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

You could use WIA to get the raw files from the camera, and then call the encoder API. 您可以使用WIA从相机获取原始文件,然后调用编码器API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM