调用Windows Media Format 编辑asf文件问题!

lxxlily 2009-09-10 11:38:14
写了一个调用COM的WMVCore.dll的class,然后我在程序中要对一个asf流媒体文件进行编辑,加入marker.代码如下

using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WMFSDK;

namespace MediaMarkersTools
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)
{
string pwszFileName = "D:\\test.asf";

IWMMetadataEditor MetadataEditor;
IWMHeaderInfo3 HeaderInfo3;

WMFLibBase.WMCreateEditor(out MetadataEditor);

MetadataEditor.Open(pwszFileName);

HeaderInfo3 = (IWMHeaderInfo3)MetadataEditor;

ushort count = 0;
HeaderInfo3.GetMarkerCount(out count);
while(count>0)
{
HeaderInfo3.RemoveMarker(0);
count--;
}


//10000000为一秒
HeaderInfo3.AddMarker("Lixiaoxiang", 10000000);
HeaderInfo3.AddMarker("Lily", 20000000);
MetadataEditor.Flush();
MetadataEditor.Close();
}
}
}


...全文
208 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lxxlily 2009-09-10
  • 打赏
  • 举报
回复
为何运行后MetadataEditor.Open(pwszFileName);报错
异常来自 HRESULT:0xC00D07E2
未处理 System.Runtime.InteropServices.COMException
Message="异常来自 HRESULT:0xC00D07E2"
Source="WMFSDK"
ErrorCode=-1072887838
StackTrace:
在 WMFSDK.IWMMetadataEditor.Open(String pwszFilename)
在 MediaMarkersTools.Form1.button1_Click(Object sender, EventArgs e) 位置 D:\ProgramCode\MediaMarkersTools\MediaMarkersTools\Form1.cs:行号 30
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 MediaMarkersTools.Program.Main() 位置 D:\ProgramCode\MediaMarkersTools\MediaMarkersTools\Program.cs:行号 18
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:


其中WMFSDK class:

using System;
using System.Runtime.InteropServices;

namespace WMFSDK
{
public class WMFLibBase
{
[DllImport("WMVCore.dll", EntryPoint = "WMCreateEditor", SetLastError = true,
CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
public static extern uint WMCreateEditor(
[Out, MarshalAs(UnmanagedType.Interface)] out IWMMetadataEditor ppMetadataEditor);

public WMFLibBase()
{
//
// TODO: Add constructor logic here
//
}
}

[Guid("96406BD9-2B2B-11d3-B36B-00C04F6108FF"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IWMMetadataEditor
{
uint Open([In, MarshalAs(UnmanagedType.LPWStr)] string pwszFilename);
uint Close();
uint Flush();

}

[Guid("15CC68E3-27CC-4ecd-B222-3F5D02D80BD5"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IWMHeaderInfo3
{
uint GetAttributeCount(
[In] ushort wStreamNum,
[Out] out ushort pcAttributes);

uint GetAttributeByIndex(
[In] ushort wIndex,
[Out, In] ref ushort pwStreamNum,
[Out, MarshalAs(UnmanagedType.LPWStr)] string pwszName,
[Out, In] ref ushort pcchNameLen,
[Out] out WMT_ATTR_DATATYPE pType,
[Out, MarshalAs(UnmanagedType.LPArray)] byte[] pValue,
[Out, In] ref ushort pcbLength);

uint GetAttributeByName(
[Out, In] ref ushort pwStreamNum,
[Out, MarshalAs(UnmanagedType.LPWStr)] string pszName,
[Out] out WMT_ATTR_DATATYPE pType,
[Out, MarshalAs(UnmanagedType.LPArray)] byte[] pValue,
[Out, In] ref ushort pcbLength);

uint SetAttribute(
[In] ushort wStreamNum,
[In, MarshalAs(UnmanagedType.LPWStr)] string pszName,
[In] WMT_ATTR_DATATYPE Type,
[In, MarshalAs(UnmanagedType.LPArray)] byte[] pValue,
[In] ushort cbLength);

uint GetMarkerCount(
[Out] out ushort pcMarkers);

uint GetMarker(
[In] ushort wIndex,
[Out, MarshalAs(UnmanagedType.LPWStr)] string pwszMarkerName,
[Out, In] ref ushort pcchMarkerNameLen,
[Out] out ulong pcnsMarkerTime);

uint AddMarker(
[In, MarshalAs(UnmanagedType.LPWStr)] string pwszMarkerName,
[In] ulong cnsMarkerTime);

uint RemoveMarker(
[In] ushort wIndex);

uint GetScriptCount(
[Out] out ushort pcScripts);

uint GetScript(
[In] ushort wIndex,
[Out, MarshalAs(UnmanagedType.LPWStr)] string pwszType,
[Out, In] ref ushort pcchTypeLen,
[Out, MarshalAs(UnmanagedType.LPWStr)] string pwszCommand,
[Out, In] ref ushort pcchCommandLen,
[Out] out ulong pcnsScriptTime);

uint AddScript(
[In, MarshalAs(UnmanagedType.LPWStr)] string pwszType,
[In, MarshalAs(UnmanagedType.LPWStr)] string pwszCommand,
[In] ulong cnsScriptTime);

uint RemoveScript(
[In] ushort wIndex);

uint GetCodecInfoCount(
[Out] out uint pcCodecInfos);

uint GetCodecInfo(
[In] uint wIndex,
[Out, In] ref ushort pcchName,
[Out, MarshalAs(UnmanagedType.LPWStr)] string pwszName,
[Out, In] ref ushort pcchDescription,
[Out, MarshalAs(UnmanagedType.LPWStr)] string pwszDescription,
[Out] out WMT_CODEC_INFO_TYPE pCodecType,
[Out, In] ref ushort pcbCodecInfo,
[Out, MarshalAs(UnmanagedType.LPArray)] byte[] pbCodecInfo);

uint GetAttributeCountEx(
[In] ushort wStreamNum,
[Out] out ushort pcAttributes);

uint GetAttributeIndices(
[In] ushort wStreamNum,
[In, MarshalAs(UnmanagedType.LPWStr)] string pwszName,
[In] ref ushort pwLangIndex,
[Out, MarshalAs(UnmanagedType.LPArray)] ushort[] pwIndices,
[Out, In] ref ushort pwCount);

uint GetAttributeByIndexEx(
[In] ushort wStreamNum,
[In] ushort wIndex,
[Out, MarshalAs(UnmanagedType.LPWStr)] string pwszName,
[Out, In] ref ushort pwNameLen,
[Out] out WMT_ATTR_DATATYPE pType,
[Out] out ushort pwLangIndex,
[Out, MarshalAs(UnmanagedType.LPArray)] byte[] pValue,
[Out, In] ref uint pdwDataLength);

uint ModifyAttribute(
[In] ushort wStreamNum,
[In] ushort wIndex,
[In] WMT_ATTR_DATATYPE Type,
[In] ushort wLangIndex,
[In, MarshalAs(UnmanagedType.LPArray)] byte[] pValue,
[In] uint dwLength);

uint AddAttribute(
[In] ushort wStreamNum,
[In, MarshalAs(UnmanagedType.LPWStr)] string pszName,
[Out] out ushort pwIndex,
[In] WMT_ATTR_DATATYPE Type,
[In] ushort wLangIndex,
[In, MarshalAs(UnmanagedType.LPArray)] byte[] pValue,
[In] uint dwLength);

uint DeleteAttribute(
[In] ushort wStreamNum,
[In] ushort wIndex);

uint AddCodecInfo(
[In, MarshalAs(UnmanagedType.LPWStr)] string pszName,
[In, MarshalAs(UnmanagedType.LPWStr)] string pwszDescription,
[In] WMT_CODEC_INFO_TYPE codecType,
[In] ushort cbCodecInfo,
[In, MarshalAs(UnmanagedType.LPArray)] byte[] pbCodecInfo);
}

public enum WMT_ATTR_DATATYPE
{
WMT_TYPE_DWORD = 0,
WMT_TYPE_STRING = 1,
WMT_TYPE_BINARY = 2,
WMT_TYPE_BOOL = 3,
WMT_TYPE_QWORD = 4,
WMT_TYPE_WORD = 5,
WMT_TYPE_GUID = 6,
}

public enum WMT_CODEC_INFO_TYPE
{
WMT_CODECINFO_AUDIO = 0,
WMT_CODECINFO_VIDEO = 1,
WMT_CODECINFO_UNKNOWN = 0xffffff
}
}



应该不是文件路径的问题,求高人解决,分不够再给
mao924 2009-09-10
  • 打赏
  • 举报
回复
top
lxxlily 2009-09-10
  • 打赏
  • 举报
回复
top

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧