简体   繁体   English

如何将最初来自电影的一系列图像转换为电影

[英]How to convert into a movie a series of images that were originally from a movie

I have a set of jpg images.我有一组 jpg 图像。 These images were originally taken from a movie.这些图像最初是从电影中拍摄的。 It was in C++ something like (I am explaining how I got these images for reference. This is not the main part of the question)它在 C++ 中(我正在解释我是如何获得这些图像以供参考的。这不是问题的主要部分)

cv::Mat test_image;

cv::VideoCapture video_capture;
video_capture.open(test_video_name);
while(true){
  video_capture >> test_image;
  if (test_image.empty()) break;
  std::string input_file_name=get_file_name();
  cv::imwrite(input_file_name,test_image);
  }

Anyway, I got these images and I want to convert them back into a movie using Python无论如何,我得到了这些图像,我想使用 Python 将它们转换回电影

so I do所以我愿意

import cv2 as cv
import glob

glob_arg= image_folder+"/*.jpg"

size=getSize()
out = cv.VideoWriter(output_video,cv.VideoWriter_fourcc(*'DIVX'), 10, size)
for filename in sorted(glob.glob(glob_arg)):
    img = cv.imread(filename)
    print(filename)
    out.write(img)

out.release()

Now, my problem is in the VideoWriter problem, specifically the "10" parameter.现在,我的问题在于VideoWriter问题,特别是“10”参数。 How can I know what value to put there?我怎么知道放在那里的价值? This parameter is the number of frames per second.这个参数是每秒的帧数。 How can I determine it so as to have the same or similar movie as the original one?如何确定它与原始电影相同或相似?

In your C++ code, you can add this line under video_capture.open(test_video_name);在您的 C++ 代码中,您可以在video_capture.open(test_video_name);下添加这一行to get the FPS of the video:获取视频的 FPS:

double fps = video.get(CAP_PROP_FPS);
std::cout << fps << std::endl;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM