FFmpeg修改AC3编码的描述子

目的:修改AC3编码的描述子标准,根据客户需求提供欧标和美标选项进行设定。

ac3格式

ATSC标准:ac3的stream_type =0x81, descriptor_tag =none

DVB标准: ac3的stream_type =0x06, descriptor_tag =0x6a

eac3格式

ATSC标准:eac3的stream_type = 0x87, descriptor_tag = none

DVB标准: eac3的stream_type =0x06, descriptor_tag =0x7a

查阅FFmpeg源码,其实已经提供了相关的设置接口和相关的字段定义,故可进行修改:
用opt.c中的av_opt_set函数可传参数进去,进行修改。
在mpegtsenc.c的AVOption结构体中,已对相关字段进行了定义。

在FFmpeg对音视频进行复用流程中,在调用avformat_write_header函数之前,可调用下面接口进行修改。(此时为EAC3编码)

#define MPEGTS_FLAG_SYSTEM_B        0x08
static void Muxer_ModifyAC3Desc(AVFormatContext *ofmt_ctx)
{        
        // set eac3_desc_flag
        // eac3_desc:  DVB:0x6a,  ATSC:0x87
        // stream_type = (ts->flags & MPEGTS_FLAG_SYSTEM_B)? 0x6a : 0x87; (from ffmpeg),
        // so we can change the value of flags
        ST_EncodeParams* pstEncodeParams        = Parameter_GetEncodeParams();
        int ac3_flag_value                                        = MPEGTS_FLAG_SYSTEM_B;
        char ac3_desc_flag[6]                                 = {0};

        (STANDARD_MODE_DVB == pstEncodeParams->enAC3DescStd) ? (ac3_flag_value = 0):
        (ac3_flag_value = MPEGTS_FLAG_SYSTEM_B);                                        
        sprintf(ac3_desc_flag, "%d", ac3_flag_value);
        av_opt_set(ofmt_ctx->priv_data, "mpegts_flags", ac3_desc_flag, 0);

        return;
}
原文地址:https://www.cnblogs.com/standardzero/p/12553220.html