Blackmagic的SDK在C# [英] blackmagic SDK in c#
问题描述
我试图对windows7的64倍,并用C#+ VS 2010速成从一个拍摄720p利用最新SDK(2011年6月)一Blackmagic的强度亲卡。
我已经成功地编译和运行,在YUV帧捕获然而,在拍摄后56帧(回调函数停止调用)停止的程序。我想知道如果我在这里缺少简单的东西?特别是考虑到我几乎没有 - 我得到在正确的大小等,但只有很短的时间正确的内容框架
也可能是有关其他的一些信息
- 如果我拔掉摄像头采集不会停止
- 我也曾在1080i的尝试这样做与PAL和同样的情况
- 同样的事情发生,即使VideoInputFrameArrived功能是空的(即只有在这帧计数器)
这里是代码:
公共部分类主窗口:窗口,IDeckLinkInputCallback
{
私人IDeckLinkIterator _deckLinkIterator;
私有列表< IDeckLink> _deckLinkList =新的List< IDeckLink>();
私人IDeckLink _currentDevice = NULL;
私人IDeckLinkInput _deckLinkInput = NULL;
私人INT _width = 1280;
私人INT _height = 720;
私人WriteableBitmap的_writeableBitmap = NULL;
IntPtr的_tempRGBData;
字节[] _tempRGBDataBytes;
DispatcherTimer _timer =新DispatcherTimer();
公共主窗口()
{
的InitializeComponent();
}
随机_random =新的随机();
无效_timer_Tick(对象发件人,EventArgs五)
{
_random.NextBytes(_tempRGBDataBytes);
_writeableBitmap.WritePixels(新Int32Rect(0,0,_width,_height),_ tempRGBData,_height * _width * 3,_width * 3);
}
私人无效Window_Loaded(对象发件人,RoutedEventArgs E)
{
_writeableBitmap =新的WriteableBitmap的(_width,_height,72,27,的PixelFormats .Bgr24,NULL);
_captureImage.Source = _writeableBitmap;
_tempRGBData = Marshal.AllocHGlobal(3 * _width * _height * Marshal.SizeOf(typeof运算(字节)));
_tempRGBDataBytes =新的字节[* 3 * _width _height]。
_deckLinkIterator =新CDeckLinkIterator();
IDeckLink DL = NULL;
,而(真)
{
_deckLinkIterator.Next(出DL);
如果(DL == NULL)
{
中断;
}
,否则
{
_deckLinkList.Add(DL);
}
}
的foreach(在_deckLinkList IDeckLink设备)
{
字符串名称;
device.GetModelName(满分名);
Console.WriteLine(+姓名);
}
_currentDevice = _deckLinkList [1];
_deckLinkInput =(IDeckLinkInput)_currentDevice;
UINT frameCount = 0;
_deckLinkInput.GetAvailableVideoFrameCount(出frameCount);
Console.WriteLine(可用的帧数:+ frameCount);
IDeckLinkDisplayModeIterator displayIterator = NULL;
_deckLinkInput.GetDisplayModeIterator(出displayIterator);
_BMDDisplayModeSupport displayModeSupport;
IDeckLinkDisplayMode DISPLAYMODE = NULL;
_BMDDisplayMode setDisplayMode = _BMDDisplayMode.bmdModeHD720p50;
_BMDPixelFormat setPixelFormat = _BMDPixelFormat.bmdFormat8BitYUV;
_BMDVideoInputFlags setInputFlag = _BMDVideoInputFlags.bmdVideoInputFlagDefault;
_deckLinkInput.DoesSupportVideoMode(setDisplayMode,setPixelFormat,setInputFlag,出displayModeSupport,出DISPLAYMODE);
试
{
// _ deckLinkInput.DisableAudioInput();
_deckLinkInput.EnableVideoInput(setDisplayMode,setPixelFormat,setInputFlag);
}
赶上(例外EM)
{
Console.WriteLine(甲板链接初始化失败:+ em.Message);
}
_deckLinkInput.SetCallback(本);
Console.WriteLine(完成!);
_timer.Interval = TimeSpan.FromSeconds(1F / 30F);
_timer.Tick + =新的EventHandler(_timer_Tick);
_timer.Start();
}
INT frameCount = 0;
公共无效VideoInputFrameArrived(IDeckLinkVideoInputFrame视频,音频IDeckLinkAudioInputPacket)
{
//获取图像数据
的IntPtr pData所;
video.GetBytes(出的pData);
//保持它的简单,所以只是计算框架 - 这个被调用56次,然后停止
Console.WriteLine(视频帧到达!!+ frameCount );
frameCount ++;
}
公共无效VideoInputFormatChanged(_BMDVideoInputFormatChangedEvents事件,IDeckLinkDisplayMode DISPLAYMODE,_BMDDetectedVideoInputFormatFlags标志)
{
Console.WriteLine(视频格式改变! );
}
//启动流
私人无效的button1_Click(对象发件人,RoutedEventArgs E)
{
_deckLinkInput.StartStreams();
}
//停止流
私人无效button2_Click(对象发件人,RoutedEventArgs E)
{
_deckLinkInput.StopStreams();
}
私人无效button4_Click(对象发件人,RoutedEventArgs E)
{
_deckLinkInput.PauseStreams();
}
私人无效button3_Click(对象发件人,RoutedEventArgs E)
{
_deckLinkInput.FlushStreams();
}
}
我'已经成功地解决了这个问题与Blackmagic的技术支持帮助
解决的办法是在回调函数的末尾插入该行:
System.Runtime.InteropServices.Marshal.ReleaseComObject(视频)
i am attempting to capture 720p from one a blackmagic intensity pro cards using the newest SDK (june 2011) on windows7 64x and with C# + VS 2010 express.
i have successfully compiled and run a program that captures frames at YUV however, capture stops after 56 frames (the callback function stops being called). i am wondering if i am missing something simple here? especially given that i am almost there - i get frames with the correct content at the correct size etc but only for a brief time.
also some other information that may be relevant:
- if i unplug the camera capture does not stop
- i have also tried this at 1080i and PAL and the same happens
- same thing happens even if the VideoInputFrameArrived function is empty (i.e. with just a frame counter in it)
here is the code:
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, 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, setPixelFormat, 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();
}
}
i've managed to solved this problem with the help of blackmagic tech support
the solution is to insert this line at the end of the callback function:
System.Runtime.InteropServices.Marshal.ReleaseComObject(video);
这篇关于Blackmagic的SDK在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!