ffmpeg3版本的解码接口做了不少调整,网上找了好多 代码学习,百分九十九都会有 声明为己否决的问题
以下代码是更新了新接口 vs2015 x64下运行。
#include <iostream>
#include <stdio.h>
#include <assert.h>
#include <SDL.h>
#include <SDL_thread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#define __STDC_CONSTANT_MACROS
extern "C"{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswresample/swresample.h"
#include "libavutil/audio_fifo.h"
};
#ifdef __MINGW32__
#undef main // Prevents SDL from overriding main().
#endif
Uint32 audio_len;//每音频帧的长度
Uint8 *audio_pos;//目前接收播放位置
AVAudioFifo* audiofifo = NULL;//
int ct = 0;
DWORD start_time, end_time;
//音频回调函数 用户数据 要填充的音频缓存区头指针 缓存区大小
void fill_audio(void *udata, Uint8 *stream, int len) {
SDL_memset(stream, 0, len);//初始化缓存区
if (audio_len == 0)
return;
len = (len>audio_len ? audio_len : len);
SDL_MixAudio(stream, audio_pos, len, SDL_MIX_MAXVOLUME);
audio_pos += len;
audio_len -= len;
//SDL_Delay(20);
}
int main(int argc, char* argv[])
{
AVFormatContext *pFormatCtx;
int i, audioStream;
AVCodecContext *pCodecCtx;
AVCodec *pCodec;
AVPacket *packet;
AVFrame *pFrame;
SDL_AudioSpec wanted_spec;
int ret;
uint32_t len = 0;
int64_t in_channel_layout;
struct SwrContext *au_convert_ctx;
FILE *pFile = NULL;
//char url[] = "yinyuepenquan.mp4";
char url[] = "zzz.mp4";
start_time = GetTickCount();
//初始化
av_register_all();
avformat_network_init();
pFormatCtx = avformat_alloc_context();
if (avformat_open_input(&pFormatCtx, url, NULL, NULL) != 0) {
printf("Couldn't ope