0

我需要在我的电脑上下载我刚刚录制的视频。我设法用图片做到了,但对于视频,我只得到一个空文件。

我已经注册了对象事件处理程序

 err = EDSDK.EdsSetObjectEventHandler(cameraDev, EDSDK.ObjectEvent_All, objectEventHandler, new IntPtr(0));

然后,我开始录制:

public void StartRecording(int sec)
{
    // set the timer, surement à mettre dans les config, plutot
    System.Timers.Timer aTimer = new System.Timers.Timer(sec * 1000);
    aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
    GC.KeepAlive(aTimer);            

    err = EDSDK.EdsSetPropertyData(cameraDev, EDSDK.PropID_Record, 0, 4, 4);
    aTimer.Start();
}

private void OnTimedEvent(object source, ElapsedEventArgs e)
{
   StopRecording();
}


public void StopRecording()
{           
    err = EDSDK.EdsSetPropertyData(cameraDev, EDSDK.PropID_Record, 0, 4, 0);
}

对象事件处理程序:

public uint objectEventHandler(uint inEvent, IntPtr inRef, IntPtr inContext)
{
    switch (inEvent)
    {
        case EDSDK.ObjectEvent_DirItemCreated:
                DownloadImage(inRef, inContext);
            break;                
    }
    return 0;
}

最后,downolad

void DownloadImage(IntPtr DirectoryRef, IntPtr inContext)
{            
    IntPtr stream = IntPtr.Zero;
    IntPtr data = IntPtr.Zero;

    EDSDK.EdsDirectoryItemInfo dirItemInfo;
    uint err;

    try
    {
        err = EDSDK.EdsGetDirectoryItemInfo(DirectoryRef, out dirItemInfo);
        err = EDSDK.EdsCreateFileStream(dirItemInfo.szFileName,
            EDSDK.EdsFileCreateDisposition.CreateAlways, EDSDK.EdsAccess.ReadWrite, out stream);

        // does not work
        err = EDSDK.EdsSetProgressCallback(stream, progressFunc, EDSDK.EdsProgressOption.Periodically, inContext);

        // Fill the stream with the resulting image
        err = EDSDK.EdsDownload(DirectoryRef, dirItemInfo.Size, stream);

        if (err == EDSDK.EDS_ERR_OK)
        {
            err = EDSDK.EdsDownloadComplete(DirectoryRef);
        }
        else
        {
            err = EDSDK.EdsDownloadCancel(DirectoryRef);
        }
        if ((stream == null) == false)
        {
            err = EDSDK.EdsRelease(stream);
            stream = IntPtr.Zero;
        }                 
    }
    catch (Exception ex)
    {
        throw new Exception(String.Format("EDSDK Error : {0}", ex.Message));
    }
    EDSDK.EdsRelease(stream);
}

在调试模式下,方法 EDSDK.EdsDownload 永远不会结束,但是没有异常,或者返回码...

请帮忙 !

4

1 回答 1

1

您是否确保将 kEdsPropID_SaveTo 设置为 1(“保存在远程相机的存储卡上”),因为您无法像使用图像一样将其直接保存到 PC。

于 2013-10-07T07:51:23.103 回答