Repository navigation
Replies: 1 comment
|
The exception is caused by the audio frames retaining their original PTS values from the input stream. Your new AAC encoder expects the first frame to start at PTS 0, but the first frame you feed it has PTS 1934336. The smallest fix for this specific error is to reset each audio frame's PTS before encoding, as the exception itself suggests: for audio_frame in container.decode(container.streams.audio[0]): Setting "pts = None" allows the encoder to assign timestamps instead of trying to preserve the input frame's original timestamp. Also, flush both encoders before closing the output container, or buffered packets may be lost: for packet in video_stream.encode(): for packet in audio_stream.encode(): output.close() If preserving the original audio exactly is more important than re-encoding it, an alternative is to remux the original audio packets using "output.add_stream(template=input_audio_stream)" and "output.mux(packet)". PyAV documents this approach in its "remuxing cookbook" (https://pyav.org/docs/stable/cookbook/basics.html#remuxing). |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Overview
I want to make modification on the images only on a video. I am using pyav to load and save it.
Expected behavior
The output video must be a video with both video and audio stream.
Actual behavior
I only manage to output either an audio or a video (without audio) file.
My code look like this:
With the previous code, the output is a video without audio and I got the following traceback:
Now I've tried to change the order of stream (starting with the audio) and I only got an audio file without video. In this order there is no error displayed, and I can see 2 streams in the output when I'm in debug mode.
All reactions