Comments (1)
For filters like atempo, you need to push multiple frames before the filter starts making output frames. See my example for how you would do that in code:
import av
from av.filter.context import FilterContext
import os
import time
import tempfile
def link_nodes(*nodes: FilterContext) -> None:
for c, n in zip(nodes, nodes[1:]):
c.link_to(n)
def main() -> None:
stretched_aud_path = "out.mp3"
audio_in_container = av.open("test.wav", mode="r", format="wav")
audio_in_stream = audio_in_container.streams.audio[0]
if os.path.exists(stretched_aud_path):
os.remove(stretched_aud_path)
audio_out_container = av.open(stretched_aud_path, mode="w", format="wav")
output_stream = audio_out_container.add_stream(codec_name="mp3", rate=48000)
# Setup filter graph
filter_graph = av.filter.Graph()
link_nodes(
filter_graph.add_abuffer(template=audio_in_stream),
filter_graph.add("atempo", "2.0"),
filter_graph.add("abuffersink"),
)
filter_graph.configure()
# Render audio
for frame in audio_in_container.decode(audio=0):
filter_graph.push(frame)
while True:
try:
output_frame = filter_graph.pull()
for packet in output_stream.encode(output_frame):
audio_out_container.mux(packet)
except av.BlockingIOError:
break
# After pushing all frames, flush the filter graph
for packet in output_stream.encode(None):
audio_out_container.mux(packet)
audio_out_container.close()
audio_in_container.close()
if __name__ == "__main__":
main()
from pyav.
Related Issues (20)
- Functional Difference In Data Stream between AV 11.0.0 and AV 12.0.0 HOT 1
- AV 12.0.0 decoded frames do not match source as in AV 11.0.0 (potential colorspace issue) HOT 3
- Missing shared object file after upgrading to Python 3.12 HOT 1
- frame.index is deprecated HOT 1
- Provide Apple M1 binaries for pypy HOT 2
- Compatibility with NumPy 2.0? HOT 9
- to_bytes does not exist on Packet. HOT 2
- Generating a video with numpy and writing it with pyav does not preserve color HOT 1
- Unable to set frame rate HOT 3
- `argument 2 of βav_bsf_list_parse_strβ from incompatible pointer type` in `bitstream.c` HOT 8
- Expose `av_frame_make_writable` HOT 2
- Support for v360 video filter HOT 1
- How do I set the value of slices?
- Allow using the ffmpeg cli API HOT 2
- Help in remuxing without decoding HOT 1
- av/frame.pxd:1:8: 'libav.pxd' not found HOT 1
- `Resampler` object still occupies memory after deletion HOT 6
- Decoding full-range yuv444p to RGB differs from ffmpeg HOT 1
- Decoding full-range yuv444p to RGB differs from ffmpeg HOT 2
- `AudioLayout` constructor with an `AudioLayout` instance is broken
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyav.