iOS音视频开发视频编码学习之路音视频开发集锦

MKV 封装格式笔记(一)

2018-07-27  本文已影响349人  团不慌

本篇笔记主要记录AVS2MKV提交过程中的学习内容,主要包含:

  1. MKV格式介绍
  2. MKV工作方式
  3. MKV修改应用

主要参考链接: MKV - Matroska Home page // 各部分标注在相应标题中


1 What's MKV

Matroska aims to become THE standard of multimedia container formats. It was derived from a project called MCF, but differentiates from it significantly because it is based on EBML (Extensible Binary Meta Language), a binary derivative of XML. EBML enables the Matroska Development Team to gain significant advantages in terms of future format extensibility, without breaking file support in old parsers.

2 How MKV

2.1 Diagram - 文件结构

Simple Representation of a Matroska File

注:各段不是必须存在,也不仅限于上述种类,图中比例与实际数据量无关,各段详细结构参见:Detailed Diagram

2.2 Specifications - 规格草案

此处只记录该草案主要内容:

  1. EBML原理介绍 // 基础数据类型等
  2. 基础语义元素 // 名称、标志位、参数等
  3. 附录 // 使用语言、块结构等

具体参数要求详见 Specification Notes 以及 EBML Elements Order Guidelines.

2.3 Codec Specs - 编解码器说明

For each TrackEntry inside matroska, there has to be a CodecID defined. This ID is represent the codec used to encode data in the Track. The codec works with the coded data in the stream, but also with some codec initialisation. There are 2 different kind of codec "initialisation" :

  • CodecPrivate in the TrackEntry
  • CodecState in the BlockGroup

Each of these elements contain the same kind of data. And these data depend on the codec used.

对于各种codecMKV只需要其提供一个基本的CodecID用于标识,并允许其根据需要定制初始化部分。
个人理解MKV不负责编解码器的细节,它的作用只是向播放器解释流的类型,以及向解码器传递所需的信息。在播放过程中需要的信息都会从标签中找到,即使什么都没有提供也只是降低了性能。

2.4 Video Tags Example - 视频标签

该部分以及 Matroska Test Suite 应该说都是 Matroska 对视频质量提升的一种建议。

Video content usually doesn't have tags in the file. But that doesn't mean it's a good thing. Here are some real-life examples where it makes sense to have tags. As for audio you can have all video parts of a bigger ensemble in the same file or in smaller files.

常规视频中很少包含(现在多了)一些与视频内容有关的“非必要”标签,但实际上这些标签还是很有意义的。MKV提供了视频标签的支持,并给出了一些范例。(而在 Matroska Test Suite 中主要是对视频自测的一些内容)

3 修改MKV支持AVS2

  1. 想要在MKV中加入新的codec支持第一部应该是加入对应的描述,即CodecID,则首先应该向MKV标准提交相应的CodecID申请,提交的地址:Matroska-Org/matroska-specification

  2. 确定使用的CodecID后,在FFmpegVLC中,分别找到MKV的编解码器描述符定义位置:ffmpeg/libavformat/matroska.cvlc/modules/demux/mkv/matroska_segment_parse.cpp,在其中加入Mkv_CodecID => Player_CODEC_ID的对应关系

  3. 重新编译后测试ffmpeg的支持(使用版本为FFmpegAVS2):

./ffmpeg -i test.avs2 -c:v copy test.mkv

重新编译后测试VLC支持(使用版本为之前自己改的VLC-AVS2):直接播放 test.mkv

播放截图

结果还是很不错的,单纯从效果看的话。视频压的很短,目前还缺乏充足的测试(跳转、同步等等)。

但想来想去还是有不少问题:

... ...


还是懂得太少。

上一篇 下一篇

猜你喜欢

热点阅读