Skip to content

[BUG] PyAvOutput create files with wrong reported resolution #1301

@azsde

Description

@azsde

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions