[英]Python New n frame video is heavier than the input video
I managed to write a code to decimate my video and take only 1 frame out of 10, in order to make my neural network more efficient in the future for character recognition.我设法编写了一个代码来抽取我的视频,并且只取 10 帧中的 1 帧,以便让我的神经网络在未来更有效地进行字符识别。 The new video
exit_video
is well decimated because it's way faster than the previous one.新视频
exit_video
被很好地抽取,因为它比前一个快得多。
1: When I print the fps of the new video, I have 30 again despite the decimation 1:当我打印新视频的 fps 时,尽管抽取,我还是有 30
2: Why is my new video heavier? 2:为什么我的新视频比较重? 50.000 ko and it was 42.000 ko for the firts one
50.000 ko,第一个是 42.000 ko
Thanks for your help谢谢你的帮助
import cv2
#import os
import sys
video = cv2.VideoCapture("./video/inputvideo.mp4")
frameWidth = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
frameHeight = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
frameFourcc = int(video.get(cv2.CAP_PROP_FOURCC))
success,image = video.read()
if not success:
print('impossible de prendre une frame')
sys.exit()
fps = video.get(cv2.CAP_PROP_FPS)
print("fps de base " + str(fps))
print(frameFourcc)
count = 0
exit_file = 'decimated_v1.mp4'
exit_video = cv2.VideoWriter(exit_file, frameFourcc, fps, (frameWidth, frameHeight))
while True:
if ((count % 10 ) ==0):
exit_video.write(image)
success,image = video.read()
if not success:
break
count +=1
exit_video.release()
exit_video_info = cv2.VideoCapture("decimated_v1.mp4")
fps_sortie = exit_video_info.get(cv2.CAP_PROP_FPS)
print("fps de sortie " + str(fps_sortie))
Decimating a video file that's not all Intra frames will require re-encoding.抽取并非所有帧内帧的视频文件将需要重新编码。 Unless your input file is eg ProRes or MJPEG, that's likely going to be the case.
除非您的输入文件是 ProRes 或 MJPEG,否则很可能会出现这种情况。
Since you're not setting encoding parameters, OpenCV likely end up using some defaults that end up with a higher bitrate than your input file.由于您没有设置编码参数,因此 OpenCV 可能最终会使用一些最终比特率高于输入文件的默认值。
You'll probably have a better time using the FFmpeg tool than OpenCV, and its select
filter .与 OpenCV 及其
select
过滤器相比,使用 FFmpeg 工具可能会更好。
ffmpeg -i ./video/inputvideo.mp4 -vf select='not(mod(n\,10))' ./decimated_v1.mp4
would be the basic syntax to use every tenth frame from the input;将是使用输入中每十帧的基本语法; you can then add your desired encoding parameters such as
-crf
to adjust the H.264 rate factor – or, of course, you can change to a different codec altogether.然后,您可以添加所需的编码参数,例如
-crf
来调整 H.264 速率因子——当然,您也可以完全更改为不同的编解码器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.