0

When I am using OpenCV library to convert a single image to video and trying to extract a frame from the video, then both the frames and input are different as my project needs a lot of precision a single change in a pixel will change my project

import cv2

# Input image file
input_image = 'output.png'

# Output video file name
output_file = 'output_video.mp4'

# Frame rate (fps) of the output video
frame_rate = 60.0

# Read the input image
image = cv2.imread(input_image)

# Get the image dimensions
height, width, channels = image.shape

# Define the video writer object
fourcc = cv2.VideoWriter_fourcc(*'mp4v') 
video_writer = cv2.VideoWriter(output_file, fourcc, frame_rate, (width, height))

# Repeat the image to create multiple frames
for _ in range(int(frame_rate)):
    video_writer.write(image)

# Release the video writer and close the output file
video_writer.release()

print("Video generation completed.")

This is my code snippet please help me with this my complete project relies on it

petezurich
  • 9,280
  • 9
  • 43
  • 57
Venkat
  • 14
  • 1

1 Answers1

0

I am not 100% sure but it is likely due to the lossy conversion of the image to an mp4. To fix this, try using a lossless codec like H.264 Lossless for encoding the video. This stackoverflow question may help more.

hidude562
  • 18
  • 5