Commit c1f2c8d5 by lenz su

编解码优化

parent 2d31d743
<?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-07T23:03:46. --> <!-- Written by QtCreator 4.10.2, 2020-01-08T10:10:37. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
...@@ -317,7 +317,7 @@ ...@@ -317,7 +317,7 @@
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value> <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory"></value> <value type="QString" key="RunConfiguration.WorkingDirectory"></value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">C:/Users/sulin/Documents/QT_PAIR_RECEIVE/bin32</value> <value type="QString" key="RunConfiguration.WorkingDirectory.default"></value>
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value> <value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap> </valuemap>
......
...@@ -297,6 +297,7 @@ bool VideoDecoder::openSoftDecoder(const AVCodecID &codec_id) ...@@ -297,6 +297,7 @@ bool VideoDecoder::openSoftDecoder(const AVCodecID &codec_id)
pCodecCtx->thread_count = 8; pCodecCtx->thread_count = 8;
pCodecCtx->pix_fmt = AV_PIX_FMT_YUV420P; pCodecCtx->pix_fmt = AV_PIX_FMT_YUV420P;
pCodecCtx->framerate.den = 30;//zcq pCodecCtx->framerate.den = 30;//zcq
pCodecCtx->flags |= AV_CODEC_FLAG_LOW_DELAY;
///打开解码器 ///打开解码器
if (avcodec_open2(pCodecCtx, pCodec, nullptr) < 0) if (avcodec_open2(pCodecCtx, pCodec, nullptr) < 0)
...@@ -351,7 +352,6 @@ bool VideoDecoder::decode(uint8_t *inputbuf, int frame_size, uint8_t *&outBuf, i ...@@ -351,7 +352,6 @@ bool VideoDecoder::decode(uint8_t *inputbuf, int frame_size, uint8_t *&outBuf, i
int resSend=avcodec_send_packet(pCodecCtx, &pkt); int resSend=avcodec_send_packet(pCodecCtx, &pkt);
if (resSend!= 0) if (resSend!= 0)
{ {
cout<<"fangle fangle send "<<resSend<<" "<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
av_packet_unref(&pkt); av_packet_unref(&pkt);
return 0; return 0;
} }
...@@ -367,7 +367,6 @@ bool VideoDecoder::decode(uint8_t *inputbuf, int frame_size, uint8_t *&outBuf, i ...@@ -367,7 +367,6 @@ bool VideoDecoder::decode(uint8_t *inputbuf, int frame_size, uint8_t *&outBuf, i
break; break;
} }
cout<<"fangle fangle receive"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
//前面初始化解码器的时候 并没有设置视频的宽高信息, //前面初始化解码器的时候 并没有设置视频的宽高信息,
//因为h264的每一帧数据都带有编码的信息,当然也包括这些宽高信息了,因此解码完之后,便可以知道视频的宽高是多少 //因为h264的每一帧数据都带有编码的信息,当然也包括这些宽高信息了,因此解码完之后,便可以知道视频的宽高是多少
//这就是为什么 初始化编码器的时候 需要初始化高度,而初始化解码器却不需要。 //这就是为什么 初始化编码器的时候 需要初始化高度,而初始化解码器却不需要。
......
...@@ -37,9 +37,6 @@ T_NALU *NALUParsing::getNextFrame() ...@@ -37,9 +37,6 @@ T_NALU *NALUParsing::getNextFrame()
{ {
QDateTime current_date_time =QDateTime::currentDateTime();
/*根据h264文件的特性 逐个字节搜索 直到遇到h264的帧头 视为获取到了完整的一帧h264视频数据*/ /*根据h264文件的特性 逐个字节搜索 直到遇到h264的帧头 视为获取到了完整的一帧h264视频数据*/
/// 关于起始码startcode的两种形式:3字节的0x000001和4字节的0x00000001 /// 关于起始码startcode的两种形式:3字节的0x000001和4字节的0x00000001
...@@ -68,8 +65,7 @@ T_NALU *NALUParsing::getNextFrame() ...@@ -68,8 +65,7 @@ T_NALU *NALUParsing::getNextFrame()
lock=false; lock=false;
return NULL; return NULL;
} }
cout<<"get frame head"<<current_date_time.toString("yyyyMMddhhmmsszzz").toStdString()<<endl; ///然后查找下一个起始码查找第一个起始码
///然后查找下一个起始码查找第一个起始码
int pos_2 = pos + StartCode; //记录当前处理的数据偏移量 int pos_2 = pos + StartCode; //记录当前处理的数据偏移量
int StartCode_2 = 0; int StartCode_2 = 0;
...@@ -90,10 +86,8 @@ T_NALU *NALUParsing::getNextFrame() ...@@ -90,10 +86,8 @@ T_NALU *NALUParsing::getNextFrame()
lock=false; lock=false;
return NULL; return NULL;
} }
cout<<"fangle fangle "<<endl;
/// 现在 pos和pos_2之间的数据就是一帧数据了 /// 现在 pos和pos_2之间的数据就是一帧数据了
/// 把他取出来 /// 把他取出来
cout<<"get frame foot"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
///由于传递给ffmpeg解码的数据 需要带上起始码 因此这里的nalu带上了起始码 ///由于传递给ffmpeg解码的数据 需要带上起始码 因此这里的nalu带上了起始码
Buf = mH264Buffer + pos; //这帧数据的起始数据(包含起始码) Buf = mH264Buffer + pos; //这帧数据的起始数据(包含起始码)
...@@ -118,9 +112,6 @@ T_NALU *NALUParsing::getNextFrame() ...@@ -118,9 +112,6 @@ T_NALU *NALUParsing::getNextFrame()
memmove(mH264Buffer, mH264Buffer + pos_2, leftSize); memmove(mH264Buffer, mH264Buffer + pos_2, leftSize);
mBufferSize = leftSize; mBufferSize = leftSize;
lock=false; lock=false;
current_date_time =QDateTime::currentDateTime();
cout<<"start get frame end"<<current_date_time.toString("yyyyMMddhhmmsszzz").toStdString()<<endl;
return nalu; return nalu;
} }
......
...@@ -28,7 +28,7 @@ void Sleep(long mSeconds) ...@@ -28,7 +28,7 @@ void Sleep(long mSeconds)
#endif #endif
static FILE * fpOut = fopen("haha", "wb"); //static FILE * fpOut = fopen("haha", "wb");
void ReadVideoFileThread::run() void ReadVideoFileThread::run()
{ {
mVideoDecoder->openDecoder(id); mVideoDecoder->openDecoder(id);
...@@ -46,28 +46,29 @@ void ReadVideoFileThread::run() ...@@ -46,28 +46,29 @@ void ReadVideoFileThread::run()
msleep(5); msleep(5);
continue; continue;
} }
// fwrite(nalu->nalu.h264Nalu.buf, 1, nalu->nalu.h264Nalu.len, fpOut); cout<<"delay test get frame"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
cout<<"time thread get frame:"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
uint8_t *bufferYUV = nullptr; uint8_t *bufferYUV = nullptr;
int width; int width;
int height; int height;
cout<<"delay test decode"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
mVideoDecoder->decode(nalu->nalu.h264Nalu.buf, nalu->nalu.h264Nalu.len, bufferYUV, width, height); mVideoDecoder->decode(nalu->nalu.h264Nalu.buf, nalu->nalu.h264Nalu.len, bufferYUV, width, height);
if (bufferYUV != nullptr) if (bufferYUV != nullptr)
{ {
//然后传给主线程显示 //然后传给主线程显示
cout<<"time thread get do display:"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
cout<<"delay test display"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
doDisplayVideo(bufferYUV, width, height, frameNum++); doDisplayVideo(bufferYUV, width, height, frameNum++);
} }
NALUParsing::FreeNALU(nalu); NALUParsing::FreeNALU(nalu);
} }
fflush(fpOut); // fflush(fpOut);
fclose(fpOut); // fclose(fpOut);
mVideoDecoder->closeDecoder(); mVideoDecoder->closeDecoder();
} }
......
...@@ -413,6 +413,7 @@ void hid_thread::run() ...@@ -413,6 +413,7 @@ void hid_thread::run()
} }
int res =-1; int res =-1;
cout<<"delay test start receive"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
while(true) { while(true) {
memset(buffer, 0, 2048); memset(buffer, 0, 2048);
...@@ -512,9 +513,8 @@ void hid_thread::run() ...@@ -512,9 +513,8 @@ void hid_thread::run()
qDebug("delay 1 "); qDebug("delay 1 ");
msleep(2); msleep(2);
} }
cout<<"time send decode:"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
int nCount = pNaluParsing->inputH264Data(pUsbFram1->buff,pUsbFram1->length); int nCount = pNaluParsing->inputH264Data(pUsbFram1->buff,pUsbFram1->length);
qDebug("fram id:%d %d ", pUsbFram1->id, pUsbFram1->length);
frameId=pUsbFram1->id; frameId=pUsbFram1->id;
} }
...@@ -523,9 +523,8 @@ void hid_thread::run() ...@@ -523,9 +523,8 @@ void hid_thread::run()
qDebug("delay 2 "); qDebug("delay 2 ");
msleep(2); msleep(2);
} }
cout<<"time send decode:"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
int nCount = pNaluParsing->inputH264Data(pUsbFram2->buff,pUsbFram2->length); int nCount = pNaluParsing->inputH264Data(pUsbFram2->buff,pUsbFram2->length);
qDebug("fram id:%d %d ", pUsbFram2->id, pUsbFram2->length);
frameId=pUsbFram2->id; frameId=pUsbFram2->id;
} }
......
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -233,7 +233,6 @@ void ShowVideoWidget::inputOneFrame(VideoFramePtr videoFrame) ...@@ -233,7 +233,6 @@ void ShowVideoWidget::inputOneFrame(VideoFramePtr videoFrame)
{ {
int width = videoFrame.get()->width(); int width = videoFrame.get()->width();
int height = videoFrame.get()->height(); int height = videoFrame.get()->height();
qDebug("%s width:%d height:%d\n", __FUNCTION__, width, height);
if (m_nVideoW <= 0 || m_nVideoH <= 0 || m_nVideoW != width || m_nVideoH != height) if (m_nVideoW <= 0 || m_nVideoH <= 0 || m_nVideoW != width || m_nVideoH != height)
{ {
......
...@@ -100,7 +100,6 @@ void MainWindow::slotBtnClick(bool isChecked) ...@@ -100,7 +100,6 @@ void MainWindow::slotBtnClick(bool isChecked)
hidThread->start(); hidThread->start();
/*if (isChecked) { /*if (isChecked) {
qDebug("start decode!"); qDebug("start decode!");
mReadVideoFileThread->start(); mReadVideoFileThread->start();
...@@ -116,7 +115,6 @@ void MainWindow::onDisplayVideo(std::shared_ptr<VideoFrame> videoFrame, int fram ...@@ -116,7 +115,6 @@ void MainWindow::onDisplayVideo(std::shared_ptr<VideoFrame> videoFrame, int fram
if(hidThread->isPlay==false){ if(hidThread->isPlay==false){
return; return;
} }
cout<<"time send play:"<<QDateTime::currentDateTime().toString("hhmmsszzz").toStdString()<<endl;
ui->label_frameNum->setText(QString("%1").arg(frameNum)); ui->label_frameNum->setText(QString("%1").arg(frameNum));
ui->widget_videoPlayer->inputOneFrame(videoFrame); ui->widget_videoPlayer->inputOneFrame(videoFrame);
} }
......
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