3D video, there are some of the upper and lower format, but whether the naked 3D or 3D glasses need to format, the following is the conversion algorithm, the use of ffmpeg decoding, YUV cutting, to achieve the video interleaving, can be in the naked eye 3D mobile phone or pad to watch the 3D effect. You must familiarize yourself with the YUV data format first.
FILE *yuvfile = fopen ("YUV_FILE_WIDTH.YUV", "AB"), if (!yuvfile) return 0;av_register_all (); Avformatcontext *pformat = null;if (Avformat_open_input (&pformat, Src_file,null,null) < 0) {return 0;} Avcodeccontext * Video_dec_ctx = NULL; Avcodec *video_dec = null;if (Avformat_find_stream_info (Pformat,null) < 0) {return 0;} Av_dump_format (pformat,0,src_file,0); int index = -1,i = 0;for (i=0;i<pformat->nb_streams;i++) {if (pFormat-> Streams[i]->codec->codec_type = = avmedia_type_video) {index = I;break;}} if ( -1 = = index) {printf ("can ' t find the codec\n"); return-1;} Video_dec_ctx = Pformat->streams[index]->codec;video_dec = Avcodec_find_decoder (video_dec_ctx->codec_id) ;//The source file's format context decoder context decoder has been found now open decoder if (Avcodec_open2 (Video_dec_ctx,video_dec,null) < 0) {return 0;} A frame of data needs to be read in the package avpacket *video_pkt = new Avpacket;av_init_packet (VIDEO_PKT), while (1) {if (Av_read_frame (pformat,video _PKT) <0) {fclose (yuvfile);d elete Video_pkt;return 0;} if (Pformat->streams[viDeo_pkt->stream_index]->codec->codec_type = = avmedia_type_video) {avframe *frame =avcodec_alloc_frame (); int got_pictrue = 0,ret = 0;ret = Avcodec_decode_video2 (VIDEO_DEC_CTX,FRAME,&GOT_PICTRUE,VIDEO_PKT); if (Ret < 0) { Continue;} if (got_pictrue) {printf ("Decode one frame is ok\n"); int height = video_dec_ctx->height/2;int width = video_dec_ctx-> ; Width*2;char *buf = new Char[height*width*3/2];memset (BUF,0,HEIGHT*WIDTH*3/2); int y_tmp=0,i=0;int u_tmp = width/2* Height*2;int v_tmp = u_tmp + width/4*height/2*2;for (i=0;i
3D video up and down conversion left and right interlaced format YUV