9 个解决方案
#1
看FFply的开源代码
#2
avi的 Encode部分
#3
PCM是raw数据,没有声道数采样率这些信息,应该先加上文件头,变成WAV格式,再写入吧。
#4
这个贴不能沉啊,顶起来。。。
#5
我也是使用h264和pcm进行封装为avi,现在视频成功了,封装音频失败,我是直接对音频数据(未加3楼所说的wav头)
但是我看了其他一些资料,好像不需要加类似wav头,就可以实现
3楼 给些建议嘛
但是我看了其他一些资料,好像不需要加类似wav头,就可以实现
3楼 给些建议嘛
#6
if(SaveAvi.nAudioFrames==0)
{
//AVIFileOpen(&SaveAvi.m_pAviFile,SaveAvi.FileSaveAvi,OF_WRITE | OF_CREATE,NULL);
memset(&SaveAvi.m_AudioStreamInfo, 0, sizeof(SaveAvi.m_AudioStreamInfo));
SaveAvi.m_AudioStreamInfo.fccType = streamtypeAUDIO;
SaveAvi.m_AudioStreamInfo.dwScale = 1; //声道数
SaveAvi.m_AudioStreamInfo.dwRate = 8000; //Hz
SaveAvi.m_AudioStreamInfo.dwSuggestedBufferSize =0;// len+32;
SaveAvi.m_AudioStreamInfo.dwSampleSize = 1;
AVIFileCreateStream(SaveAvi.m_pAviFile,&SaveAvi.m_pAudioStreams,(AVISTREAMINFO *)&SaveAvi.m_AudioStreamInfo);
}
//音频格式设置
WAVEFORMAT waveFormat;
memset(&waveFormat,0,sizeof(waveFormat));
if(0==compress_style)
waveFormat.wFormatTag = WAVE_FORMAT_PCM;
else
waveFormat.wFormatTag = WAVE_FORMAT_ADPCM;
waveFormat.nChannels = 1;
waveFormat.nSamplesPerSec = 8000;
//waveFormat.wBitsPerSample = 16;
waveFormat.nBlockAlign = /*waveFormat.wBitsPerSample*/ 16* waveFormat.nChannels / 8;
waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec*waveFormat.nBlockAlign;
//设置音频格式
AVIStreamSetFormat(SaveAvi.m_pAudioStreams,SaveAvi.nAudioFrames,&waveFormat,sizeof(waveFormat));
//写数据
InitializeCriticalSection(&g_s);
EnterCriticalSection(&g_s);
AVIStreamWrite(SaveAvi.m_pAudioStreams,SaveAvi.nAudioFrames ,1,(LPBYTE)audio,
len+32 ,AVIIF_KEYFRAME,NULL,NULL);
LeaveCriticalSection(&g_s);
DeleteCriticalSection(&g_s);
SaveAvi.nAudioFrames++;
}
其中SaveAvi.m_AudioStreamInfo.dwSuggestedBufferSize=0//csdn说的,在不确定的情况下,设置为0
AVIStreamWrite(SaveAvi.m_pAudioStreams,SaveAvi.nAudioFrames ,1,(LPBYTE)audio,
len ,AVIIF_KEYFRAME,NULL,NULL);
//len是从网络上接收到的音频(pcm)大小
路过的高手帮我看看是怎么回事啊
{
//AVIFileOpen(&SaveAvi.m_pAviFile,SaveAvi.FileSaveAvi,OF_WRITE | OF_CREATE,NULL);
memset(&SaveAvi.m_AudioStreamInfo, 0, sizeof(SaveAvi.m_AudioStreamInfo));
SaveAvi.m_AudioStreamInfo.fccType = streamtypeAUDIO;
SaveAvi.m_AudioStreamInfo.dwScale = 1; //声道数
SaveAvi.m_AudioStreamInfo.dwRate = 8000; //Hz
SaveAvi.m_AudioStreamInfo.dwSuggestedBufferSize =0;// len+32;
SaveAvi.m_AudioStreamInfo.dwSampleSize = 1;
AVIFileCreateStream(SaveAvi.m_pAviFile,&SaveAvi.m_pAudioStreams,(AVISTREAMINFO *)&SaveAvi.m_AudioStreamInfo);
}
//音频格式设置
WAVEFORMAT waveFormat;
memset(&waveFormat,0,sizeof(waveFormat));
if(0==compress_style)
waveFormat.wFormatTag = WAVE_FORMAT_PCM;
else
waveFormat.wFormatTag = WAVE_FORMAT_ADPCM;
waveFormat.nChannels = 1;
waveFormat.nSamplesPerSec = 8000;
//waveFormat.wBitsPerSample = 16;
waveFormat.nBlockAlign = /*waveFormat.wBitsPerSample*/ 16* waveFormat.nChannels / 8;
waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec*waveFormat.nBlockAlign;
//设置音频格式
AVIStreamSetFormat(SaveAvi.m_pAudioStreams,SaveAvi.nAudioFrames,&waveFormat,sizeof(waveFormat));
//写数据
InitializeCriticalSection(&g_s);
EnterCriticalSection(&g_s);
AVIStreamWrite(SaveAvi.m_pAudioStreams,SaveAvi.nAudioFrames ,1,(LPBYTE)audio,
len+32 ,AVIIF_KEYFRAME,NULL,NULL);
LeaveCriticalSection(&g_s);
DeleteCriticalSection(&g_s);
SaveAvi.nAudioFrames++;
}
其中SaveAvi.m_AudioStreamInfo.dwSuggestedBufferSize=0//csdn说的,在不确定的情况下,设置为0
AVIStreamWrite(SaveAvi.m_pAudioStreams,SaveAvi.nAudioFrames ,1,(LPBYTE)audio,
len ,AVIIF_KEYFRAME,NULL,NULL);
//len是从网络上接收到的音频(pcm)大小
路过的高手帮我看看是怎么回事啊
#7
lz,这个问题解决了么?
#8
lz,这个问题解决了吗?能不能共享下,395759141@qq.com ,先谢谢了!
#9
楼主文件解决了吗?能给点指导吗?我现在也是在做ipcam获取h264和pcm,但是不知道怎么封装成文件。
#1
看FFply的开源代码
#2
avi的 Encode部分
#3
PCM是raw数据,没有声道数采样率这些信息,应该先加上文件头,变成WAV格式,再写入吧。
#4
这个贴不能沉啊,顶起来。。。
#5
我也是使用h264和pcm进行封装为avi,现在视频成功了,封装音频失败,我是直接对音频数据(未加3楼所说的wav头)
但是我看了其他一些资料,好像不需要加类似wav头,就可以实现
3楼 给些建议嘛
但是我看了其他一些资料,好像不需要加类似wav头,就可以实现
3楼 给些建议嘛
#6
if(SaveAvi.nAudioFrames==0)
{
//AVIFileOpen(&SaveAvi.m_pAviFile,SaveAvi.FileSaveAvi,OF_WRITE | OF_CREATE,NULL);
memset(&SaveAvi.m_AudioStreamInfo, 0, sizeof(SaveAvi.m_AudioStreamInfo));
SaveAvi.m_AudioStreamInfo.fccType = streamtypeAUDIO;
SaveAvi.m_AudioStreamInfo.dwScale = 1; //声道数
SaveAvi.m_AudioStreamInfo.dwRate = 8000; //Hz
SaveAvi.m_AudioStreamInfo.dwSuggestedBufferSize =0;// len+32;
SaveAvi.m_AudioStreamInfo.dwSampleSize = 1;
AVIFileCreateStream(SaveAvi.m_pAviFile,&SaveAvi.m_pAudioStreams,(AVISTREAMINFO *)&SaveAvi.m_AudioStreamInfo);
}
//音频格式设置
WAVEFORMAT waveFormat;
memset(&waveFormat,0,sizeof(waveFormat));
if(0==compress_style)
waveFormat.wFormatTag = WAVE_FORMAT_PCM;
else
waveFormat.wFormatTag = WAVE_FORMAT_ADPCM;
waveFormat.nChannels = 1;
waveFormat.nSamplesPerSec = 8000;
//waveFormat.wBitsPerSample = 16;
waveFormat.nBlockAlign = /*waveFormat.wBitsPerSample*/ 16* waveFormat.nChannels / 8;
waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec*waveFormat.nBlockAlign;
//设置音频格式
AVIStreamSetFormat(SaveAvi.m_pAudioStreams,SaveAvi.nAudioFrames,&waveFormat,sizeof(waveFormat));
//写数据
InitializeCriticalSection(&g_s);
EnterCriticalSection(&g_s);
AVIStreamWrite(SaveAvi.m_pAudioStreams,SaveAvi.nAudioFrames ,1,(LPBYTE)audio,
len+32 ,AVIIF_KEYFRAME,NULL,NULL);
LeaveCriticalSection(&g_s);
DeleteCriticalSection(&g_s);
SaveAvi.nAudioFrames++;
}
其中SaveAvi.m_AudioStreamInfo.dwSuggestedBufferSize=0//csdn说的,在不确定的情况下,设置为0
AVIStreamWrite(SaveAvi.m_pAudioStreams,SaveAvi.nAudioFrames ,1,(LPBYTE)audio,
len ,AVIIF_KEYFRAME,NULL,NULL);
//len是从网络上接收到的音频(pcm)大小
路过的高手帮我看看是怎么回事啊
{
//AVIFileOpen(&SaveAvi.m_pAviFile,SaveAvi.FileSaveAvi,OF_WRITE | OF_CREATE,NULL);
memset(&SaveAvi.m_AudioStreamInfo, 0, sizeof(SaveAvi.m_AudioStreamInfo));
SaveAvi.m_AudioStreamInfo.fccType = streamtypeAUDIO;
SaveAvi.m_AudioStreamInfo.dwScale = 1; //声道数
SaveAvi.m_AudioStreamInfo.dwRate = 8000; //Hz
SaveAvi.m_AudioStreamInfo.dwSuggestedBufferSize =0;// len+32;
SaveAvi.m_AudioStreamInfo.dwSampleSize = 1;
AVIFileCreateStream(SaveAvi.m_pAviFile,&SaveAvi.m_pAudioStreams,(AVISTREAMINFO *)&SaveAvi.m_AudioStreamInfo);
}
//音频格式设置
WAVEFORMAT waveFormat;
memset(&waveFormat,0,sizeof(waveFormat));
if(0==compress_style)
waveFormat.wFormatTag = WAVE_FORMAT_PCM;
else
waveFormat.wFormatTag = WAVE_FORMAT_ADPCM;
waveFormat.nChannels = 1;
waveFormat.nSamplesPerSec = 8000;
//waveFormat.wBitsPerSample = 16;
waveFormat.nBlockAlign = /*waveFormat.wBitsPerSample*/ 16* waveFormat.nChannels / 8;
waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec*waveFormat.nBlockAlign;
//设置音频格式
AVIStreamSetFormat(SaveAvi.m_pAudioStreams,SaveAvi.nAudioFrames,&waveFormat,sizeof(waveFormat));
//写数据
InitializeCriticalSection(&g_s);
EnterCriticalSection(&g_s);
AVIStreamWrite(SaveAvi.m_pAudioStreams,SaveAvi.nAudioFrames ,1,(LPBYTE)audio,
len+32 ,AVIIF_KEYFRAME,NULL,NULL);
LeaveCriticalSection(&g_s);
DeleteCriticalSection(&g_s);
SaveAvi.nAudioFrames++;
}
其中SaveAvi.m_AudioStreamInfo.dwSuggestedBufferSize=0//csdn说的,在不确定的情况下,设置为0
AVIStreamWrite(SaveAvi.m_pAudioStreams,SaveAvi.nAudioFrames ,1,(LPBYTE)audio,
len ,AVIIF_KEYFRAME,NULL,NULL);
//len是从网络上接收到的音频(pcm)大小
路过的高手帮我看看是怎么回事啊
#7
lz,这个问题解决了么?
#8
lz,这个问题解决了吗?能不能共享下,395759141@qq.com ,先谢谢了!
#9
楼主文件解决了吗?能给点指导吗?我现在也是在做ipcam获取h264和pcm,但是不知道怎么封装成文件。