Commit 3ad1fe49 by xiongziliang

支持265解码

parent 787081eb
......@@ -13,6 +13,7 @@
#include <string>
#include <memory>
#include <stdexcept>
#include "Extension/Frame.h"
#ifdef __cplusplus
extern "C" {
#endif
......@@ -27,14 +28,24 @@ using namespace std;
namespace mediakit {
class H264Decoder
{
class FFMpegDecoder{
public:
H264Decoder(void){
FFMpegDecoder(int codec_id){
auto ff_codec_id = AV_CODEC_ID_H264;
switch (codec_id){
case CodecH264:
ff_codec_id = AV_CODEC_ID_H264;
break;
case CodecH265:
ff_codec_id = AV_CODEC_ID_H265;
break;
default:
throw std::invalid_argument("不支持该编码格式");
}
avcodec_register_all();
AVCodec *pCodec = avcodec_find_decoder(AV_CODEC_ID_H264);
AVCodec *pCodec = avcodec_find_decoder(ff_codec_id);
if (!pCodec) {
throw std::runtime_error("未找到H264解码器");
throw std::runtime_error("未找到解码器");
}
m_pContext.reset(avcodec_alloc_context3(pCodec), [](AVCodecContext *pCtx) {
avcodec_close(pCtx);
......@@ -57,7 +68,7 @@ public:
throw std::runtime_error("创建帧缓存失败");
}
}
virtual ~H264Decoder(void){}
virtual ~FFMpegDecoder(void){}
bool inputVideo(unsigned char* data,unsigned int dataSize,uint32_t ui32Stamp,AVFrame **ppFrame){
AVPacket pkt;
av_init_packet(&pkt);
......
/*
/*
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
......@@ -12,13 +12,12 @@
#include "Util/util.h"
#include "Util/logger.h"
#include <iostream>
#include "Poller/EventPoller.h"
#include "Rtsp/UDPServer.h"
#include "Player/MediaPlayer.h"
#include "Util/onceToken.h"
#include "H264Decoder.h"
#include "FFMpegDecoder.h"
#include "YuvDisplayer.h"
#include "Network/sockutil.h"
#include "Extension/H265.h"
using namespace std;
using namespace toolkit;
......@@ -111,8 +110,8 @@ int main(int argc, char *argv[]) {
}
auto viedoTrack = strongPlayer->getTrack(TrackVideo);
if (!viedoTrack || viedoTrack->getCodecId() != CodecH264) {
WarnL << "没有视频或者视频不是264编码!";
if (!viedoTrack) {
WarnL << "没有视频!";
return;
}
......@@ -123,24 +122,21 @@ int main(int argc, char *argv[]) {
auto &displayer = (*storage)["displayer"];
auto &merger = (*storage)["merger"];
if(!decoder){
decoder.set<H264Decoder>();
decoder.set<FFMpegDecoder>(frame->getCodecId());
}
if(!displayer){
displayer.set<YuvDisplayer>(nullptr,url);
}
if(!merger){
merger.set<FrameMerger>();
};
}
merger.get<FrameMerger>().inputFrame(frame,[&](uint32_t dts,uint32_t pts,const Buffer::Ptr &buffer){
AVFrame *pFrame = nullptr;
bool flag = decoder.get<H264Decoder>().inputVideo((unsigned char *) buffer->data(), buffer->size(), dts, &pFrame);
bool flag = decoder.get<FFMpegDecoder>().inputVideo((unsigned char *) buffer->data(), buffer->size(), dts, &pFrame);
if (flag) {
displayer.get<YuvDisplayer>().displayYUV(pFrame);
}
});
return true;
});
}));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论