H.264 MP4文件中的像素格式存储在哪里? [英] Where is pixel format stored in H.264 MP4 file?

查看:241
本文介绍了H.264 MP4文件中的像素格式存储在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个转换器,它将H.264/AAC RTMP流转换为有效的MP4文件.我已经 大部分 完成了.我正在解析AMF标签,读取AVCDecoderConfigurationRecord和AACSpecificConfig,我正在生成有效的moov原子,等等.

I'm working on a transmuxer that will convert an H.264/AAC RTMP stream to a valid MP4 file. I'm mostly done. I'm parsing the AMF tag, reading the AVCDecoderConfigurationRecord and AACSpecificConfig, I'm generating a valid moov atom, etc.

在发现并修复了代码中的一些错误之后,我得到了一个 主要是 有效的MP4文件.但是,当我尝试在ffprobe中读取视频时,出现以下错误:

After discovering and fixing a few bugs in my code, I've got a mostly valid MP4 file. However when I attempt to read the video in ffprobe I get the following error:

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f9fb4000b80] Failed to open codec in avformat_find_stream_info
    Last message repeated 1 times
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f9fb4000b80] Could not find codec parameters for stream 1 (Video: h264 (avc1 / 0x31637661), none, 640x360): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options

找不到像素格式.浏览我的AVCDecoderConfigurationRecord解析逻辑(用于生成avcC原子作为avc1原子的一部分),我有以下内容:

It's unable to find the pixel format. Skimming through my AVCDecoderConfigurationRecord parsing logic (which is used to generate the avcC atom as part of the avc1 atom), I have the following:

// Parsed per: https://github.com/LiminWang/simple-rtmp-server/blob/master/trunk/doc/H.264-AVC-ISO_IEC_14496-15.pdf
var info = parseAVCConfig(packet);

// Fortunately my video sample has one of each of these
// I may need to concatenate multiple in the future
var sps = info.sps[0];
var pps = info.pps[0];

var avcc = box(
    types.avcC,
    new Uint8Array([
        // Version
        0x01,
        // Profile
        info.profile,
        // Profile Compat
        info.compat,
        // Level
        info.level,
        // LengthSizeMinusOne, hard-coded to 4 bytes (copied HLS.js)
        0xfc | 3,
        // 3bit reserved (111) + numOfSequenceParameterSets
        0xE0 | sps.byteLength
    ]
        .concat(Array.from(sps))
        .concat([
            // NumOfPictureParametersets
            pps.byteLength
        ])
        .concat(Array.from(pps))
    )
);

您可以看到avcc原子包含配置文件,兼容性和级别-但是之后,我仅直接从AVCDecoderConfigurationRecord复制了SPS和PPS.我在原子中的任何地方都没有定义像素格式,因此我假设它是SPS或PPS的一部分.

As you can see the avcc atom contains the profile, compat, and level -- but after that I just copy over the SPS and PPS directly from the AVCDecoderConfigurationRecord. Nowhere in the atom do I define a pixel format, so I assumed it was part of the SPS or PPS.

查看AVCDecoderConfigurationRecord的规范,没有专门称为像素格式"的内容,但是有"chroma_format","bit_depth_luma_minus8"和"bit_depth_chroma_minus_8"-但是,只有在配置文件为100、110, 122或244.我的个人资料是66(这些字节对我来说不存在)

Looking at the spec for the AVCDecoderConfigurationRecord, there's nothing specifically called "pixel format", but there is a "chroma_format", "bit_depth_luma_minus8", and "bit_depth_chroma_minus_8" -- however these only exist if the profile is 100, 110, 122, or 244. My profile is 66 (and these bytes don't exist for me)

目前,我正在做的概念验证仅支持单个视频,因此在最坏的情况下,我可以将像素格式硬编码为yuv420.但我什至不知道将这些信息放在输出MP4中的位置.它是否进入avcC原子?还是avc1原子?还是mvhd原子?

At the moment this proof of concept I'm doing only has to support a single video, so worst-case scenario I can hard-code the pixel format to yuv420. But I don't even know where to put this information in the output MP4. Does it go in the avcC atom? Or the avc1 atom? Or the mvhd atom?

链接:

  • buffer.mp4: This is the file I'm creating, which does not work. ffprobe says it cannot find the pixel format. http://files.stevendesu.com/buffer.mp4
  • test.mp4: This is a segment of the same video converted to MP4 by ffmpeg for comparison. http://files.stevendesu.com/test.mp4

推荐答案

看看chroma_format_idc记录ITU-T H.264建议书(04/2017)-7.3.2.1.1序列参数集数据语法. chroma_format_idc是SPS的一部分. 对于profile_idc 100、110、122、244、44、83、86、118、128、138、139、134或135,chroma_format_idc存储在SPS内.否则,您假设为1(= 4:2:0).

Take a look at the chroma_format_idc Rec. ITU-T H.264 (04/2017) - 7.3.2.1.1 Sequence parameter set data syntax. chroma_format_idc is part of SPS. For profile_idc 100, 110, 122, 244, 44, 83, 86, 118, 128, 138, 139, 134 or 135 the chroma_format_idc is stored inside the SPS. Otherwise you assume 1 (= 4:2:0).

7.4.2.1.1序列参数集数据语义

chroma_format_idc specifies the chroma sampling relative to the luma sampling as specified in clause 6.2. The value of
chroma_format_idc shall be in the range of 0 to 3, inclusive. When chroma_format_idc is not present, it shall be inferred
to be equal to 1 (4:2:0 chroma format).

这篇关于H.264 MP4文件中的像素格式存储在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆