picamera2 icon indicating copy to clipboard operation
picamera2 copied to clipboard

[BUG] PyAvOutput create files with wrong reported resolution

Open azsde opened this issue 5 months ago • 5 comments

Hi,

I'm using the following code:

from picamera2 import Picamera2
from picamera2.encoders import H264Encoder, Quality
from picamera2.outputs import PyavOutput

import time


# Declare picam
picam2 = Picamera2()

mode=picam2.sensor_modes[1] # Here mode 1 supports up to 1080p@56fps on the camera v3
sensor={'output_size': mode['size'],'bit_depth':mode['bit_depth']}

# Create and set video configuration
video_config = picam2.create_video_configuration(main={"size": (1920, 1080), "format": "YUV420"},
                                            sensor=sensor,
                                            controls={
                                                'FrameRate': 60,
                                                'NoiseReductionMode': 1,
                                                'AfMode': 1,
                                                'AeConstraintMode': 2}, # 0 = Normal, 1 = ConstraintHighlight , 2 = ConstraintShadows
                                            )
picam2.configure(video_config)
h264encoder = H264Encoder(framerate=60)

picam2.start()

output = PyavOutput("test.mp4")
picam2.start_recording(h264encoder, output, quality=Quality.HIGH)

time.sleep(10)

picam2.stop_recording()


The produced file is reported as 640 x 480 in resolution instead of the 1920x1080.

The actual stream seems to be fine as VLC seems to correctly detect the size, so does handbrake. But premiere pro sees 640 x 480 and editing the video is really annoying.

Am I doing something wrong or is there a bug ?

The only way to fix the file's resolution without re-encoding was to use the following commands:

# Get the effective FPS of the initial MP4 file
ffprobe -v 0 -select_streams v:0 -show_entries stream=r_frame_rate \
    -of default=noprint_wrappers=1:nokey=1 myvideo.mp4

# Extract the h264 stream
ffmpeg -y -i myvideo.mp4 -an -c:v copy -bsf:v h264_mp4toannexb temp.h264

# Remux the h264 stream into an MP4 file and specify its frame rate
ffmpeg -y -r <FPS> -i temp.h264 -c:v copy myvideo-fixed.mp4

azsde avatar Jul 29 '25 09:07 azsde

What kind of Pi is this?

davidplowman avatar Jul 29 '25 12:07 davidplowman

Pi5 with latest updates

azsde avatar Jul 29 '25 14:07 azsde

I think I am seeing something funny on a Pi 5, it may be the same on other Pis. Looking at the mp4 file, the "moov -> trak -> mdia -> minf -> stbl -> stsd -> avc1" box (if I'm reading it all correctly) is reporting 640x480.

Ah, I think maybe I see something. Are you able to test if the branch here improves things for you? It seems to fix the avc1 box resolution.

davidplowman avatar Jul 29 '25 15:07 davidplowman

@davidplowman with your branch it works as expected :)

azsde avatar Jul 29 '25 15:07 azsde

Fantastic! Well, I'll merge that onto next and it'll be in the next release.

davidplowman avatar Jul 29 '25 15:07 davidplowman