一 代码
ffmpeg版本5.1.2,dll是:ffmpeg-5.1.2-full_build-shared。x64的。
文件、流地址对使用者来说是一样。
流地址(RTMP、HTTP-FLV、RTSP等):信令完成后,才进行音视频传输。信令包括音视频格式、参数等协商。
接流的在实际中的应用:1 展示,播放。2 给算法用,一般是需要RGB格式的。
#ifndef _DECODE_H264_H_
#define _DECODE_H264_H_
#include <string>
extern "C"
{
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
#include "libswscale/swscale.h"
#include "libavutil/avutil.h"
#include "libavutil/mathematics.h"
#include "libavutil/time.h"
#include "libavutil/pixdesc.h"
#include "libavutil/display.h"
};
#pragma comment(lib, "avformat.lib")
#pragma comment(lib, "avutil.lib")
#pragma comment(lib, "avcodec.lib")
#pragma comment(lib, "swscale.lib")
class CDecodeH264
{
public:
CDecodeH264();
~CDecodeH264();
public:
public:
int DecodeH264();
int Start();
int Close();
int DecodeH264File_Init();
int ReleaseDecode();
void H264Decode_Thread_Fun();
std::string dup_wchar_to_utf8(const wchar_t* wstr);
double get_rotation(AVStream *st);
public:
AVFormatContext* m_pInputFormatCtx = nullptr;
AVCodecContext* m_pVideoDecodeCodecCtx = nullptr;
const AVCodec* m_pCodec = nullptr;
SwsContext* m_pSwsContext = nullptr;
AVFrame* m_pFrameScale = nullptr;
AVFrame* m_pFrameYUV = nullptr;
AVPacket* m_pAVPacket = nullptr;
enum AVMediaType m_CodecType;
int m_output_pix_fmt;
int m_nVideoStream = -1;
int m_nFrameHeight = 0;
int m_nFrameWidth = 0;
int m_nFPS;
int m_nVideoSeconds;
FILE* m_pfOutYUV = nullptr;
FILE* m_pfOutYUV2 = nullptr;
};
#endif
#include "DecodeH264.h"
#include <thread>
#include <functional>
#include <codecvt>
#include <locale>
char av_error2[AV_ERROR_MAX_STRING_SIZE] = { 0 };
#define av_err2str2(errnum) av_make_error_string(av_error2, AV_ERROR_MAX_STRING_SIZE, errnum)
CDecodeH264::CDecodeH264()
{
}
CDecodeH264::~CDecodeH264()
{
ReleaseDecode();
}
std::string CDecodeH264::dup_wchar_to_utf8(const wchar_t* wstr)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
return converter.to_bytes(wstr);
}
//Side data :
//displaymatrix: rotation of -

本文详细介绍了如何使用ffmpeg的H.264解码器进行文件解码,包括初始化输入流、处理信令、视频解码、帧转换以及处理兼容性问题,如文件名编码、视频旋转和非标准分辨率的处理。
最低0.47元/天 解锁文章
2415

被折叠的 条评论
为什么被折叠?



