ffmpeg DASH 编码:vp9 编解码器的比特率始终为 200k

Posted

技术标签:

【中文标题】ffmpeg DASH 编码:vp9 编解码器的比特率始终为 200k【英文标题】:ffmpeg DASH encoding: always getting bitrate as 200k for vp9 codec 【发布时间】:2019-11-28 20:02:38 【问题描述】:

我正在使用以下命令,之前输入 here: 来生成 DASH 文件:

ffmpeg -y -nostdin -loglevel error -i "$1" \
        -map 0:v:0  -map 0:v:0 -map 0:v:0  -map 0:v:0  -map 0:v:0  -map 0:v:0 -map 0:a\?:0  \
        -maxrate:v:0 350k -bufsize:v:0 700k -c:v:0 libx264 -filter:v:0 "scale=320:-2"  \
        -maxrate:v:1 1000k -bufsize:v:1 2000k -c:v:1 libx264 -filter:v:1 "scale=640:-2"  \
        -maxrate:v:2 3000k -bufsize:v:2 6000k -c:v:2 libx264 -filter:v:2 "scale=1280:-2" \
        -maxrate:v:3 300k -minrate:v:3 100k -bufsize:v:3 600k -c:v:3 libvpx-vp9 -filter:v:3 "scale=320:-2"  \
        -maxrate:v:4 1088k -minrate:v:4 200k -bufsize:v:4 2176k -c:v:4 libvpx-vp9 -filter:v:4 "scale=640:-2"  \
        -maxrate:v:5 1500k -minrate:v:5 300k -bufsize:v:5 3000k -c:v:5 libvpx-vp9 -filter:v:5 "scale=1280:-2"  \
        -use_timeline 1  -use_template 1 -adaptation_sets "id=0,streams=0,1,2 id=1,streams=3,4,5 id=2,streams=a" \
        -threads 8 -crf 3 -seg_duration 5 -hls_init_time 1 -hls_time 5 -hls_playlist true -f dash "$2"

问题是,在输出中,vp9 编解码器的带宽始终为 200k(请参见下面的输出),而对于 h264 编解码器的相同视频带宽随着标准分辨率的不同而变化,而且相当小,我预计 vp9 会更少它压缩得更多。我已经使用多个不同的选项进行了测试,例如:-b:v-deadline-cpu-used-crf 等,但无法使用这些不同的值,我错过了什么?

样本输出mpd文件:

<?xml version="1.0" encoding="utf-8"?>
<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="urn:mpeg:dash:schema:mpd:2011"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xsi:schemaLocation="urn:mpeg:DASH:schema:MPD:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd"
    profiles="urn:mpeg:dash:profile:isoff-live:2011"
    type="static"
    mediaPresentationDuration="PT25.4S"
    minBufferTime="PT15.0S">
    <ProgramInformation>
    </ProgramInformation>
    <Period id="0" start="PT0.0S">
        <AdaptationSet id="0" contentType="video" segmentAlignment="true" bitstreamSwitching="true" lang="und">
            <Representation id="0" mimeType="video/mp4" codecs="avc1.64000c" band   frameRate="24000/1001">
                <SegmentTemplate timescale="24000" initialization="init-stream$RepresentationID$.m4s" media="chunk-stream$RepresentationID$-$Number%05d$.m4s" startNumber="1">
                    <SegmentTimeline>
                        <S t="0" d="130130" />
                        <S d="250250" />
                        <S d="176176" />
                        <S d="54054" />
                    </SegmentTimeline>
                </SegmentTemplate>
            </Representation>
            <Representation id="1" mimeType="video/mp4" codecs="avc1.64001e" band   frameRate="24000/1001">
                <SegmentTemplate timescale="24000" initialization="init-stream$RepresentationID$.m4s" media="chunk-stream$RepresentationID$-$Number%05d$.m4s" startNumber="1">
                    <SegmentTimeline>
                        <S t="0" d="130130" />
                        <S d="250250" />
                        <S d="180180" />
                        <S d="50050" />
                    </SegmentTimeline>
                </SegmentTemplate>
            </Representation>
            <Representation id="2" mimeType="video/mp4" codecs="avc1.64001f" band   frameRate="24000/1001">
                <SegmentTemplate timescale="24000" initialization="init-stream$RepresentationID$.m4s" media="chunk-stream$RepresentationID$-$Number%05d$.m4s" startNumber="1">
                    <SegmentTimeline>
                        <S t="0" d="130130" />
                        <S d="250250" />
                        <S d="180180" />
                        <S d="50050" />
                    </SegmentTimeline>
                </SegmentTemplate>
            </Representation>
        </AdaptationSet>
        <AdaptationSet id="1" contentType="video" segmentAlignment="true" bitstreamSwitching="true" lang="und">
            <Representation id="3" mimeType="video/mp4" codecs="vp09.00.11.08" band   frameRate="24000/1001">
                <SegmentTemplate timescale="24000" initialization="init-stream$RepresentationID$.m4s" media="chunk-stream$RepresentationID$-$Number%05d$.m4s" startNumber="1">
                    <SegmentTimeline>
                        <S t="0" d="128128" r="3" />
                        <S d="98098" />
                    </SegmentTimeline>
                </SegmentTemplate>
            </Representation>
            <Representation id="4" mimeType="video/mp4" codecs="vp09.00.21.08" band   frameRate="24000/1001">
                <SegmentTemplate timescale="24000" initialization="init-stream$RepresentationID$.m4s" media="chunk-stream$RepresentationID$-$Number%05d$.m4s" startNumber="1">
                    <SegmentTimeline>
                        <S t="0" d="128128" r="3" />
                        <S d="98098" />
                    </SegmentTimeline>
                </SegmentTemplate>
            </Representation>
            <Representation id="5" mimeType="video/mp4" codecs="vp09.00.31.08" band   frameRate="24000/1001">
                <SegmentTemplate timescale="24000" initialization="init-stream$RepresentationID$.m4s" media="chunk-stream$RepresentationID$-$Number%05d$.m4s" startNumber="1">
                    <SegmentTimeline>
                        <S t="0" d="128128" r="3" />
                        <S d="98098" />
                    </SegmentTimeline>
                </SegmentTemplate>
            </Representation>
        </AdaptationSet>
        <AdaptationSet id="2" contentType="audio" segmentAlignment="true" bitstreamSwitching="true" lang="eng">
            <Representation id="6" mimeType="audio/mp4" codecs="mp4a.40.2" band audiosamplingRate="44100">
                <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2" />
                <SegmentTemplate timescale="44100" initialization="init-stream$RepresentationID$.m4s" media="chunk-stream$RepresentationID$-$Number%05d$.m4s" startNumber="1">
                    <SegmentTimeline>
                        <S t="0" d="235520" r="3" />
                        <S d="180224" />
                    </SegmentTimeline>
                </SegmentTemplate>
            </Representation>
        </AdaptationSet>
    </Period>
</MPD>

我正在使用这个video,但我尝试过的所有大约 30 秒的视频都是一样的。

【问题讨论】:

【参考方案1】:

从这个answer 获得帮助,看来我必须使用Two-pass 编码或Constant Quality 编码。

当我使用Constant Quality 编码时,我删除了bufSizeminRate 等并将-b:v 设置为零,我能够生成不默认为200k 的可变比特率,下面的示例命令,我将测试Two-pass 编码也是如此。

ffmpeg -y -nostdin -loglevel error -i "$1" \
        -map 0:v:0  -map 0:v:0 -map 0:v:0  -map 0:v:0  -map 0:v:0  -map 0:v:0 -map 0:a\?:0  \
        -maxrate:v:0 350k -bufsize:v:0 700k -c:v:0 libx264 -filter:v:0 "scale=320:-2"  \
        -maxrate:v:1 1000k -bufsize:v:1 2000k -c:v:1 libx264 -filter:v:1 "scale=640:-2"  \
        -maxrate:v:2 3000k -bufsize:v:2 6000k -c:v:2 libx264 -filter:v:2 "scale=1280:-2" \
        -b:v:3 0 -c:v:3 libvpx-vp9 -filter:v:3 "scale=320:-2"  \
         -b:v:4 0 -c:v:4 libvpx-vp9 -filter:v:4 "scale=640:-2"  \
         -b:v:5 0 -c:v:5 libvpx-vp9 -filter:v:5 "scale=1280:-2"  \
        -use_timeline 1  -use_template 1 -adaptation_sets "id=0,streams=0,1,2 id=1,streams=3,4,5 id=2,streams=a" \
        -threads 32 -deadline best -cpu-used 1 -crf 3 -seg_duration 5 -hls_init_time 1 -hls_time 5 -hls_playlist true -f dash "$2"

【讨论】:

以上是关于ffmpeg DASH 编码:vp9 编解码器的比特率始终为 200k的主要内容,如果未能解决你的问题,请参考以下文章

WebRTC 视频编解码类型的选择 VP8 H264 还是其他?(openh264编码,ffmpeg解码)

WebRTC 视频编解码类型的选择 VP8 H264 还是其他?(openh264编码,ffmpeg解码)

聊聊视频中的编解码器,你所不知道的h264h265vp8vp9和av1编解码库

Google 视频编码格式 VP9 究竟厉害在哪里

ffmpeg mp4box制作dash流

webrtc支持h264