Commit a4eb142c by lenz su

解码分辨率 帧率 编码格式 打印到excel

parent 0ba2cf40
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.10.2, 2020-01-04T16:33:07. --> <!-- Written by QtCreator 4.10.2, 2020-01-04T19:56:44. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
......
...@@ -8,7 +8,10 @@ ...@@ -8,7 +8,10 @@
#include "QDataStream" #include "QDataStream"
#include "iostream" #include "iostream"
using namespace std; using namespace std;
#include <fstream>
#include <string>
#include <QDateTime>
bool isloged=false;
VideoDecoder::VideoDecoder() VideoDecoder::VideoDecoder()
{ {
pCodec = nullptr; pCodec = nullptr;
...@@ -33,8 +36,8 @@ void VideoDecoder::initWidth(int width, int height) ...@@ -33,8 +36,8 @@ void VideoDecoder::initWidth(int width, int height)
#else #else
int yuvSize = av_image_get_buffer_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height, 1); //按1字节进行内存对齐,得到的内存大小最接近实际大小 int yuvSize = av_image_get_buffer_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height, 1); //按1字节进行内存对齐,得到的内存大小最接近实际大小
// int yuvSize = av_image_get_buffer_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height, 0); //按0字节进行内存对齐,得到的内存大小是0 // int yuvSize = av_image_get_buffer_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height, 0); //按0字节进行内存对齐,得到的内存大小是0
// int yuvSize = av_image_get_buffer_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height, 4); //按4字节进行内存对齐,得到的内存大小稍微大一些 // int yuvSize = av_image_get_buffer_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height, 4); //按4字节进行内存对齐,得到的内存大小稍微大一些
unsigned int numBytes = static_cast<unsigned int>(yuvSize); unsigned int numBytes = static_cast<unsigned int>(yuvSize);
bufferYUV = static_cast<uint8_t *>(av_malloc(numBytes * sizeof(uint8_t))); bufferYUV = static_cast<uint8_t *>(av_malloc(numBytes * sizeof(uint8_t)));
...@@ -345,20 +348,20 @@ bool VideoDecoder::decode(uint8_t *inputbuf, int frame_size, uint8_t *&outBuf, i ...@@ -345,20 +348,20 @@ bool VideoDecoder::decode(uint8_t *inputbuf, int frame_size, uint8_t *&outBuf, i
if (avcodec_send_packet(pCodecCtx, &pkt) != 0) if (avcodec_send_packet(pCodecCtx, &pkt) != 0)
{ {
fprintf(stderr, "input AVPacket to decoder failed!\n"); fprintf(stderr, "input AVPacket to decoder failed!\n");
av_packet_unref(&pkt); av_packet_unref(&pkt);
return 0; return 0;
} }
// while (0 == avcodec_receive_frame(pCodecCtx, pFrame)) // while (0 == avcodec_receive_frame(pCodecCtx, pFrame))
while(1) while(1)
{ {
int ret = avcodec_receive_frame(pCodecCtx, pFrame); int ret = avcodec_receive_frame(pCodecCtx, pFrame);
if (ret != 0) if (ret != 0)
{ {
// char buffer[1024] = {0}; // char buffer[1024] = {0};
// av_strerror(ret, buffer, 1024); // av_strerror(ret, buffer, 1024);
// fprintf(stderr, "avcodec_receive_frame = %d %s\n", ret, buffer); // fprintf(stderr, "avcodec_receive_frame = %d %s\n", ret, buffer);
break; break;
} }
...@@ -375,13 +378,24 @@ bool VideoDecoder::decode(uint8_t *inputbuf, int frame_size, uint8_t *&outBuf, i ...@@ -375,13 +378,24 @@ bool VideoDecoder::decode(uint8_t *inputbuf, int frame_size, uint8_t *&outBuf, i
//格式转换 解码之后的数据是yuv420p的 把她转换成 rgb的图像数据 //格式转换 解码之后的数据是yuv420p的 把她转换成 rgb的图像数据
sws_scale(img_convert_ctx, sws_scale(img_convert_ctx,
(uint8_t const * const *) pFrame->data, pFrame->linesize, (uint8_t const * const *) pFrame->data, pFrame->linesize,
0, pCodecCtx->height, 0, pCodecCtx->height,
pFrameYUV->data, pFrameYUV->linesize); pFrameYUV->data, pFrameYUV->linesize);
outBuf = bufferYUV; outBuf = bufferYUV;
outWidth = pCodecCtx->width; outWidth = pCodecCtx->width;
outHeight = pCodecCtx->height; outHeight = pCodecCtx->height;
if(!isloged){
ofstream oFile;
oFile.open("test.csv",ios::out|ios::trunc);
oFile<<"width"<<","<<"height"<<","<<"pix_fmt"<<","<<"fps"<<endl;
oFile<< pCodecCtx->width<<","<<pCodecCtx->height<<","<<"AV_PIX_FMT_YUV420P"<<","<<pCodecCtx->time_base.den<<endl;
oFile.close();
isloged=true;
}
} }
av_packet_unref(&pkt); av_packet_unref(&pkt);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment