|
@@ -156,9 +156,60 @@ int ivh264framedecode::GetJpegData(std::shared_ptr<char> & pstr_ptr,int & ndatas
|
|
|
|
|
|
}
|
|
|
|
|
|
+void ivh264framedecode::InitJPEGEncode()
|
|
|
+{
|
|
|
+ AVCodec* pCodec;
|
|
|
+ if(mbTransJpeg)
|
|
|
+ {
|
|
|
+ // pFormatCtx = avformat_alloc_context(); //分配AVFormatCtx
|
|
|
+// pStream = avformat_new_stream(pFormatCtx, 0);
|
|
|
+// if (NULL == pStream)
|
|
|
+// {
|
|
|
+// std::cout<<" JPEG Create pStream fail."<<std::endl;
|
|
|
+// return;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ pCodec = avcodec_find_encoder(AV_CODEC_ID_MJPEG); //查找编码器
|
|
|
+ if (NULL == pCodec)
|
|
|
+ {
|
|
|
+ printf("can not find jpeg codec!\n");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*设置相关信息*/
|
|
|
+ mpCodecCtxJpeg = avcodec_alloc_context3(pCodec);
|
|
|
+// mpCodecCtxJpeg = pStream->codec;
|
|
|
+ mpCodecCtxJpeg->codec_id = AV_CODEC_ID_MJPEG;
|
|
|
+ mpCodecCtxJpeg->codec_type = AVMEDIA_TYPE_VIDEO;
|
|
|
+ mpCodecCtxJpeg->pix_fmt = AV_PIX_FMT_YUVJ420P;
|
|
|
+ mpCodecCtxJpeg->width = mframewidth;
|
|
|
+ mpCodecCtxJpeg->height = mframeheight;
|
|
|
+ mpCodecCtxJpeg->time_base.num = 1;
|
|
|
+ mpCodecCtxJpeg->time_base.den = 30;
|
|
|
+ mpCodecCtxJpeg->bit_rate = 40000000;
|
|
|
+
|
|
|
+
|
|
|
+ av_opt_set_int(mpCodecCtxJpeg->priv_data, "qscale",1, 0);
|
|
|
+
|
|
|
+ if (avcodec_open2(mpCodecCtxJpeg, pCodec, NULL) < 0)
|
|
|
+ {
|
|
|
+ printf("con not open jpeg codec!\n");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
void ivh264framedecode::encodejpeg(AVFrame *frame)
|
|
|
{
|
|
|
|
|
|
+ if(mbInitJpegEncode == false)
|
|
|
+ {
|
|
|
+ InitJPEGEncode();
|
|
|
+ mbInitJpegEncode = true;
|
|
|
+ }
|
|
|
// if(mnsamplenow>mnsamplecount)
|
|
|
// {
|
|
|
// mnsamplenow = 0;
|
|
@@ -269,6 +320,11 @@ void ivh264framedecode::decode(AVCodecContext *dec_ctx, AVFrame *frame, AVPacket
|
|
|
|
|
|
mnyuvcount++;
|
|
|
|
|
|
+ if((mframeheight != frame->height)||(mframewidth != frame->width))
|
|
|
+ {
|
|
|
+ mframeheight = frame->height;
|
|
|
+ mframewidth = frame->width;
|
|
|
+ }
|
|
|
if(mbTransJpeg)
|
|
|
{
|
|
|
encodejpeg(frame);
|
|
@@ -438,52 +494,6 @@ void ivh264framedecode::threaddecode()
|
|
|
}
|
|
|
|
|
|
|
|
|
-// AVFormatContext* pFormatCtx;
|
|
|
-// AVStream* pStream;
|
|
|
- AVCodec* pCodec;
|
|
|
- if(mbTransJpeg)
|
|
|
- {
|
|
|
- // pFormatCtx = avformat_alloc_context(); //分配AVFormatCtx
|
|
|
-// pStream = avformat_new_stream(pFormatCtx, 0);
|
|
|
-// if (NULL == pStream)
|
|
|
-// {
|
|
|
-// std::cout<<" JPEG Create pStream fail."<<std::endl;
|
|
|
-// return;
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
- pCodec = avcodec_find_encoder(AV_CODEC_ID_MJPEG); //查找编码器
|
|
|
- if (NULL == pCodec)
|
|
|
- {
|
|
|
- printf("can not find jpeg codec!\n");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- /*设置相关信息*/
|
|
|
- mpCodecCtxJpeg = avcodec_alloc_context3(pCodec);
|
|
|
-// mpCodecCtxJpeg = pStream->codec;
|
|
|
- mpCodecCtxJpeg->codec_id = AV_CODEC_ID_MJPEG;
|
|
|
- mpCodecCtxJpeg->codec_type = AVMEDIA_TYPE_VIDEO;
|
|
|
- mpCodecCtxJpeg->pix_fmt = AV_PIX_FMT_YUVJ420P;
|
|
|
- mpCodecCtxJpeg->width = mframewidth;
|
|
|
- mpCodecCtxJpeg->height = mframeheight;
|
|
|
- mpCodecCtxJpeg->time_base.num = 1;
|
|
|
- mpCodecCtxJpeg->time_base.den = 30;
|
|
|
- mpCodecCtxJpeg->bit_rate = 40000000;
|
|
|
-
|
|
|
-
|
|
|
- av_opt_set_int(mpCodecCtxJpeg->priv_data, "qscale",1, 0);
|
|
|
-
|
|
|
- if (avcodec_open2(mpCodecCtxJpeg, pCodec, NULL) < 0)
|
|
|
- {
|
|
|
- printf("con not open jpeg codec!\n");
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-// char * strbuff = new char[10000000];
|
|
|
-// int ndatasize = 0;
|
|
|
while (mbthreadrun) {
|
|
|
|
|
|
iv::rawframedata xraw;
|