最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Audio delay after resuming FFmpeg on Windows - Stack Overflow

programmeradmin3浏览0评论

I'm building a screen recording software for Windows using Python. I use FFmpeg for recording and psutil to pause and resume the process.

Here is a sample of my code:

import psutil
import subprocess

process = subprocess.Popen([
        'ffmpeg', '-y',
        '-rtbufsize', '100M',
        '-f', 'gdigrab',
        '-thread_queue_size', '1024',
        '-probesize', '50M',
        '-r', '24',
        '-draw_mouse', '1',
        '-video_size', '1920x1080',
        '-i', 'desktop', 
        '-f', 'dshow',
        '-channel_layout', 'stereo',
        '-thread_queue_size', '1024',
        '-i', 'audio=Microphone (2- High Definition Audio Device)', # my audio device
        '-c:v', 'h264_nvenc', # encoding via Nvidia
        '-r', '24',
        '-preset', 'p1',
        '-pix_fmt', 'yuv444p',
        '-fps_mode', 'cfr',
        '-c:a', 'aac', 
        '-ac', '2',
        '-b:a', '128k',
        'output.mp4'])

ffmpeg_proc = psutil.Process(process.pid)

# pause
ffmpeg_proc.suspend()

# resume
ffmpeg_proc.resume() 

The issue is that after resuming, the audio becomes choppy and delayed, while the video continues smoothly.

I have tried using following flags, but they didn't solve the issue:

-analyzeduration
-fflags +genpts
-async
-use_wallclock_as_timestamps
-af aresample=async=1

How can I properly pause and resume FFmpeg without causing audio delay? Is there any other method to handle this properly?

Thanks for any suggestions.

发布评论

评论列表(0)

  1. 暂无评论