• 音视频解封装demo:将FLV文件解封装(demux)得到文件中的H264数据和AAC数据(纯手工,不依赖第三方开源库)


    1、README

    前言

    注意:flv是不支持h.265封装的。目前解封装功能正常,所得到的H.264文件与AAC文件均可正常播放。

    a. demo使用
    $ make clean && make DEBUG=1
    $ 
    $ $ ./flv_demux_h264_aac 
    Usage: 
       ./flv_demux_h264_aac avfile/test1.flv
       ./flv_demux_h264_aac avfile/test2.flv
    
    b. 参考链接

    【参考文章】

    【参考源码】

    【工具下载】

    c. demo目录架构
    $ tree
    .
    ├── aac_adts.c
    ├── aac_adts.h
    ├── avfile
    │   ├── test1.aac
    │   ├── test1.flv
    │   ├── test1.h264
    │   ├── test2.aac
    │   ├── test2.flv
    │   └── test2.h264
    ├── docs
    │   ├── FLV封装格式介绍及解析 - 简书.mhtml
    │   ├── FLV格式详解_JT同学的博客-CSDN博客_flv格式.mhtml
    │   ├── 笔记---H.264里的SEI - 简书.mhtml
    │   ├── 音视频封装:FLV格式详解和打包H264、AAC方案(上) - 云+社区 - 腾讯云.mhtml
    │   └── 音视频封装:FLV格式详解和打包H264、AAC方案(下) - 云+社区 - 腾讯云.mhtml
    ├── flv.c
    ├── flv_format.h
    ├── flv.h
    ├── h264_nalu.h
    ├── main.c
    ├── Makefile
    ├── README.md
    ├── reference_code
    │   └── Flv_to_h264_AAC_Demux.zip
    └── tools
        ├── FlvParse.exe
        ├── H264BSAnalyzer.exe
        └── SpecialAAAC.exe
    

    2、主要代码片段

    flv_format.h
    /***************************************************************
     * describe: Flv file format description(Mainly for H.264 & AAC)
     * author: linriming
     * e-mail: linriming20@163.com
     ***************************************************************/
    
    #ifndef __FLV_FORMAT_H__
    #define __FLV_FORMAT_H__
    
    
    #include 
    
    
    #define AUDIO_SUPPORT(x)    (x << 2)    /* bit[2] in flvheader's type_flag */
    #define VIDEO_SUPPORT(x)    (x << 0)    /* bit[0] in flvheader's type_flag */
    
    
    #define SIZE_FLV_HEADER         sizeof(struct flvHeader)    /* 9 Bytes */
    #define SIZE_FLV_TAG_HEADER     sizeof(struct flvTagHeader) /* 11 Bytes */
    #define SIZE_PREVIOUS_TAG_SIZE  sizeof(uint32_t)            /* 4 Bytes */
    
    
    /* FLV tag type */
    typedef enum{
    	FLVTAG_TYPE_AUDIO  = 0x08,
    	FLVTAG_TYPE_VIDEO  = 0x09,
    	FLVTAG_TYPE_SCRIPT = 0x12,
    }flvTagType;
    
    
    /* AMF data type in