⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ffmpegext.cpp

📁 包裝ffmpeg中的codecs成為DirectShow中的transform filter
💻 CPP
字号:
//#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
//#include <avcodec.h>
//#include <avformat.h>
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
}

AVCodecContext *pCodecCtx;
AVCodec *pCodec;

int ffmpegDecode(unsigned char *input, int inLen, unsigned char *buffer)
{
	int bytesDecoded;
	int frameFinished;
	//
    AVFrame *pFrame = avcodec_alloc_frame();
	AVFrame *pFrameRGB = avcodec_alloc_frame();

	int numBytes = avpicture_get_size(PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
	avpicture_fill((AVPicture *)pFrame, buffer, PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
	avpicture_fill((AVPicture *)pFrameRGB, (uint8_t *) buffer, PIX_FMT_RGBA32, pCodecCtx->width, pCodecCtx->height);
	//
	bytesDecoded = avcodec_decode_video(pCodecCtx, pFrame, &frameFinished, (uint8_t *) input, inLen);
	//img_convert((AVPicture *)pFrameRGB, PIX_FMT_RGBA32, (AVPicture*)pFrame,  pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height);
	
	struct SwsContext *img_convert_ctx;
	img_convert_ctx = sws_getContext(320,240,PIX_FMT_YUV420P,
									320,240,PIX_FMT_RGBA32, SWS_BICUBIC, NULL, NULL, NULL);

	sws_scale (img_convert_ctx, pFrame->data, pFrame->linesize,
			0, 240,pFrameRGB->data , pFrameRGB->linesize );
	sws_freeContext(img_convert_ctx);
	//
	memcpy(buffer, pFrameRGB->data[0], pCodecCtx->width*pCodecCtx->height*4);
	//
	av_free(pFrame);
	av_free(pFrameRGB);
	return bytesDecoded;
}

int ffmpegInit(void)
{
    av_register_all();
	//
	pCodecCtx = avcodec_alloc_context();
	avcodec_get_context_defaults(pCodecCtx);
	//
    pCodec=avcodec_find_decoder(CODEC_ID_FLV1);
    if(pCodec==NULL)
        return -1;
	//
    if(pCodec->capabilities & CODEC_CAP_TRUNCATED)
        pCodecCtx->flags|=CODEC_FLAG_TRUNCATED;
	//
	pCodecCtx->width = 320;
	pCodecCtx->height = 240;
    //
    if(avcodec_open(pCodecCtx, pCodec)<0)
        return -1;
	//  avcodec_close(pCodecCtx);
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -