python视频延迟严重_Python音视频合并中的延迟问题

通过一个附带有音频和视频的python-rasypm音频捕捉设备和picaerm录制的音频和视频。在

通过ffmpeg合并两个文件,直到30秒音频/视频都很好地同步,但是30秒之后,我开始体验延迟问题。在

你能指导我解决这个问题吗?在import picamera, subprocess, os

import pyaudio,wave,sys

CHUNK = 8192

FORMAT = pyaudio.paInt16

CHANNELS = 1

RATE = 44100

RECORD_SECONDS = 60 #"Recording Duration"

WAVE_OUTPUT_FILENAME = 'Audio.wav'

H264_OUTPUT_FILENAME = 'Video.h264'

frames = []

with picamera.PiCamera() as camera:

camera.resolution= (640,480)

p = pyaudio.PyAudio()

stream = p.open(format=FORMAT,

channels = CHANNELS,

rate = RATE,

input = True,

input_device_index = 0,

frames_per_buffer = CHUNK)

camera.start_preview(fullscreen=False, window=(930, 0, 425, 295))# "Start Video Preview"

camera.start_recording(H264_OUTPUT_FILENAME, quality = 30) # "Start Video Recording"

# "Start Audio Dubbing"

for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):

data = stream.read(CHUNK)

frames.append(data)

stream.stop_stream() # "Pause the Stream"

stream.close() # "Stream Stop"

p.terminate() # "Stream Cloase"

camera.stop_recording() # "Pause" the recording

camera.stop_preview() # "Stop Preview"

camera.close() # "Camera Close"

# Creation of MIC WAVE FILE

wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')

wf.setnchannels(CHANNELS)

wf.setsampwidth(p.get_sample_size(FORMAT))

wf.setframerate(RATE)

wf.writeframes(b''.join(frames))

wf.close()

# Combining/Merging of Audio/Video File into mkv

cmd = 'ffmpeg -y -i Audio.wav -r 30 -i Video.h264 -filter:a aresample=async=1 -c:a flac -c:v copy av.mkv'

subprocess.call(cmd, shell=True) # "Muxing Done

print('Muxing Done')

你可能感兴趣的:(python视频延迟严重)