简体   繁体   English

Python 新的n帧视频比输入视频重

[英]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.

相关问题 尝试通过按键输入更改视频帧 - Trying to change Video Frame by key input 如何使用python OpenCV处理视频文件的速度比文件帧速率快? - How to process video files with python OpenCV faster than file frame rate? 是否有用于实时视频输入的Python库? - Is there a Python library for live video input? 无法使用cv2.VideoCapture(video_path).set(cv2.CAP_PROP_FPS,new_frame_rate)更改输入视频的帧速率 - Not able to change frame-rate for input video using cv2.VideoCapture(video_path).set(cv2.CAP_PROP_FPS, new_frame_rate) 如何在opencv python中获取视频的前一帧 - How to get previous frame of a video in opencv python 限制python和opencv上的视频捕获帧速率 - Limiting video capture frame rate on python and opencv 用python视频中的图像替换帧范围 - Replace frame range with image in a video with python 如何在 python 中获取带有 imageio 的视频的最后一帧? - How to get the last frame of a video with imageio in python? 使用 Python 解析和渲染 Kinesis Video Streams 并获取输入帧的图像表示 - Using Python to parse and render Kinesis Video Streams and get an image representation of the input frame 如何在Python OpenCV中裁剪图像/视频 - How to crop an Image/Video n Python OpenCV
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM