跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[分享创造] 利用 b 站二压, 30fps 和 60fps 下显示不同的画面

发表于

效果图

4gllUch.png

简单来说,当一个高 FPS 的视频压缩为较低 FPS 的视频时,会选择某些帧作为关键帧插入。

B 站提供了 30fps 或 60fps 的视频。

因此,我们可以创建一个 120fps 的视频,然后在第1+4n 帧插入你希望在 30fps 下显示的内容,其余帧则插入你希望在 60fps 下显示的内容。

这样,在阿 b 二压后,30fps 和 60fps 的视频就会显示不同的画面。

至于“1+4n”这个公式的由来。

可以首先制作一个每帧都标有序号的 120fps 视频。然后使用 ffmpeg 将视频转换为 30fps ,观察哪些帧被保留,从而确定关键帧。

proof of concept

懒得传 gist 了

import cv2

class Fps120FrameReader:
    def __init__(self, filename):
        self.src = cv2.VideoCapture(filename)
        self.framerate = int(self.src.get(cv2.CAP_PROP_FPS))
        if self.framerate not in [30,60,120]:
            raise Exception(f"not support frame rate other than 30, 60, 120, framerate {self.framerate}")
        self.current_frame = 0
        self.frame = None

    def read(self):
        if self.current_frame % (120 // self.framerate) == 0:
            ok, self.frame = self.src.read()
            if not ok:
                self.frame = None
        self.current_frame +=1
        return self.frame

    def close(self):
        return self.src.release()

    @property
    def size(self):
        return int(self.src.get(cv2.CAP_PROP_FRAME_WIDTH)),int(self.src.get(cv2.CAP_PROP_FRAME_HEIGHT))



readerA = Fps120FrameReader('igotsmoke.mp4')
readerB = Fps120FrameReader('benkui.mp4')

assert readerA.size == readerB.size

fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter('output_video_C.mp4', fourcc, 120, readerA.size)

frame_count = 0
while True:
    frameA = readerA.read()
    frameB = readerB.read()

    if frameA is None or frameB is None:
        break

    if frame_count % 4 == 1:
        out.write(frameA)
    else:
        out.write(frameB)

    frame_count += 1

readerA.close()
readerB.close()
out.release()

print("ok")

Featured Replies

No posts to show

创建帐户或登录来提出意见

Account

导航

搜索

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.