FFmpegYUV420保存JPEG例子-創(chuàng)新互聯(lián)

說明 FFmpeg3.4版本

我們提供的服務(wù)有:網(wǎng)站設(shè)計、成都網(wǎng)站制作、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、壽縣ssl等。為近千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的壽縣網(wǎng)站制作公司

bool SaveYUV420ToJPEG(const std::string &strFileName, int nWidth, int nHeight, int linesize, uint8_t * Y, uint8_t * U, uint8_t * V)
{
?AVFormatContext* pFormatCtx;
?AVCodecContext* pCodecCtx;
?AVCodec* pCodec;
?AVFrame* pFrame;???
?AVPacket pkt;???????
?int nRet = 0;?
?
?avformat_alloc_output_context2(&pFormatCtx, NULL, NULL, strFileName.c_str());???
???
?AVStream* pVideoAVStream = avformat_new_stream(pFormatCtx, 0);
?if (NULL == pVideoAVStream) return false;
??
?pCodecCtx = avcodec_alloc_context3(NULL);
?if (NULL == pCodecCtx)?return false;

avcodec_parameters_to_context(pCodecCtx, pVideoAVStream->codecpar);

pCodecCtx->codec_id = pFormatCtx->oformat->video_codec;
?pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO;??
?pCodecCtx->pix_fmt = AV_PIX_FMT_YUVJ420P;
?pCodecCtx->width? = nWidth;???
?pCodecCtx->height = nHeight;????
?pCodecCtx->time_base.num = 1;??
?pCodecCtx->time_base.den = 25;???

pCodec = avcodec_find_encoder(pCodecCtx->codec_id);???
?if (NULL == pCodec) return false;
??
?if (avcodec_open2(pCodecCtx, pCodec,NULL) < 0)
?{?????????
??return false;??
?}???
?pFrame = av_frame_alloc();??

int nJpegQuality = 80;?????
?pCodecCtx->qcompress = (float)nJpegQuality/100.f; // 0~1.0, default is 0.5??????
?pCodecCtx->qmin = 2;??????
?pCodecCtx->qmax = 31;??????
?pCodecCtx->max_qdiff = 3;???????
???
?avformat_write_header(pFormatCtx,NULL);????
?av_new_packet(&pkt, pCodecCtx->width * pCodecCtx->height * 3);
?pFrame->data[0] = Y;???
?pFrame->data[1] = U;??
?pFrame->data[2] = V;???
?pFrame->linesize[0] = linesize;???
?pFrame->linesize[1] = linesize/2;???
?pFrame->linesize[2] = linesize/2;???
?
?nRet = avcodec_send_frame(pCodecCtx, pFrame);
?if (avcodec_receive_packet(pCodecCtx, &pkt) != 0) return false;
?????
?pkt.stream_index = 0;???????
?nRet = av_write_frame(pFormatCtx, &pkt);??????
?av_packet_unref(&pkt);
??
?av_write_trailer(pFormatCtx);????
?avcodec_close(pCodecCtx);
?avcodec_free_context(&pCodecCtx);
?av_frame_free(&pFrame);???????
?avio_close(pFormatCtx->pb);???
?avformat_free_context(pFormatCtx);????
?return true;
}

調(diào)用例子

SaveYUV420ToJPEG("fengyuzaitu.jpg", pFrame->width, pFrame->height, pFrame->linesize[0], pFrame->data[0], pFrame->data[1], pFrame->data[2]);

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

分享題目:FFmpegYUV420保存JPEG例子-創(chuàng)新互聯(lián)
本文鏈接:http://bm7419.com/article30/dichpo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站ChatGPT、企業(yè)建站、建站公司用戶體驗、品牌網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護公司