Video Encoder Basic

本文详细介绍了视频编码的基础概念,包括视频流结构、帧类型(IFrame、BFrame、PFrame)、编码方式(CBR、VBR、ABR)及其优缺点,并对比了单次和两次通过VBR编码的区别。此外,还解释了3:2 Pull Down技术以及NTSC制式下29.97 fps帧率的选择原因。

1.     Video Stream Structure

l  Stream: a coded video stream, consists of successive GOPs

l  GOP: group of successive picture

l  Picture: equal to the frame (I frame, B frame, P frame)

l  Slice: a group of macro blocks

l  Macro Block: consists of two of more blocks of pixels. In MPEG2 and other early codec the size is fixed at blocks of 8x8 pixels. In more modern codec such as h.263 and h.264 the overarching macro block size is fixed at 16x16 pixels

l  Structure Diagram

 Structure Diagram

     

2.     I Frame, B Frame, P Frame

l  I Frames: intra coded frames. That is, all the information to reconstruct an I Frame access unit is contained in that access unit. It is essentially a JPEG image.

l  P Frame: forward Predictive coded frames (inter frames). This means that macro-blocks in a P-Frame refer to an access unit in the future.

l  B Frame: bidirectional predictive coded frames (inter frames). This means that macro-blocks in a B-Frame refer to an access unit in the future and an access unit in the past

 

3.     CBR, VBR, ABR

l  CBR

²  Constant bit rate encoding means that the rate at which a codec's output data should be consumed is constant.

²  CBR would not be the optimal choice for storage as it would not allocate enough data for complex sections (resulting in degraded quality) while wasting data on simple sections.

 

l  VBR

²  VBR allows a higher bitrate (and therefore more storage space) to be allocated to the more complex segments of media files while less space is allocated to less complex segments.

²  The advantages of VBR are that it produces a better quality-to-space ratio compared to a CBR file of the same data. The bits available are used more flexibly to encode the sound or video data more accurately, with fewer bits used in less demanding passages and more bits used in difficult-to-encode passages.

²  The disadvantages are that it may take more time to encode, as the process is more complex, and that some hardware might not be compatible with VBR files.

 

l  ABR

²  It can have higher bitrate and lower bitrate parts, and the average bitrate for a certain timeframe is obtained by dividing the number of bits used during the timeframe by the number of seconds in the timeframe.

²  As it is a form of variable bitrate, this allows more complex portions of the material to use more bits and less complex areas to use fewer bits.

²  ABR encoding is desirable for users who want the general benefits of VBR encoding (an optimum bitrate from frame to frame) but with a relatively predictable file size.

 

l  At a given bitrate, VBR is usually higher quality than ABR, which is higher quality than CBR (constant bitrate).

 

4.     1-Pass vs. 2-Pass

l  One pass VBR has a moving window over which it analyzes the video.  That is, the encoder looks ahead a second or two decides how complex the video is and allocated bits based on that information. Because it is only looking ahead a short time in the future it has no idea how complex the video is much later in the movie so the allocation is not as optimal as it could be

l  Two pass VBR analyzes the entire movie for video complexity in the first pass.  It then stores this information.  It can take advantage of knowing the variation in complexity of the entire movie and allocate bits more effectively than the 1-pass approach.

l  For example, perhaps the beginning of the movie is all very high action but the end is people sitting quietly talking.  The high action is much more difficult to encode and should be allocated many more bits than the talking part of the movie.  The two pass algorithm can take advantage of knowing the complexity of the entire movie while the one pass cannot.

l  Single-pass encoding is used when the encoding speed is most important - e.g. for real-time encoding.

l  Two pass encoding is used when the encoding quality is most important. Two pass encoding cannot be used in real-time encoding, live broadcast or live streaming.

 

5.     3:2 Pull Down

l  Display the video with 24fps on NTSC 29.97fps

l  Implement

 

3:2 Pulldown

 

6.     Why is 29.97fps, rather than 30 fps

l  In the days of black and white TV, the frame rate was 30 fps

l  When they added color, they had to add in extra data but wanted to keep the signal backwardly compatible with black and white TVs

l  The addition of the color subcarrier also required a slight reduction of the frame rate from 30 frames per second to 30/1.001 (very close to 29.97) frames per second

 

7.     Drop Frame & Non Drop Frame

l  Display the video with 30fps on NTSC 29.97fps

l  (30fps – 29.97fps) x 60seconds=1.8frames, you cannot adjust by 1.8 frames per minute, but you can adjust by 18 full frames per 10 minutes.

l  Because 10 minutes is not evenly divisible by 18 frames, we use drop-frame timecode and drop two frame numbers every minute; by the ninth minute, you have dropped all 18 frame numbers. No frames need to be dropped the tenth minute. That is how drop-frame timecode works.

 

### 如何安装和配置 OBS Encoder OBS Encoder 是 OBS Studio 的核心组件之一,用于处理视频和音频流的编码。以下是关于如何安装和配置 OBS Encoder 的详细指南。 #### 1. 安装 OBS Studio OBS Encoder 通常是 OBS Studio 的一部分,因此安装 OBS Studio 就可以使用其内置的编码器。可以从官方网站下载并安装 OBS Studio[^4]。 - 前往 [OBS 官方网站](https://obsproject.com/) 下载最新版本。 - 根据操作系统选择合适的安装包(Windows、macOS 或 Linux)。 - 安装完成后,启动 OBS Studio。 #### 2. 配置 OBS Encoder OBS Encoder 的配置可以通过 OBS Studio 的设置界面完成。以下是具体步骤: - **打开设置**:在 OBS Studio 中,点击右下角的齿轮图标,选择“设置”。 - **选择输出**:在左侧菜单中选择“输出”,根据需求选择流媒体或文件输出模式。 - **配置编码器**:在“输出”选项卡中,选择“高级输出模式”。然后,在“编码器”下拉菜单中选择所需的编码器类型(如 x264、NVENC 等)[^5]。 - **调整参数**:根据需要调整比特率、关键帧间隔等参数。这些参数直接影响视频质量与文件大小。 #### 3. 自定义编码器(高级用户) 如果需要自定义编码器设置,可以使用以下方法: - **修改配置文件**:OBS Studio 的配置文件通常位于用户目录下的 `obs-studio/basic/profiles` 文件夹中。可以通过编辑 JSON 配置文件来调整编码器参数[^6]。 - **命令行参数**:对于开发者或高级用户,可以通过代码调用 `obs_encoder_set_video` 函数设置视频编码器参数[^2]。 ```python # 示例:通过 Python 调用 OBS API 设置编码器 import obspython as obs def set_encoder(encoder_name, video_object): encoder = obs.obs_get_encoder_by_name(encoder_name) if encoder is not None: obs.obs_encoder_set_video(encoder, video_object) obs.obs_encoder_release(encoder) ``` #### 4. 使用外部编码器 如果需要使用外部编码器(如 FFmpeg),可以按照以下步骤操作: - 在 OBS Studio 的“工具”菜单中选择“FFmpeg 输出路径”。 - 设置 FFmpeg 可执行文件的路径。 - 在输出设置中选择“FFmpeg 推流”作为输出模式。 --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值