Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video not saving for different codec formats and dimension #761

Open
hkair opened this issue Dec 16, 2022 · 1 comment
Open

Video not saving for different codec formats and dimension #761

hkair opened this issue Dec 16, 2022 · 1 comment

Comments

@hkair
Copy link

hkair commented Dec 16, 2022

Expected behaviour

I am currently trying to write a video after applying some mediapipe operations.
The video with (size: 1080 x 1920, codec: MPEG-4 AAC, Timed Metadata, HEVC) is able to be written by the cv.VideoWriter class, but for some reason a video with (size: 720 x 1080, codec: Timed Metadata, H.264, MPEG-4 AAC) is not being written. I assumed it was due to the H.264 codec. But, I'm not sure how to fix it at the moment. Apologies, if this is an easy fix!

For additional info, the larger video was recorded from a video and the smaller video was downloaded from facebook messenger, which is why i assume they have different codec formats.

Actual behaviour

Both video formats should be able to be written using cv.VideoWriter class.
Also, i have tried saving the video without any of the mediapipe operations. The behaviour is the same. When I view the frames with cv.imshow(), the frames are flipped for the 1080 x 1980 as well.

Steps to reproduce

  • example code
# OpenCV Capture
cap = cv.VideoCapture(args.input if args.input else 0)

# Create a VideoWriter object so we can save the video output
fourcc = cv.VideoWriter_fourcc(*'mp4v')
output_frames_per_second = 30.0
out = cv.VideoWriter(os.path.join(OUTPUT_DIR, args.output_filename),  
                        fourcc, 
                        output_frames_per_second, 
                        (args.width, args.height))

while cap.isOpened():
    hasFrame, frame = cap.read()
    print(hasFrame)
    if not hasFrame:
        # cv.waitKey()
        break
    
    # Flip image vertically if model type is mediatype
    if args.model_type == 'mediapipe':
        frame = cv.flip(frame, -1)
    # Get Pose Joints
    points = pose.returnPoints(frame)

    # Draw Pose Joints on frame
    pose.drawJoints(frame, points)

    # Display Frame
    # cv.imshow('OpenPose using OpenCV', frame)

    # Write the frame to the output video file
    out.write(frame)

if args.model_type == 'media':
    pose.close()

# Stop when the video is finished
cap.release()
     
# Release the video recording
out.release()
  • operating system
    mac os Ventura
  • architecture (e.g. x86)
    ARM (silicon)
  • opencv-python version
    opencv-contrib-python==4.6.0.66
    opencv-python==4.5.5.64
@hkair hkair changed the title Video not saving for different formats and dimension Video not saving for different codec formats and dimension Dec 16, 2022
@asmorkalov
Copy link
Collaborator

asmorkalov commented Dec 20, 2022

  1. cv::VideoWriter capabilities depend on back-end. Could you share cv.getBuildInformation() output and try to run the app with OPENCV_VIDEOIO_DEBUG=1 set in environment. Both logs allows to understand which backend is used.

the frames are flipped for the 1080 x 1980 as well.

This indicates that the orginal video may contain rotation meta information. OpenCV supports rotation meta if FFmpeg is used as backend for cv::VideoCapture. See CAP_PROP_ORIENTATION_AUTO  and CAP_PROP_ORIENTATION_META in documentation: https://docs.opencv.org/4.x/d4/d15/group__videoio__flags__base.html#gaeb8dd9c89c10a5c63c139bf7c4f5704d. cv::VideoWriter does not use rotation tags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants