-
(转)利用ffmpeg来进行视频解码的完整示例代码(H.264)
- Decode()
- {
- FILE * inpf;
-
- int nWrite;
- int i,p;
- int nalLen;
- unsigned char* Buf;
- int got_picture, consumed_bytes;
- unsigned char *DisplayBuf;
- DisplayBuf=(unsigned char *)malloc(60000);
-
- char outfile[] = "test.pgm";
-
-
- inpf = fopen("test.264", "rb");
-
-
-
- if(!inpf)
- {
- goto Decodereturn;
- }
-
- nalLen = 0;
- Buf = (unsigned char*)calloc ( 1000000, sizeof(char));
-
-
- avcodec_init();
- avcodec_register_all();
- codec = avcodec_find_decoder(CODEC_ID_H264);
-
- if (!codec) {
- return 0;
- }
-
-
- c = avcodec_alloc_context();
-
- if(!c){
- return 0;
- }
-
-
- if (avcodec_open(c, codec) < 0) {
- return 0;
- }
-
-
-
- picture = avcodec_alloc_frame();
- if(!picture){
- return 0;
- }
-
- rgbdatanew = (unsigned char *)malloc(sizeof(unsigned char)*(3 * width * height));
-
- while(!feof(inpf))
- {
-
-
- nalLen = getNextNal(inpf, Buf);
-
-
- consumed_bytes= avcodec_decode_video(c, picture, &got_picture, Buf, nalLen);
-
- if(consumed_bytes > 0)
- {
-
-
- p=0;
- for(i=0; i<c->height; i++)
- {
- memcpy(DisplayBuf+p,picture->data[0] + i * picture->linesize[0], c->width);
- p+=c->width;
- }
- for(i=0; i<c->height/2; i++)
- {
- memcpy(DisplayBuf+p,picture->data[1] + i * picture->linesize[1], c->width/2);
- p+=c->width/2;
- }
- for(i=0; i<c->height/2; i++)
- {
- memcpy(DisplayBuf+p,picture->data[2] + i * picture->linesize[2], c->width/2);
- p+=c->width/2;
- }
-
- DisplayVideo(DisplayBuf);
- }
- }
-
-
- if(inpf)
- fclose(inpf);
-
- Decodereturn:
-
-
- if(c) {
- avcodec_close(c);
- av_free(c);
- c = NULL;
- }
-
- if(picture) {
- av_free(picture);
- picture = NULL;
- }
-
-
- if(Buf)
- {
- free(Buf);
- Buf = NULL;
- }
-
- free(DisplayBuf);
- }
-
相关阅读:
Android开发常见问题及解决方法
Jquery chosen动态设置值实例介绍 select Ajax动态加载数据 设置chosen和获取他们选中的值
Unity3d 基于物理渲染Physically-Based Rendering之实现
Unity3d 基于物理渲染Physically-Based Rendering之specular BRDF
Unity3d HDR和Bloom效果(高动态范围图像和泛光)
unity3d 制造自己的水体water effect(一)
unity3d shader之Roberts,Sobel,Canny 三种边缘检测方法
Unity3d shader之卡通着色Toon Shading
NVIDIA CG语言 函数之所有数学类函数(Mathematical Functions)
Unity3d 使用DX11的曲面细分
-
原文地址:https://www.cnblogs.com/seacode/p/1767627.html
Copyright © 2020-2023
润新知