You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
time_base for the stream returned when calling add_stream_from_template is None and if you try to assign it, then it gives an error about it being a decoder.
Here's code that can be used to reproduce it:
import sys
from av import open as av_open
def _main(input_filename: str, output_filename: str, set_time_base: bool):
with av_open(input_filename) as in_container, av_open(output_filename, "w") as out_container:
in_video = in_container.streams.video[0]
in_audio = in_container.streams.audio[0]
print("In:", in_video.time_base, in_audio.time_base)
out_video = out_container.add_stream_from_template(in_video)
if set_time_base:
out_video.time_base = in_video.time_base
out_audio = out_container.add_stream_from_template(in_audio)
if set_time_base:
out_audio.time_base = in_audio.time_base
print("Out:", out_video.time_base, out_audio.time_base)
for packet in in_container.demux():
out_container.mux_one(packet)
if __name__ == "__main__":
if len(sys.argv) <= 2:
print("usage:", sys.argv[0], "<input> <output>")
sys.exit(1)
_main(sys.argv[1], sys.argv[2], len(sys.argv) > 3 and sys.argv[3] in ("y", "Y"))
Running with a file will output the following:
In: 1/16000 1/8000
Out: None None
And then adding a 3rd argument of y or Y will try to set it and cause it to fail with this error:
Traceback (most recent call last):
File "/usr/src/app/test_add_stream.py", line 30, in <module>
_main(sys.argv[1], sys.argv[2], len(sys.argv) > 3 and sys.argv[3] in ("y", "Y"))
File "/usr/src/app/test_add_stream.py", line 19, in _main
out_audio.time_base = in_audio.time_base
File "av/stream.pyx", line 127, in av.stream.Stream.__setattr__
File "av/codec/context.pyx", line 541, in av.codec.context.CodecContext.time_base.__set__
RuntimeError: Cannot access 'time_base' as a decoder
Activity
ncheng89 commentedon Aug 1, 2025
I also encountered this problem. I copied the input stream as a template and did not copy the time base of the input stream to the output stream.