背景:在播放在线视频的时候声音播放不正常,通过生成pipeline dot文件分析,看到audio部分aac raw格式,所以初步思路是dump es流后,分析gstreamer pipeline播放,然后发现问题。(dump数据后,pipeline都是在ubuntu上运行的)
首先需要dump数据,下面是一个简单例子的代码,也可以用C函数写:
GstMapInfo map;
std::ofstream outfile;
gst_buffer_map (buffer.get(), &map, GST_MAP_READ);
outfile.open("/data/audio.data", std::ios::out|std::ios::binary|std::ios::app);
outfile.write((const char*)map.data, map.size);
outfile.close();
gst_buffer_unmap(buffer.get(), &map);
dump出数据之后,对dump数据播放,audio.data是直接从http source里面dump出来的数据,所以以为是裸数据,尝试一些参数进行播放,因为通过dot文件,已经知道caps,使用caps"audio/mpeg,rate=44100,channels=2"
,后面跟aacparse,avdec_aac_fixed:
gst-launch-1.0 filesrc location=/home/hui/media-files/debug/audio.data \
!"audio/mpeg,rate=44100,channels=2" ! aacparse! avdec_aac_fixed ! pulsesink
协商失败,所以加上audioconvert ! audioresample
gst-launch-1.0 filesrc location=/home/hui/media-files/debug/audio.data \
!"audio/mpeg,rate=44100,channels=2" ! aacparse! avdec_aac_fixed ! audioconvert ! audioresample ! pulsesink
还是不行,通过mediainfo可以看到,是mp4类型的数据包,所以加上qtdemux就可以解析,"audio/mpeg,rate=44100,channels=2"
就不需要了:
gst-launch-1.0 filesrc location=/home/hui/disk4t/media-test/media-files/debug/audio.data \
! qtdemux ! aacparse! avdec_aac_fixed ! audioconvert ! audioresample ! pulsesink
播放声音有杂音,变音,感觉是解码不对,通过dot文件可以看到,本身是mpeg raw格式,所以又增加adts
的caps audio/mpeg,stream-format=adts
,加上强制caps后播放正常:
gst-launch-1.0 filesrc location=/home/hui/media-files/debug/audio.data \
! qtdemux ! aacparse ! audio/mpeg,stream-format=adts ! avdec_aac_fixed ! audioconvert ! audioresample ! pulsesink
所以问题定位:avdec_aac_fixed对aac raw格式的处理不好,通过增加adts caps就可以解决问题:
后面的sink使用playsink代替pulsesink也是可以的:
gst-launch-1.0 filesrc location=audio.data \
! qtdemux ! "audio/mpeg,rate=44100,channels=2" \
! aacparse ! audio/mpeg,stream-format=adts ! avdec_aac ! playsink
参考知识:多种音频的格式以及其解码流程