2014-08-31 13 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