0

I'm trying to create a video from a set of jpg images. I would like that each frame of the video is exactly the same of the images used to create it. In order to get this result I'm using the following command:

ffmpeg -i %05d.jpg -c:v huffyuv test.avi

However if I check if the first frame is equal to the first image used to create the video I get some differences. In order to check this I used the following code:

import argparse
import cv2
import glob
import os
from os.path import isfile, join

parser = argparse.ArgumentParser()

parser.add_argument(
    "video",
    default = None,
    help = 'video to be compared',
    type = str)
parser.add_argument(
    "image",
    default = None,
    help = 'image to be compared with the first frame of the video',
    type = str)

args = parser.parse_args()

# opening video
cap = cv2.VideoCapture(args.video)
# reading first frame
ret, frame = cap.read()

# opening image
image = cv2.imread(args.image)

# computing difference between the first frame of the video and the image
diff = frame - image

# showing the differences: the two images are equal if the result is a black image
cv2.imshow("diff", diff)
cv2.waitKey(0)
cv2.destroyAllWindows()

If I use opencv to perform the conversion the result is as expected: no differences between the first frame and the first image used to create the video. This is python code used to generate the video from the images:

import argparse
import cv2
import glob
import os

parser = argparse.ArgumentParser()

parser.add_argument(
    "jpg_folder",
    default = None,
    help = 'Path to folder with numbered jpg folder, must be alphabetically ordered (e.g 00000.jpg, 00001.jpg, ...)',
    type = str)
parser.add_argument(
    "avi_output",
    default = None,
    help = 'name of the outputavi file',
    type = str)
parser.add_argument(
    "--frame-rate",
    default = 30,
    help = 'number of frame per second used in the genrerated video (default is 30)',
    type = int)

args = parser.parse_args()

#read images to be used to create the video
files = glob.glob(os.path.join(args.jpg_folder,'*.jpg'))
files.sort(key=lambda x: x)

#extract images dimensions
tmp_img = cv2.imread(files[0])
height, width, layers = tmp_img.shape

#create video writer with lossless codec
out = cv2.VideoWriter(args.avi_output,cv2.VideoWriter_fourcc('H', 'F', 'Y', 'U'), args.frame_rate, (width, height))
#read each image and add it to the video
for filename in files:
    jpgImage = cv2.imread(filename) 
    out.write(jpgImage)
#release the resource used to write the video
out.release()

Am I missing some option in order to get the same result using ffmpeg?

rlar
  • 856
  • 1
  • 10
  • 15
  • True lossless: ffmpeg -i %05d.jpg -c:v copy test.avi – Nuzhny Mar 20 '19 at 15:23
  • I already tried this command, and tried it now as well, but it suffers of the same issue. Did you try to convert some images and test with the script I've written above if the first frame of the video is the same of the first image used to create it? – rlar Mar 20 '19 at 15:41

0 Answers0