In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Describe the FFmpeg3.4 version
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. 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
}
Call example
SaveYUV420ToJPEG ("fengyuzaitu.jpg", pFrame- > width, pFrame- > height, pFrame- > linesize [0], pFrame- > data [0], pFrame- > data [1], pFrame- > data [2])
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.