1、文件功能:将输入流解封装,分解为H264格式的视频流和AAC格式的音频流,分别保存在文件中;
2、音频流(AAC格式)文件可以用VLC播放器播放,视频流(H264)文件可用H264Visa播放(使用VLC播放器不能播放,原因待查);
3、此程序由 雷霄骅先生 所写的程序改编而来,在此致以深深的无法用语言表达的谢意。愿逝者安息,生者前行!!
4、本人邮箱:zxwphysics@126.com。
// 雷霄骅原程序的地址
http://blog.csdn.net/leixiaohua1020/article/details/39802819
#include "stdafx.h"
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
};
#pragma comment(lib, "avcodec.lib")
#pragma comment(lib, "avformat.lib")
/* 雷霄骅
FIX: H.264 in some container format (FLV, MP4, MKV etc.) need "h264_mp4toannexb" bitstream filter (BSF)
* Add SPS,PPS in front of IDR frame
* Add start code ("0,0,0,1") in front of NALU
H.264 in some container (MPEG2TS) don't need this BSF.
*/
//'1': Use H.264 Bitstream Filter
#define USE_H264BSF 1
int main(int argc, char* argv[])
{
// Variables Definition
AVFormatContext* ifmt_ctx = NULL; // Format context of input stream
const char* input_filepath = NULL; // File path of input stream
int idx_audio = -1; // index of input audio stream
int idx_video = -1; // index of input video stream
AVStream* pAudioStream = NULL; // Stream structure of input audio stream
AVCodecContext* pAudioCodecCtx = NULL; // main external API structure of input audio stream
AVCodec* pAudioCodec = NULL; // AVCodec structure of input audio stream
AVStream* pVideoStream = NULL; // ... of input video stream
AVCodecContext* pVideoCodecCtx = NULL; //
AVCodec* pVideoCodec = NULL; //
AVFormatContext* ofmt_ctx_audio = NULL; // Format context of output audio stream
AVStream* pAudioStream_out = NULL; // Output audio stream (AAC)
const char* output_filepath_audio = NULL; // File path of output audio stream
AVFormatContext* ofmt_ctx_video = NULL; // ... of output video stream
AVStream* pVideoStream_out = NULL; // H264
const char* output_filepath_video = NULL; //