2013-06-06 1 views
-1

나는 ffmpeg.exe를 사용하여 파일을 압축 한 다음 pipstream을 사용하여 각 40ms의 Form1 타이머에서 비트 맵을 가져 와서 pipestream에 씁니다.실시간으로 파일 크기를 가져 오거나 표시하려면 어떻게해야합니까?

응용 프로그램을 닫으면 하드 디스크에 새로운 avi 비디오 파일이 생성됩니다.

매번 40ms마다 또는 새 비트 맵이 도착할 때마다 파일이 하드 디스크에 아직 생성되지 않은 경우에도 파일을 실시간으로보고 싶습니다. 크기가됩니다. eample에 대한 :

40킬로바이트 다음은 40ms 120킬로바이트 후 후 후 40ms로 200킬로바이트 등등 ..

public void Start(string pathFileName, int BitmapRate) 
     { 
      string outPath = pathFileName; 
      p = new NamedPipeServerStream(pipename, PipeDirection.Out, 1, PipeTransmissionMode.Byte); 
      b = new byte[1920 * 1080 * 3]; // some buffer for the r g and b of pixels of an image of size 720p 

      ProcessStartInfo psi = new ProcessStartInfo(); 
      psi.WindowStyle = ProcessWindowStyle.Hidden; 
      psi.UseShellExecute = false; 
      psi.CreateNoWindow = false; 
      psi.FileName = ffmpegFileName; 
      psi.WorkingDirectory = workingDirectory; 
      psi.Arguments = @"-f rawvideo -pix_fmt bgr0 -video_size 1920x1080 -i \\.\pipe\mytestpipe -map 0 -c:v libx264 -r " + BitmapRate + " " + outPath; 
      process = Process.Start(psi); 
      process.EnableRaisingEvents = false; 
      p.WaitForConnection(); 
     } 

     public void PushFrame(Bitmap bmp) 
     { 

      int length; 
      // Lock the bitmap's bits. 
      //bmp = new Bitmap(1920, 1080); 
      Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); 
      //Rectangle rect = new Rectangle(0, 0, 1280, 720); 
      System.Drawing.Imaging.BitmapData bmpData = 
       bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, 
       bmp.PixelFormat); 

      int absStride = Math.Abs(bmpData.Stride); 
      // Get the address of the first line. 
      IntPtr ptr = bmpData.Scan0; 

      // Declare an array to hold the bytes of the bitmap. 
      //length = 3 * bmp.Width * bmp.Height; 
      length = absStride * bmpData.Height; 
      byte[] rgbValues = new byte[length]; 

      //Marshal.Copy(ptr, rgbValues, 0, length); 
      int j = bmp.Height - 1; 
      for (int i = 0; i < bmp.Height; i++) 
      { 
       IntPtr pointer = new IntPtr(bmpData.Scan0.ToInt32() + (bmpData.Stride * j)); 
       System.Runtime.InteropServices.Marshal.Copy(pointer, rgbValues, absStride * (bmp.Height - i - 1), absStride); 
       j--; 
      } 
      p.Write(rgbValues, 0, length); 
      bmp.UnlockBits(bmpData); 

내가 그것을 어떻게 할 수 있습니까?

답변

0

일단 ffmpeg를 파일이 아닌 stdout에 출력하게 만들 수 있습니다. 그런 다음 RedirectStandardOutput 속성을 설정하여 출력을 캡처 할 수 있습니다.

그러면 리디렉션 된 출력을 읽고 디스크에 직접 저장해야합니다. 물론 저장 한 데이터의 양을 정확히 알 수 있습니다.

관련 문제