The jpg format images into a variety of YUV sequence, three of brief (there are many online data)
1, FFmpeg and Python
Original: https://blog.csdn.net/yuejisuo1948/article/details/83512539
since the run to be coded, it is necessary to create a data set .yuv picture format, but the hand only .png / .jpg format, so that recording under the conversion process. Other image format can be, modify the code on the trip.
Command to convert a single file:
ffmpeg -i xxx.png -s WxH -pix_fmt yuv420p10le xxx.yuv
-i represents the input picture represented the path -s output picture resolution
-pix_fmt is a picture format, see https://blog.csdn.net/yuejisuo1948/article/details/83617359
The last plane is the path of the output image
Batch conversion can write a bat file, it can be directly used in the following manner:
① install ffmpeg
Official website (all versions): ffmepg official website
window version: https://ffmpeg.zeranoe.com/builds/
② installation of ffmpeg python3 interfaces ffmpy3
Enter the following command at the command line:
pip install ffmpy3
③ unzip the downloaded version of windows, you will copy ffmpeg.exe to run python code folder
④python code is as follows:
# -*- coding: utf-8 -*-
import os
from PIL import Image
from ffmpy3 import FFmpeg
in_jpgDatasetPath = 'I:/VOC/trainval'
out_yuvDatasetPath = 'I:/VVC/loop/yuvdataset'
piclist = os.listdir(in_jpgDatasetPath)
for pic in piclist:
picname = pic.split('.')[0]
picpath = os.path.join(in_jpgDatasetPath,pic)
img = Image.open(picpath)
in_wid,in_hei = img.size
out_wid = in_wid//16*16
out_hei = in_hei//16*16
size = '{}x{}'.format(out_wid,out_hei) #输出文件会缩放成这个大小
outname = out_yuvDatasetPath + '/' + picname + '_'+size+ '.yuv'
ff = FFmpeg(inputs={picpath:None},
outputs={outname:'-s {} -pix_fmt yuv420p'.format(size)})
print(ff.cmd)
ff.run()
2, Opencv and Python
Original: https://blog.csdn.net/lql0716/article/details/53412252
import cv2
fps = 24 #视频帧率
fourcc = cv2.cv.CV_FOURCC('M','J','P','G')
videoWriter = cv2.VideoWriter('D:/testResults/match/flower2.avi', fourcc, fps, (1360,480)) #(1360,480)为视频大小
for i in range(1,300):
p1=0
p2=i
img12 = cv2.imread('D:/testResults/img_'+str(p1)+'_'+str(p2)+'.jpg')
# cv2.imshow('img', img12)
# cv2.waitKey(1000/int(fps))
videoWriter.write(img12)
videoWriter.release()
3、MATLAB
Original: https://blog.csdn.net/jxlijunhao/article/details/19981237?utm_source=tuicool&utm_medium=referral
function video=frames2Video(framesPath,videoName,quality,Compressed,fps,startFrame,endFrame)
%framesPath :图像序列所在路径,同时要保证图像大小相同
%videoName: 表示将要创建的视频文件的名字
%quality: 生成视频的质量 0-100
%Compressed: 压缩类型, 'Indeo3'(默认), 'Indeo5', 'Cinepak', 'MSVC', 'RLE' or 'None'
%fps: 帧率
%startFrame ,endFrame ;表示从哪一帧开始,哪一帧结束
if(exist('videoName','file'))
delete videoName.avi
end
%生成视频的参数设定
aviobj=avifile(videoName); %创建一个avi视频文件对象,开始时其为空
aviobj.Quality=quality;
aviobj.Fps=fps;
aviobj.compression=Compressed;
%读入图片
for i=startFrame:endFrame
fileName=sprintf('%08d',i); %根据文件名而定 我这里文件名是00000001.jpg 00000002.jpg ....
frames=imread([framesPath,fileName,'.jpg']);
aviobj=addframe(aviobj,uint8(frames));
end
aviobj=close(aviobj); % 关闭创建视频
end
Enter the command window in
path='你的文件路径';
frames2Video(path,'dog',90,'None',5,1,32);