| 1 |
import av |
| 2 |
|
| 3 |
av.logging.set_level(av.logging.VERBOSE) |
| 4 |
|
| 5 |
input_file = av.open("input.wav") |
| 6 |
output_file = av.open("output.wav", mode="w") |
| 7 |
|
| 8 |
input_stream = input_file.streams.audio[0] |
| 9 |
output_stream = output_file.add_stream("pcm_s16le", rate=input_stream.rate) |
| 10 |
|
| 11 |
graph = av.filter.Graph() |
| 12 |
graph.link_nodes( |
| 13 |
graph.add_abuffer(template=input_stream), |
| 14 |
graph.add("atempo", "2.0"), |
| 15 |
graph.add("abuffersink"), |
| 16 |
).configure() |
| 17 |
|
| 18 |
for frame in input_file.decode(input_stream): |
| 19 |
graph.push(frame) |
| 20 |
while True: |
| 21 |
try: |
| 22 |
for packet in output_stream.encode(graph.pull()): |
| 23 |
output_file.mux(packet) |
| 24 |
except (av.BlockingIOError, av.EOFError): |
| 25 |
break |
| 26 |
|
| 27 |
# Flush the stream |
| 28 |
for packet in output_stream.encode(None): |
| 29 |
output_file.mux(packet) |
| 30 |
|
| 31 |
input_file.close() |
| 32 |
output_file.close() |