AAC 還原 pcm/WAV, faad 的已知問題填坑

年假在家研究一了一下流媒體,之前客戶需求要把mp4轉成h264+pcm 串流,紀錄一下

前言

libfaac 相信轉過aac格式的人都知道。他有一個對應的庫:libfaad,可用於將aac轉為pcm,windows , linux , macOS 都有offcial release,其他os 可能要交叉編譯就是了。

libfaac & libfaad 官方頁面.

WAV 檔實際上就是 wav header (72 byte)+ pcm source,方便播放&debug 就faad decode pcm前面加上了

詳細介紹wav header.

FAAD (libfaad)的已知錯誤

非常坑爹
除非從原碼階段自行編譯,否則AAC mono一律會變成stereo,網路上已有先見詳述原因與解法

原碼

Makefile 要怎樣include faad

CC = gcc
LIB= -lfaad
INC = neaacdec.h faad.h
SRC =
SIMPLE_MAIN = aac_decode.c
MAIN = aac_decode.c
TARGET = aac_decoder
LDFLAG = -pthread
CFLAG = $(SRC) $(MAIN) $(INC)  $(LDFLAG) $(LIB) 

all:
	$(CC) $(CFLAG) -o $(TARGET) 
	mv $(TARGET) ./bin
	@echo "make all"

clean:
	rm -f bin/*
	@echo "clean all"

faad example

/*
 * Example file that decodes raw AAC data from stdin,
 * and outputs the PCM audio data to stdout.
 */

#include <neaacdec.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

struct WavFileHeader
{
   
    char        id[4];          // should always contain "RIFF"
    int     totallength;    // total file length minus 8
    char        wavefmt[8];     // should be "WAVEfmt "
    int     format;         // 16 for PCM format
    short     pcm;            // 1 for PCM format
    short     channels;       // channels
    int     frequency;      // sampling frequency
    int     bytes_per_second;
    short     bytes_by_capture;
    short     bits_per_sample;
    char        data[4];        // should always contain "data"
    int     bytes_in_data;
};
void write_wav_header(FILE* file, int totalsamcnt_per_channel, int samplerate, int channels){
   
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值