录制时音频/视频不同步

时间:2020-06-14 17:24:30

标签: ffmpeg

我正在使用gdigrab录制桌面,并使用dshow录制音频,但是它们不同步。

这是我尝试的第一件事,总是有大约相同的延迟(大约20-30帧):

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="menu">
<ul class="mega-menu">
    <li class="has-mega-menu"><a href=""><span class="material-icons icon">laptop</span>digital</a>
        <ul class="mega-submenu">
            <li><a href="">phone</a></li>
            <li><a href="">mobile accessory</a></li>
            <li><a href="">computer</a></li>
            <li><a href="">computer</a></li>
            <li><a href="">computer</a></li>
            <li><a href="">computer</a></li>
            <li><a href="">computer</a></li>
            <li><a href="">computer</a></li>
            <li><a href="">computer</a></li>
            <li><a href="">computer</a></li>
            <li><a href="">computer</a></li>
            <li><a href="">computer</a></li>
            <li><a href="">computer</a></li>
            <li><a href="">computer</a></li>
            <li><a href="">computer</a></li>
            <li><a href="">computer</a></li>
            <li><a href="">computer</a></li>
            <li><a href="">computer</a></li>
            <li><a href="">computer</a></li>
            <li><a href="">computer</a></li>
            <li><a href="">computer</a></li>
            <li><a href="">computer</a></li>
        </ul>
    </li>
    <li class="has-mega-menu"><a href=""><span class="material-icons icon">home</span>home requirement</a>
        <ul class="mega-submenu">
            <li><a href="">tv</a></li>
            <li><a href="">Furniture</a></li>
            <li><a href="">Refrigerator</a></li>
        </ul>
    </li>
    <li class="has-mega-menu"><a href=""><span class="material-icons icon">work</span>clothes</a>
        <ul class="mega-submenu">
            <li><a href="">Shirt</a></li>
            <li><a href="">T-shirt</a></li>
            <li><a href="">jacket</a></li>
        </ul>
    </li>
</ul>
</div>

我想尝试的第二件事解决了音频同步问题,但我可以说真的,因为它使录音变得很慢:

// Command
ffmpeg -f dshow -i audio="Microphone (NVIDIA RTX Voice)" -f gdigrab -framerate 60 -offset_x 0 -offset_y 0 -video_size 1920x1080 -i desktop -c:v h264 -preset ultrafast -qp 0 C:\Videos\test2.mp4

// Bottom of debug log
Input file #0 (audio=Microphone (NVIDIA RTX Voice)):
  Input stream #0:0 (audio): 15 packets read (1323000 bytes); 15 frames decoded (330750 samples);
  Total: 15 packets (1323000 bytes) demuxed
Input file #1 (desktop):
  Input stream #1:0 (video): 223 packets read (1849663242 bytes); 223 frames decoded;
  Total: 223 packets (1849663242 bytes) demuxed
Output file #0 (C:\Videos\test2.mp4):
  Output stream #0:0 (video): 243 frames encoded; 243 packets muxed (211227447 bytes);
  Output stream #0:1 (audio): 322 frames encoded (329728 samples); 323 packets muxed (120103 bytes);
  Total: 566 packets (211347550 bytes) muxed
238 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0000028163c9c040] Statistics: 2 seeks, 810 writeouts

如何同步音频和视频?

事实证明,只有麦克风才有延迟,我尝试使用// Command ffmpeg -f gdigrab -framerate 60 -offset_x 0 -offset_y 0 -video_size 1920x1080 -i desktop -f dshow -i audio="Microphone (NVIDIA RTX Voice)" -c:v h264 -preset ultrafast -qp 0 C:\Videos\test2.mp4 // Bottom of debug log Input file #0 (desktop): Input stream #0:0 (video): 112 packets read (928978848 bytes); 112 frames decoded; Total: 112 packets (928978848 bytes) demuxed Input file #1 (audio=Microphone (NVIDIA RTX Voice)): Input stream #1:0 (audio): 12 packets read (1058400 bytes); 12 frames decoded (264600 samples); Total: 12 packets (1058400 bytes) demuxed Output file #0 (C:\Videos\test2.mp4): Output stream #0:0 (video): 388 frames encoded; 388 packets muxed (109408287 bytes); Output stream #0:1 (audio): 258 frames encoded (264192 samples); 259 packets muxed (96404 bytes); Total: 647 packets (109504691 bytes) muxed 124 frames successfully decoded, 0 decoding errors [AVIOContext @ 0000019da713c040] Statistics: 2 seeks, 421 writeouts 设备并且音频已完美同步,但这只是桌面音频,而不是麦克风。

2 个答案:

答案 0 :(得分:0)

尝试将设备从RTX更改为实际设备。

答案 1 :(得分:0)

有两种可能的解决方案:

  1. 使用 dshow screen-capture-recorder 而不是 gdigrab

ffmpeg -f dshow -i video="screen-capture-recorder":audio="Your-Microphone" output.mkv

  1. 或者为视频或音频设置一个偏移值,这样会更快一些

将 -itoffset 00:00:0.6(例如 600ms)放在更快的后面