2014-08-31 17 views
0

首先,我无法播放和录制高清视频(1920x1080),当我将相机分辨率更改为1920x1080节目并录制黑色背景时,如果相机分辨率为720x576, 。我确定问题在于我的解决方案,因为当我使用DesktopVideo(Blackmagic Decklink Studio 2附带的软件)时,它会显示来自相机的高清视频。 二,如何转换视频与AForge?像改变分辨率和帧速率,我可以改变编解码器和比特率,但是当我在“FileWriter.Open”命令中更改分辨率和帧率时,我会得到错误分辨率,并且FrameRate必须与我从相机捕获的位图相同。AForge转换和HD的问题

如果有人知道如何解决这些问题,请分享信息,谢谢!

下面是代码

using System; 

using System.Collections.Generic; 

using System.ComponentModel; 

using System.Data; 

using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using AForge.Video; 
using AForge.Video.DirectShow; 
using AForge.Video.FFMPEG; 
using AForge.Video.VFW; 

namespace WindowsFormsApplication12 
{ 
    public partial class Form1 : Form 
    { 
     private FilterInfoCollection VideoCaptureDevices; 

     private VideoCaptureDevice FinalVideo = null; 
     private VideoCaptureDeviceForm captureDevice; 
     private Bitmap video; 
     //private AVIWriter AVIwriter = new AVIWriter(); 
     private VideoFileWriter FileWriter = new VideoFileWriter(); 
     private SaveFileDialog saveAvi; 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 


      VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); 
      captureDevice = new VideoCaptureDeviceForm(); 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      /////capture device list 
      if (captureDevice.ShowDialog(this) == DialogResult.OK) 
      { 

       VideoCaptureDevice videoSource = captureDevice.VideoDevice; 
       FinalVideo = captureDevice.VideoDevice; 
       FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame); 
       FinalVideo.Start(); 
      } 
     } 
     void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs) 
     { 
      if (butStop.Text == "Stop Record") 
      { 
       video = (Bitmap)eventArgs.Frame.Clone(); 
       pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone(); 
       //AVIwriter.Quality = 0; 
       FileWriter.WriteVideoFrame(video); 
       //AVIwriter.AddFrame(video); 
      } 
      else 
      { 
       video = (Bitmap)eventArgs.Frame.Clone(); 
       pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone(); 
      } 
     } 

     private void button2_Click(object sender, EventArgs e) 
     { 
      ////record button 
      saveAvi = new SaveFileDialog(); 
      saveAvi.Filter = "Avi Files (*.avi)|*.avi"; 
      if (saveAvi.ShowDialog() == System.Windows.Forms.DialogResult.OK) 
      { 
       int h = captureDevice.VideoDevice.VideoResolution.FrameSize.Height; 
       int w = captureDevice.VideoDevice.VideoResolution.FrameSize.Width; 
       FileWriter.Open(saveAvi.FileName, w, h,25,VideoCodec.Default,5000000); 
       FileWriter.WriteVideoFrame(video); 

       //AVIwriter.Open(saveAvi.FileName, w, h); 
       butStop.Text = "Stop Record"; 
       //FinalVideo = captureDevice.VideoDevice; 
       //FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame); 
       //FinalVideo.Start(); 
      } 
     } 

     private void butStop_Click(object sender, EventArgs e) 
     { 
      if (butStop.Text == "Stop Record") 
      { 
       butStop.Text = "Stop"; 
       if (FinalVideo == null) 
       { return; } 
       if (FinalVideo.IsRunning) 
       { 
        //this.FinalVideo.Stop(); 
        FileWriter.Close(); 
        //this.AVIwriter.Close(); 
        pictureBox1.Image = null; 
       } 
      } 
      else 
      { 
       this.FinalVideo.Stop(); 
       FileWriter.Close(); 
       //this.AVIwriter.Close(); 
       pictureBox1.Image = null; 
      } 
     } 

     private void button3_Click(object sender, EventArgs e) 
     { 
      pictureBox1.Image.Save("IMG" + DateTime.Now.ToString("hhmmss") + ".jpg"); 
     } 

     private void button4_Click(object sender, EventArgs e) 
     { 
      this.Close(); 
     } 

     private void Form1_FormClosing(object sender, FormClosingEventArgs e) 
     { 
      if (FinalVideo == null) 
      { return; } 
      if (FinalVideo.IsRunning) 
      { 
       this.FinalVideo.Stop(); 
       FileWriter.Close(); 
       //this.AVIwriter.Close(); 
      } 
     } 


    } 
} 

回答

0

所提供的代码简单地捕捉和在选择用于捕获设备的格式当前活动的/保存。一般来说,分辨率变化是一种“昂贵”的操作,不能作为免费的操作。

您希望通过将捕捉设备切换为更合适的格式来更改捕捉设备的分辨率,然后捕捉该分辨率,并以正确的分辨率处理所有进一步的数据操作。可用的分辨率和选项可能是硬件特定的。

如果/当没有合适的捕获分辨率选项可用时,您通常会将视频重新采样为新的分辨率。尽管Windows API具有合适的功能,但在您的特定情况下,您有兴趣将其与AForge库集成,并且您需要检查其文档以确定它是否提供了各自的包装,以及它是否可以整合到捕获过程中(或,你需要自己编写这段代码来处理缩放)。

+0

我没有转换任何东西。当我将捕捉设备(相机)上的选项从高清更改为全高清时,它会显示黑屏,当它是高清时,它可以正常工作 – 2017-06-26 17:33:06

+0

如果配置与信号源和/或格式不匹配,Blackmagic设备会呈现黑色。您有责任正确设置源过滤器(正确解析度,以编程方式更正源或通过更改控制面板中此设备的相应默认值)。 Desktop Video正常工作并不能证明您可以使用过滤器捕获视频。 Desktop Video不使用您使用的过滤器,而是共享DeckLink SDK进行捕获,而Blackmagic已经废弃了您使用的DirectShow界面。 – 2017-06-26 17:48:21