FFmpeg开发实战(六):jpeg转换为yuv格式图像

您所在的位置:网站首页 jpeg怎么转化为pdj格式 FFmpeg开发实战(六):jpeg转换为yuv格式图像

FFmpeg开发实战(六):jpeg转换为yuv格式图像

2024-07-09 14:27| 来源: 网络整理| 查看: 265

文章目录 0. 参考文献1. jpeg转yuv2. 源码下载

JPG和PNG等图片的解码方式和视频解码是一样的,因为视频是由一幅一幅的图片组成的,只不过视频的帧是会前后参考的,而JPG等图片是单独的一帧而已。

0. 参考文献

ffmpeg解码JPG和PNG等图片

1. jpeg转yuv int main(int argc, char* argv[]) { int i; char szFileName[128] = { 0 }; int decLen = 0; int frame = 0; AVCodecContext *pCodecCtx = NULL; AVFrame *pFrame = NULL; AVCodec *pCodec = NULL; AVFormatContext *pFormatCtx = NULL; /*if (argc != 3) { fprintf(stderr, "ERROR:need 3 argument!n"); exit(-1); }*/ sprintf(szFileName, "%s", "H:/bmp2jpg/1.jpeg"); #ifdef ENABLE_DEMUX_SAVE FILE* frvdemux = fopen("rvdemuxout.rm", "wb+"); if (NULL == frvdemux) { fprintf(stderr, "create rvdemuxout file failedn"); exit(1); } #endif /* output yuv file name */ sprintf(ffrvout, "%s", "H:/bmp2jpg/1.yuv"); pfout = fopen(ffrvout, "wb+"); if (NULL == pfout) { printf("create output file failedn"); exit(1); } printf("==========> Begin test ffmpeg call ffmpeg rv decodern"); av_register_all(); /* Open input video file */ //printf("before avformat_open_input [%s]n", szFileName); if (avformat_open_input(&pFormatCtx, szFileName, NULL, NULL) != 0) { fprintf(stderr, "Couldn't open input filen"); return -1; } //printf("after avformat_open_inputn"); /* Retrieve stream information */ if (avformat_find_stream_info(pFormatCtx, 0) nb_streams); for (i = 0; i nb_streams; i++) { if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { videoStream = i; printf("the first video stream index: videoStream = %dn", videoStream); break; } } if (videoStream == -1) return -1; // Didn't find a video stream /* Get a pointer to the codec context for the video stream */ pCodecCtx = pFormatCtx->streams[videoStream]->codec; printf("pCodecCtx->codec_id = %dn", pCodecCtx->codec_id); pCodec = avcodec_find_decoder(pCodecCtx->codec_id); if (pCodec == NULL) { fprintf(stderr, "can not find decoder!n"); return -1; } /* Open codec */ if (avcodec_open2(pCodecCtx, pCodec, NULL) = 0) { //printf("[main]avpkt->slice_count=%dn", packet.sliceNum); /* Is this a packet from the video stream? */ if (packet.stream_index == videoStream) { packetno++; #ifdef ENABLE_PRINT_FRAME_BYTES if (1) { int i; int size = packet.size linesize[0], pCodecCtx->width, pCodecCtx->height); printf("===>YUV format = %dn", pFrame->format); } #ifdef ENABLE_YUV_SAVE /* save yuv pic */ if (frame format) { case 0: /* YUV420P */ case 12: yuv420p_save(pFrame, pCodecCtx); break; case 2: /* RGB24 */ rgb24_save(pFrame, pCodecCtx); break; case 13: /* YUVJ422P */ yuv422p_save(pFrame, pCodecCtx); break; case 14: /* YUVJ444P */ yuv444p_save(pFrame, pCodecCtx); break; default: fprintf(stderr, "unsupport YUV format for savingn"); break; } fprintf(stderr, "===>save pic successn"); } #endif /* frame index grow */ frame++; } //printf("===========> %dn", decLen); /* left data in pkt , go on decoding */ packet.data += decLen; packet.size -= decLen; } if (frame == FRAME_NUM) { printf("==========> decoded [%d pkt frames] ---> save [%d YUV frames], enough to stop!n", packetno, FRAME_NUM); break; } } /* FIXME no need free in this file */ //printf("free packet that was allocated by av_read_framen"); // Free the packet that was allocated by av_read_frame //av_free_packet(&packet); } printf("decoding job down! begin to freen"); /* Free the YUV frame */ av_free(pFrame); /* Close the codec */ avcodec_close(pCodecCtx); /* Close the video file */ avformat_free_context(pFormatCtx); fclose(pfout); printf("==========> END-OKn"); return 0; } 2. 源码下载

jpeg转换为yuv格式图像源码



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3