PyAV icon indicating copy to clipboard operation
PyAV copied to clipboard

Program crashes when output container uses input container properties as output container as template after input container is closed

Open ncheng89 opened this issue 1 year ago • 0 comments

Overview

Program crashes when output container uses input container properties as output container as template after input container is closed

Expected behavior

The corresponding exception should be thrown instead of crashing the program.

Actual behavior

root@941f5896c51c:/tmp# python3 test.py <av.VideoStream #0 h264, yuv420p 1920x1080 at 0x7f409f81c130> Check duration: Segmentation fault (core dumped) root@941f5896c51c:/tmp#

Investigation

This error is similar to the 1137 issue fixed in version 11.0.0

Reproduction

import os.path as osp import time

import av import numpy as np

def make_sample_video(save_path,in_video_stream): """ Modified example from: https://pyav.org/docs/stable/cookbook/numpy.html#generating-video """

# Avoid repeat video creation
if osp.exists(save_path):
    return

# Output settings (not important?)
duration = 4
fps = 24
total_frames = duration * fps
vid_w = 256
vid_h = 128

container = av.open(save_path, mode="w")
stream = container.add_stream(template=in_video_stream)
stream.width = vid_w
stream.height = vid_h
stream.pix_fmt = "yuv420p"

# Write random frames
for frame_i in range(total_frames):
    img = np.random.randint(0, 255, (vid_h, vid_w, 3), dtype=np.uint8)
    frame = av.VideoFrame.from_ndarray(img, format="rgb24")
    for packet in stream.encode(frame):
        container.mux(packet)

# Flush stream
for packet in stream.encode():
    container.mux(packet)

# Close the file
container.close()

sample_file_path = "rainbow_noise.mp4" container = av.open(sample_file_path, mode="r") in_video_stream = container.streams.video[0]

make_sample_video(sample_file_path,in_video_stream) print(in_video_stream)

time.sleep(3) container.close()

print("Check duration:") print(in_video_stream) #print(container.duration) print("Finished!") ` image

Versions

  • OS: Ubuntu 20.04.6
  • PyAV runtime: PyAV v11.0.0 library configuration: --disable-static --enable-shared --libdir=/tmp/vendor/lib --prefix=/tmp/vendor --disable-alsa --disable-doc --disable-libtheora --disable-mediafoundation --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libspeex --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-lzma --enable-version3 --enable-zlib library license: GPL version 3 or later libavcodec 60. 3.100 libavdevice 60. 1.100 libavfilter 9. 3.100 libavformat 60. 3.100 libavutil 58. 2.100 libswresample 4. 10.100 libswscale 7. 1.100

Additional context

https://github.com/PyAV-Org/PyAV/issues/1137

ncheng89 avatar Dec 29 '23 02:12 ncheng89