задача – как исправить скорость воспроизведения записи, выходной файл воспроизводится почти в 2 раза быстрее.
Form1
- Код: Выделить всё
Imports System.IO
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)>
Private Shared Function GetAsyncKeyState(ByVal vkey As Integer) As Short
End Function
Private fcounter As Integer = 0
Private recording As Boolean
Private proc As New Process
Private writer As BinaryWriter
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
recording = False
Try
writer.Close()
Catch ex As Exception
End Try
If bmp IsNot Nothing Then
bmp.Dispose()
bmp = Nothing
End If
End Sub
Private Sub Record_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Record.Click
' mini me on record!
'Me.WindowState = FormWindowState.Minimized
If bmp IsNot Nothing Then
bmp.Dispose()
bmp = Nothing
End If
bmp = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height) ', System.Drawing.Imaging.PixelFormat.Format24bppRgb)
Label7.Text = "Recording"
Application.DoEvents()
Try
proc.StartInfo.FileName = Application.StartupPath & "\ffmpeg.exe"
' note: ' -an = no audio
proc.StartInfo.Arguments = "-f image2pipe -i pipe:.bmp -pix_fmt yuv420p -c:v libx264 -acodec flac -bufsize 60000k -b:v 1800k -y " & Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\test.mp4"
proc.StartInfo.UseShellExecute = False
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
proc.StartInfo.RedirectStandardInput = True
proc.StartInfo.RedirectStandardOutput = True
proc.StartInfo.CreateNoWindow = True
proc.Start()
' start capture using BGW
recording = True
BackgroundWorker1.RunWorkerAsync()
Catch ex As Exception
recording = False
Label7.Text = "ERROR"
MessageBox.Show(ex.Message)
Try
writer.Close()
Catch
End Try
End Try
End Sub
Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
writer = New BinaryWriter(proc.StandardInput.BaseStream)
Do
If GetAsyncKeyState(Keys.LButton) >= 0 Then ' mousedown = False
bmp = ScreenCap(True, False)
ElseIf GetAsyncKeyState(Keys.LButton) < 0 Then ' mousedown = True
bmp = ScreenCap(True, True)
End If
' save capture
bmp.Save(writer.BaseStream, System.Drawing.Imaging.ImageFormat.Bmp)
fcounter = fcounter + 1
' if ESC key pressed exit
If GetAsyncKeyState(Keys.Escape) < 0 Then
recording = False
Exit Do
End If
Loop While recording
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
' recording stopped
writer.Close()
LblFrames.Text = fcounter.ToString("000000")
Label7.Text = "STOPPED"
Application.DoEvents()
If bmp IsNot Nothing Then
bmp.Dispose()
bmp = Nothing
End If
Application.DoEvents()
Me.WindowState = FormWindowState.Normal
End Sub
Private Sub StopREC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopREC.Click
recording = False 'stop!
Label7.Text = "STOPPED"
End Sub
End Class]
ScreenCapture
- Код: Выделить всё
Imports System.Runtime.InteropServices
Module ScreenCapture
Public bmp As Bitmap
<StructLayout(LayoutKind.Sequential)> _
Private Structure POINTAPI
Public x As Int32
Public y As Int32
End Structure
<StructLayout(LayoutKind.Sequential)> _
Private Structure CURSORINFO
Public cbSize As Int32
Public flags As Int32
Public hCursor As IntPtr
Public ptScreenPos As POINTAPI
End Structure
<StructLayout(LayoutKind.Sequential)> _
Private Structure ICONINFO
Public fIcon As Boolean
Public xHotspot As Int32
Public yHotspot As Int32
Public hbmMask As IntPtr
Public hbmColor As IntPtr
End Structure
<DllImport("user32.dll", EntryPoint:="GetCursorInfo")> _
Private Function GetCursorInfo(ByRef pci As CURSORINFO) As Boolean
End Function
<DllImport("user32.dll")> _
Private Function DrawIcon(hDC As IntPtr, X As Int32, Y As Int32, hIcon As IntPtr) As Boolean
End Function
<DllImport("user32.dll", EntryPoint:="GetIconInfo")> _
Private Function GetIconInfo(hIcon As IntPtr, ByRef piconinfo As ICONINFO) As Boolean
End Function
Private Const vbSRCCOPY As Int32 = &HCC0020
Private Const CAPTUREBLT As Int32 = &H40000000 ' capture layered windows
<DllImport("gdi32.dll")> _
Private Function BitBlt(ByVal hdc As IntPtr, ByVal nXDest As Int32, ByVal nYDest As Int32, ByVal nWidth As Int32, ByVal nHeight As Int32, ByVal hdcSrc As IntPtr, ByVal nXSrc As Int32, ByVal nYSrc As Int32, ByVal dwRop As Int32) As Boolean
End Function
<DllImport("gdi32.dll")> _
Private Function DeleteObject(hObject As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
Public Function ScreenCap(IncludeMouse As Boolean, Optional DrawEllipse As Boolean = False) As Bitmap
'*** NOTE: "bmp" is already declared as Public for screen capture app, so ignore next line! ***
'Dim bmp As New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)', System.Drawing.Imaging.PixelFormat.Format24bppRgb)
Using gdest As Graphics = Graphics.FromImage(bmp)
Dim hDestDC As IntPtr = gdest.GetHdc()
Using gsrc As Graphics = Graphics.FromHwnd(IntPtr.Zero)
Dim hSrcDC As IntPtr = gsrc.GetHdc()
BitBlt(hDestDC, 0, 0, bmp.Width, bmp.Height, hSrcDC, 0, 0, vbSRCCOPY Or CAPTUREBLT)
If IncludeMouse Then
Dim pcin As New CURSORINFO()
pcin.cbSize = Marshal.SizeOf(pcin)
If GetCursorInfo(pcin) Then
Dim piinfo As ICONINFO
If GetIconInfo(pcin.hCursor, piinfo) Then
' updated for screen capture app >
If DrawEllipse Then ' mouse was left clicked
' Create new graphics object using handle of device context.
Using newGraphics As Graphics = Graphics.FromHdc(hDestDC)
'draw red circle around center of mouse pointer
newGraphics.DrawEllipse(New Pen(Color.Red, 2), pcin.ptScreenPos.x - 14, pcin.ptScreenPos.y - 14, 28, 28)
End Using ' Release handle to device context.
End If
' draw mouse pointer
DrawIcon(hDestDC, pcin.ptScreenPos.x - piinfo.xHotspot, pcin.ptScreenPos.y - piinfo.yHotspot, pcin.hCursor)
' clean up
If Not piinfo.hbmMask.Equals(IntPtr.Zero) Then DeleteObject(piinfo.hbmMask)
If Not piinfo.hbmColor.Equals(IntPtr.Zero) Then DeleteObject(piinfo.hbmColor)
End If
End If
End If
gsrc.ReleaseHdc()
End Using 'gsrc.Dispose()
gdest.ReleaseHdc()
End Using 'gdest.Dispose()
Return bmp
End Function
End Module
пользуясь русскоязычной справкой http://help.ubuntu.ru/wiki/ffmpeg пробовал подставлять разные значения командной строки FFmpag, не выходит