VB.NET - 帧捕获问题以及使用ffmpeg问题将音频与视频同步

时间:2013-12-01 07:38:35

标签: vb.net ffmpeg

我在VB.NET中有一个代码,可以定期捕获桌面的全屏图像(代码在20ms的计时器刻度事件中运行)在同一个自动收报机事件中,我甚至捕获了音频。 用于捕获屏幕截图的代码

    Filenum.Text = Filenum.Text + 1
    Dim screensize As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
    Dim BMP As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
    Dim ga As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(BMP)
    ga.CopyFromScreen(New Point(0, 0), New Point(0, 0), screensize)
    Cursor.Draw(ga, New Rectangle(Cursor.Position, Cursor.Size))
    Dim fileDiro As String = My.Computer.FileSystem.CurrentDirectory + "\Recorder\VidShots-" + DT + "\img"

    Dim frame As String = Filenum.Text
    BMP.Save(fileDiro + frame + ".png")

我注意到上面的代码在正常录制桌面时运行正常(不是太多预期)但是在录制视频或快速动作捕捉时,它无法生成足够的帧来创建合适的剪辑。

'''' Code exclusively for Audio recording - Start audio recording - added 22/09/2013

 mciSendString("open new Type waveaudio Alias recsound", "", 0, 0)
    mciSendString("record recsound", "", 0, 0)

 '''' Code exclusively for Audio recording - Stop audio recording - added 22/09/2013
    Using w As New IO.FileStream( _
                    My.Computer.FileSystem.CurrentDirectory + "\Recorder\sound.mp3", _
                    IO.FileMode.Create _
                )
        w.SetLength(64000)
    End Using

    Dim fP As String
    fP = My.Computer.FileSystem.CurrentDirectory & "\Recorder\sound.mp3"
    mciSendString("save recsound " & Chr(34) & fP & Chr(34), "", 0, 0)
    mciSendString("close recsound", "", 0, 0)
    My.Computer.Audio.Stop()

问题是当我尝试使用ffmpeg.exe将音频和视频多路复用时,音频与生成的视频不同步。下面是执行的两个ffmpeg语句的示例。

 Dim startInfo As New ProcessStartInfo(My.Computer.FileSystem.CurrentDirectory & "\ffmpeg.exe")
       startInfo.Arguments = "-r " + max.ReadLine + " -analyzeduration 2147483647 -probesize 2147483647 -i Recorder/" + x + "/img%d.png -r 12 -b:v 900K Recorder/" + x + "/video.avi"
        Debug.Print(startInfo.Arguments.ToString)

        p = Process.Start(startInfo)
        p.WaitForExit()
        'Process.Start(My.Computer.FileSystem.CurrentDirectory & "\ffmpeg.exe", "-r 10 -analyzeduration 2147483647 -probesize 2147483647 -i Recorder/" + x + "/img%d.png -r 50 Recorder/" + x + "/video.avi"))
        Process.Start(My.Computer.FileSystem.CurrentDirectory & "\ffmpeg.exe", "-i Recorder/" + x + "/video.avi -i Recorder/sound.mp3 -map 0 -map 1 -codec copy -shortest Recorder/" + x + "/video1.avi")
        Debug.Print("-i Recorder/" + x + "/video.avi -i Recorder/sound.mp3 -map 0 -map 1 -codec copy -shortest Recorder/" + x + "/video1.avi")

有人可以帮助让音频和视频同步吗?

0 个答案:

没有答案