You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.3 KiB
46 lines
1.3 KiB
import av
|
|
from av.filter import Graph
|
|
|
|
|
|
def main():
|
|
input_container = av.open('supernatural.webm', mode='r')
|
|
input_container2 = av.open('yiv3.webm', mode='r')
|
|
input_video_stream = input_container.streams.video[0]
|
|
|
|
output_container = av.open("out.mp4", "w")
|
|
output_audio_stream = output_container.add_stream('aac', rate=input_container2.streams.audio[0].base_rate)
|
|
|
|
graph = Graph()
|
|
|
|
in_src = graph.add_abuffer(template=input_container.streams.audio[0])
|
|
in_src2 = graph.add_abuffer(template=input_container2.streams.audio[0])
|
|
pad = graph.add("amix", "inputs=2:duration=longest")
|
|
print(dir(pad))
|
|
in_src.link_to(pad, 0, 0)
|
|
in_src2.link_to(pad, 0, 1)
|
|
sink = graph.add('abuffersink')
|
|
pad.link_to(sink)
|
|
graph.configure()
|
|
|
|
for frame in input_container.decode(audio=0):
|
|
in_src.push(frame)
|
|
|
|
for frame in input_container2.decode(audio=0):
|
|
in_src2.push(frame)
|
|
while True:
|
|
try:
|
|
filtered_frame = pad.pull()
|
|
output_container.mux(output_audio_stream.encode(filtered_frame))
|
|
except:
|
|
break
|
|
|
|
for packet in output_audio_stream.encode():
|
|
output_container.mux(packet)
|
|
|
|
input_container.close()
|
|
input_container2.close()
|
|
output_container.close()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|
|
|