Audio 混入MPEG-TS:音频流参数错误

Audio 混入MPEG-TS:音频流参数错误,audio,ffmpeg,pcm,mpeg2-ts,Audio,Ffmpeg,Pcm,Mpeg2 Ts,我正在尝试使用ffmpeg将视频(H.264)和音频(PCM_S16LE,无压缩)多路复用到MPEG传输流中。视频显示很好。但是,音频流不会播放。ffprobe显示的音频流是AAC,这显然不是我的意图。所以我在添加音频流时一定是做错了什么。你知道我该怎么纠正吗 这是我添加音频流的代码: void add_audio_stream() { CodecID codec_id = CODEC_ID_PCM_S16LE; AVStream *p_ast = av_new_stream

我正在尝试使用ffmpeg将视频(H.264)和音频(PCM_S16LE,无压缩)多路复用到MPEG传输流中。视频显示很好。但是,音频流不会播放。ffprobe显示的音频流是AAC,这显然不是我的意图。所以我在添加音频流时一定是做错了什么。你知道我该怎么纠正吗

这是我添加音频流的代码:

void add_audio_stream()
{

    CodecID codec_id = CODEC_ID_PCM_S16LE;

    AVStream *p_ast = av_new_stream(fc, 1);

    if (!p_ast) {
        fprintf(stderr, "Could not alloc audio stream\n");
        exit(1);
    }

    ai = p_ast->index;

    AVCodecContext *pcc = p_ast->codec;
    avcodec_get_context_defaults2( pcc, AVMEDIA_TYPE_AUDIO );

    pcc->codec_type = AVMEDIA_TYPE_AUDIO;
    pcc->codec_id = codec_id;
    pcc->sample_fmt = AV_SAMPLE_FMT_S16;
    //pcc->bit_rate = 44100*16*2;
    pcc->bit_rate = 0;
    pcc->sample_rate = 44100;
    pcc->channels = 2;
    pcc->time_base = (AVRational){1, 44100};


    // some formats want stream headers to be separate
    if (fc->oformat->flags & AVFMT_GLOBALHEADER)
    {
        printf(" **** 1 ****\n");
        pcc->flags |= CODEC_FLAG_GLOBAL_HEADER;
    }
    else
        printf(" **** 2 ****\n");


    AVCodec *codec;

    /* find the audio encoder */
    codec = avcodec_find_encoder(pcc->codec_id);
    if (!codec) {
        fprintf(stderr, "codec not found\n");
        exit(1);
    }


    /* open it */
    if (avcodec_open(pcc, codec) < 0) 
    {
        fprintf(stderr, "could not open codec\n");
        exit(1);
    }
}

我想我怀疑MEPG2 TS是否允许PCM音频。它可以占用MPI、MP2或AAC。AAC更多地被视为一种默认选择,而不是身份识别

此外,与视频不同,音频标题的描述性不强。i、 e.没有开始代码和其他东西,所以除了PES头,通常没有办法找出它是什么类型的音频

如果可能,对音频进行编码


尝试使用Gspot应用程序进行交叉检查。

不久前,我也玩过它。我发现: -蓝光仅支持48000采样率 -我总是用BIG-ENDIAN而不是LITTLE-ENDIAN


我认为ffmpeg将为mpeg2\u ts使用蓝光设置。

看起来MPEG-ts支持AES3格式的PCM音频作为专用数据,如所述


目前,ffmpeg中有一个
s302m
编码器/解码器,可以让您轻松实现目标。

感谢您的洞察力,迪潘!然而,我遇到的许多参考文献似乎表明,MPEG-2 TS支持线性未压缩PCM。显然,许多电视台正在使用原始PCM(我知道在这个过程中带宽被浪费了,但无论如何)。例如,()建议在蓝光场景中使用原始PCM。更多的例子:我想我遗漏了一些小细节。我今天要打一架。如果你发现一个错误,请随意提出建议。THXAm我应该设置框架尺寸吗?为什么是零?对不起,对于上面的评论,我的意思是:在我使用avcodec_open2(pcc,codec,NULL)打开编解码器后,pcc->frame_size是1。为什么框架大小等于1个样本?这没有任何意义。
ffprobe version N-32405-g6337de9, Copyright (c) 2007-2011 the FFmpeg developers
  built on Sep  8 2011 11:20:12 with gcc 4.4.3
  configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-x11grab --enable-libmp3lame
  libavutil    51. 16. 0 / 51. 16. 0
  libavcodec   53. 13. 0 / 53. 13. 0
  libavformat  53. 12. 0 / 53. 12. 0
  libavdevice  53.  3. 0 / 53.  3. 0
  libavfilter   2. 39. 0 /  2. 39. 0
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0
[mpegts @ 0xa96daa0] Continuity Check Failed
[mpegts @ 0xa96daa0] Continuity Check Failed
[aac @ 0xa974da0] channel element 0.1 is not allocated
[aac @ 0xa974da0] More than one AAC RDB per ADTS frame is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.

.
.
lot of gobbly-gook about missing AAC parameters . . . 
.
.

[aac @ 0xa974da0] More than one AAC RDB per ADTS frame is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[aac @ 0xa974da0] Error decoding AAC frame header.
[mpegts @ 0xa96daa0] max_analyze_duration 5000000 reached at 5429789
[mpegts @ 0xa96daa0] Continuity Check Failed
[mpegts @ 0xa96daa0] Continuity Check Failed

Input #0, mpegts, from 'test_audio_video.mts':
  Duration: 00:00:40.35, start: 0.010000, bitrate: 1907 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
Stream #0.0[0x100]: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p, 640x480, 30 fps, 30 tbr, 90k tbn, 60 tbc

Stream #0.1[0x101]: Audio: aac ([6][0][0][0] / 0x0006), 96000 Hz, 4.0, s16, 9 kb/s