opencv videowriter控制bi

2024-10-01 17:35:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个使用opencv中的videowriter的python脚本。在

https://gist.github.com/stanchiang/b4e4890160a054a9c1d65f9152172600


如果我接收一个文件,不管我是简单地将视频帧传递给编写器(有效地复制文件),还是尝试编辑帧,文件总是较大的。我希望它不比原稿大(因为如果你读我的剧本,我会模糊很多东西)。在

在检查了它们的元数据之后,使用ffprobe -v quiet -print_format json -show_format -show_streams inputFile.mp4我注意到新文件的比特率比以前提高了5.5倍以上。在

https://www.diffchecker.com/8r2syeln


由于比特率是文件大小的一个重要决定因素,我想知道

  1. 我可以通过视频编写器硬编码新文件的所需比特率
  2. 是否因为某种原因需要大幅提高的比特率

Tags: 文件httpsgithub脚本comformat编辑视频
1条回答
网友
1楼 · 发布于 2024-10-01 17:35:47

基本上这个答案是https://stackoverflow.com/a/13298538/1079379

# import packages
from PIL import Image
from subprocess import Popen, PIPE
from imutils.video import VideoStream
from imutils.object_detection import non_max_suppression
from imutils import paths
import cv2
import numpy as np
import imutils

# ffmpeg setup
p = Popen(['ffmpeg', '-y', '-f', 'image2pipe', '-vcodec', 'mjpeg', '-r', '24', '-i', '-', '-vcodec', 'h264', '-qscale', '5', '-r', '24', 'video.mp4'], stdin=PIPE)

video = cv2.VideoCapture('videos.mp4')

while True:
    ret, frame = video.read()
    if ret:
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        im = Image.fromarray(frame)
        im.save(p.stdin, 'JPEG')
    else:
        break

p.stdin.close()
p.wait()
video.release()
cv2.destroyAllWindows()

相关问题 更多 >

    热门问题