如何解决c#中的blackmagic SDK
| 我试图使用Windows7 64x上的最新SDK(2011年6月)和C#+ VS 2010 Express,从一张Blackmagic Intensity Pro卡中捕获720p。 我已经成功编译并运行了一个在YUV处捕获帧的程序,但是,捕获在56帧后停止(回调函数停止被调用)。我想知道我是否在这里缺少一些简单的东西?特别是考虑到我快到了-我得到的帧具有正确的内容,正确的大小等,但只是短暂的时间。 还有一些其他可能相关的信息: 如果我拔下相机,拍摄不会停止 我也曾在1080i和PAL上尝试过这种情况 即使VideoInputFrameArrived函数为空,也会发生同样的事情(即其中只有一个帧计数器) 这是代码:public partial class MainWindow : Window,IDeckLinkInputCallback
{
private IDeckLinkIterator _deckLinkIterator;
private List<IDeckLink> _deckLinkList = new List<IDeckLink>();
private IDeckLink _currentDevice=null;
private IDeckLinkInput _deckLinkInput = null;
private int _width=1280;
private int _height=720;
private WriteableBitmap _writeableBitmap =null;
IntPtr _tempRGBData;
byte[] _tempRGBDataBytes;
dispatcherTimer _timer = new dispatcherTimer();
public MainWindow()
{
InitializeComponent();
}
Random _random = new Random();
void _timer_Tick(object sender,EventArgs e)
{
_random.NextBytes(_tempRGBDataBytes);
_writeableBitmap.WritePixels(new Int32Rect(0,_width,_height),_tempRGBData,_height * _width * 3,_width * 3);
}
private void Window_Loaded(object sender,RoutedEventArgs e)
{
_writeableBitmap = new WriteableBitmap(_width,_height,72,27,PixelFormats.Bgr24,null);
_captureImage.source = _writeableBitmap;
_tempRGBData = Marshal.AllocHGlobal(3 * _width * _height * Marshal.SizeOf(typeof(byte)));
_tempRGBDataBytes = new byte[3 * _width * _height];
_deckLinkIterator = new CDeckLinkIterator();
IDeckLink dl=null;
while(true)
{
_deckLinkIterator.Next(out dl);
if(dl==null)
{
break;
}
else
{
_deckLinkList.Add(dl);
}
}
foreach (IDeckLink device in _deckLinkList)
{
String name;
device.GetModelName(out name);
Console.WriteLine(\"\" + name);
}
_currentDevice = _deckLinkList[1];
_deckLinkInput = (IDeckLinkInput)_currentDevice;
uint frameCount=0;
_deckLinkInput.GetAvailableVideoFrameCount(out frameCount);
Console.WriteLine(\"available frame count: \" + frameCount);
IDeckLinkdisplayModeIterator displayIterator=null;
_deckLinkInput.GetdisplayModeIterator(out displayIterator);
_BMDdisplayModeSupport displayModeSupport;
IDeckLinkdisplayMode displayMode=null;
_BMDdisplayMode setdisplayMode = _BMDdisplayMode.bmdModeHD720p50;
_BMDPixelFormat setPixelFormat = _BMDPixelFormat.bmdFormat8BitYUV;
_BMDVideoInputFlags setInputFlag = _BMDVideoInputFlags.bmdVideoInputFlagDefault;
_deckLinkInput.DoesSupportVideoMode(setdisplayMode,setPixelFormat,setInputFlag,out displayModeSupport,out displayMode);
try
{
//_deckLinkInput.disableAudioinput();
_deckLinkInput.EnableVideoInput(setdisplayMode,setInputFlag);
}
catch (Exception em)
{
Console.WriteLine(\"deck link init Failed: \" + em.Message);
}
_deckLinkInput.SetCallback(this);
Console.WriteLine(\"done!\");
_timer.Interval = TimeSpan.FromSeconds(1f / 30f);
_timer.Tick += new EventHandler(_timer_Tick);
_timer.Start();
}
int frameCount = 0;
public void VideoInputFrameArrived(IDeckLinkVideoInputFrame video,IDeckLinkAudioInputPacket audio)
{
//get image data
IntPtr pData;
video.GetBytes(out pData);
//keeping it simple so just counting frames - this gets called 56 times then stops
Console.WriteLine(\"video frame arrived!! \" + frameCount);
frameCount++;
}
public void VideoInputFormatChanged(_BMDVideoInputFormatChangedEvents events,IDeckLinkdisplayMode displayMode,_BMDDetectedVideoInputFormatFlags flags)
{
Console.WriteLine(\"video format changed!!\");
}
//start stream
private void button1_Click(object sender,RoutedEventArgs e)
{
_deckLinkInput.StartStreams();
}
//stop stream
private void button2_Click(object sender,RoutedEventArgs e)
{
_deckLinkInput.StopStreams();
}
private void button4_Click(object sender,RoutedEventArgs e)
{
_deckLinkInput.PauseStreams();
}
private void button3_Click(object sender,RoutedEventArgs e)
{
_deckLinkInput.FlushStreams();
}
}
解决方法
我已经在blackmagic技术支持的帮助下解决了这个问题
解决方案是在回调函数的末尾插入以下行:
System.Runtime.InteropServices.Marshal.ReleaseComObject(video);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。