【问题标题】:ffmpeg audio and the iphoneffmpeg 音频和 iphone
【发布时间】:2019-06-17 19:10:49
【问题描述】:

有没有人能够让 ffmpeg 与音频队列一起工作,当我尝试创建队列时出现错误。

ret = avcodec_open(enc, codec);

if (ret < 0) {
    NSLog(@"Error: Could not open video decoder: %d", ret); 
    av_close_input_file(avfContext); 
    return; 
}


if (audio_index >= 0) { 
    AudioStreamBasicDescription
    audioFormat;

    audioFormat.mFormatID = -1;

    audioFormat.mSampleRate =
    avfContext->streams[audio_index]->codec->sample_rate;

    audioFormat.mFormatFlags = 0;

    switch (avfContext->streams[audio_index]->codec->codec_id)
    {
    case CODEC_ID_MP3: 
        audioFormat.mFormatID = kAudioFormatMPEGLayer3; 
        break;

    case CODEC_ID_AAC: 
        audioFormat.mFormatID = kAudioFormatMPEG4AAC;
        audioFormat.mFormatFlags = kMPEG4Object_AAC_Main;
        break;

    case CODEC_ID_AC3:
        audioFormat.mFormatID = kAudioFormatAC3; 
        break; 
    default: 
        break; 
    }

    if (audioFormat.mFormatID != -1) { 
        audioFormat.mBytesPerPacket = 0; 
        audioFormat.mFramesPerPacket =
        avfContext->streams[audio_index]->codec->frame_size;

        audioFormat.mBytesPerFrame = 0;

        audioFormat.mChannelsPerFrame = avfContext->streams[audio_index]->codec->channels;

        audioFormat.mBitsPerChannel = 0;

        if (ret = AudioQueueNewOutput(&audioFormat, audioQueueOutputCallback, self, NULL, NULL, 0, &audioQueue)) {

            NSLog(@"Error creating audio output queue: %d", ret);
        }

只有音频的问题,

只要我能弄清楚如何让音频队列工作,视频就是完美的。

http://web.me.com/cannonwc/Site/Photos_6.html

我虽然是 remoteio,但没有太多关于它的文档。

我将与任何帮助我使其工作的人分享完整课程的代码。

这个想法是有一个单一的视图控制器来播放任何传递给它的流媒体视频,类似于 iphone 上的 ffplay,但没有 sdl 开销。

【问题讨论】:

    标签: iphone ffmpeg audio-streaming


    【解决方案1】:

    您很可能错过了 AudioStreamBasicDescription 结构中的一些重要规范:我不了解 ffmpeg,但是指定每帧零字节和每包零字节将不起作用;) 考虑到 samplerateaudio formatchannelsbits per sample,这就是我将如何填充结构

    iAqc.mDataFormat.mSampleRate = iSampleRate;
    iAqc.mDataFormat.mFormatID = kAudioFormatLinearPCM;
    iAqc.mDataFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
    iAqc.mDataFormat.mBytesPerPacket = (iBitsPerSample >> 3) * iNumChannels;
    iAqc.mDataFormat.mFramesPerPacket = 1;
    iAqc.mDataFormat.mBytesPerFrame = (iBitsPerSample >> 3) * iNumChannels;
    iAqc.mDataFormat.mChannelsPerFrame = iNumChannels;
    iAqc.mDataFormat.mBitsPerChannel = iBitsPerSample;
    

    我假设您正在将 PCM 样本写入音频设备。 只要您知道您正在使用的音频格式,调整它应该没有问题:要记住的重要一点是所有这些东西的含义。 这里我使用每个数据包一个样本帧,因此每个数据包的字节数与每个样本帧的字节数一致。

    大多数问题的出现是因为在错误的上下文中大量使用了诸如“样本”、“样本帧”之类的词:样本帧可以被认为是音频数据的原子单元包含所有可用通道的样本是指构成样本帧的单个数据子单元。

    例如,您有 2 个通道的音频流,每个样本的分辨率为 16 位:一个样本将是 2 个字节大(16bps/8 或 16 >> 3),样本帧也将采用将通道考虑在内,因此它将是 4 字节大(2 字节 x 2 通道)。

    重要 这背后的理论不仅适用于 iPhone,也适用于一般的音频编码! 碰巧 AudioQueues 会要求您提供有关音频流的明确定义的规范,这很好,但您可能会被要求提供字节,因此将音频数据大小表示为音频帧总是好的,您始终可以转换数据大小和确定这一点。

    【讨论】:

      猜你喜欢
      • 2011-03-07
      • 1970-01-01
      • 1970-01-01
      • 2010-12-18
      • 1970-01-01
      • 2016-05-26
      • 2016-09-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多