关于ffmpeg解码内存增加解决方案-替换解码代码

从ffmpeg中提取wma pro解码器 经过一周半的努力,终于从ffmpeg中提取了一个包含asf解析功能和wmapro解码功能,并能在VC2005上运行的工程,当然现在还很简陋,呵呵。 这个是我第一次从ffmpeg中提取解码器模块,ffmpeg是个相当大的工程,这给提取工作带来了很大的麻烦,更大的麻烦其实在于ffmpeg遵循了C99的标准,而VC不支持。以前没怎么接触C99,经过这次移植对它稍稍了解了一下,也许是我C的水平不够,我感 阅读详情
AI摘要

本文介绍了一个关于FFmpeg在循环播放过程中出现内存泄漏的问题及其解决办法。通过详细分析问题原因,作者给出了调整代码的具体步骤,并分享了一段经过验证能够避免内存泄漏的代码示例。

Linux环境:Ubuntu16.4
ffmpeg库版本:ffmpeg-3.4.1
问题:最近在弄ffmpeg视频解码,由于项目的需要,需要一直重复播放链表中挂在的图片,一直循环,但是遇到一个问题是,每次调用ffmpeg图像解码函数,使用top命令查看程序所占内存大小,发现每调用一次内存就增加一点,最后占掉了系统所有的内存,被系统防护机制杀掉了。
尝试解决:
1、遇到上述问题之后,我开始怀疑是不是我忘记释放申请的内存,然后一直找啊找,发现申请的该释放的已经释放,然后在最初的视频解码代码修修改改还是不行。
2、然后我使用一块固定内存存放packet,outbuffer,就不再每播放一次申请一次,但后面也是失败了。
问题发现:在论坛博客找了许久,应该是av_read_frame(pFormatCtx, packet)的问题,其自动会为其分配内存,所以问题也出现在下面的一段代码:
packet = (AVPacket *) av_malloc(sizeof(AVPacket));
av_new_packet(packet, unFrameSize)  //这里其实不用的,如果加了这里那么将分配一个没用到的内存,因为av_read_frame()会重新分配一块内存挂在Pframe上,所以这段内存将没有被用到,也不能被回收,所以解码没调用一次就内存就升高一点。
解决方案:
1、删除掉:
av_new_packet(packet, unFrameSize)
2、使用ffmpeg新的解码方案:
/*************************************************
  Function:      
  Description:   
  Input:      
                 
  Output:         
  Return:     	 -1-失败   0-成功
  Author:        
  Date:          2018-01-01

  Modification History
  Author:
  Date:
  Description:
*************************************************/

INT32 videoPlay(char* fim)
{
    AVPacket packet;
    AVCodec *pCodec = NULL;
    AVCodecContext *origin_ctx = NULL, *ctx= NULL;
    AVFrame *pFrame = NULL;
    AVFormatContext *fmt_ctx = NULL;
	
    int video_stream;
    int got_frame = 0;
    int byte_buffer_size;
    int i = 0;
    int result;
    int end_of_stream = 0;
	

		
		/*打开输入文件*/
		result = avformat_open_input(&fmt_ctx, fileName, NULL, NULL);
    	if (result < 0) {
			   Console_Error("Couldn't open input Picture.\n");
			   continue;
		}
		
		/*获取文件视频流信息*/
		result = avformat_find_stream_info(fmt_ctx, NULL);
    	if (result < 0) {
			   Console_Error("Couldn't find stream information.\n");
			   continue;
		}

		/*获取视频编码格式*/
		video_stream = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
    	if (video_stream < 0) {
			Console_Error("Didn't find a video stream.\n");
			continue;
		}

		origin_ctx = fmt_ctx->streams[video_stream]->codec;
		
		/*查找解码器*/
		pCodec = avcodec_find_decoder(origin_ctx->codec_id);
    	if (!pCodec) {
			Console_Error("Codec not found.\n");
			continue;
		}

		ctx = avcodec_alloc_context3(pCodec);
   	 	if (!ctx) {
			Console_Error("avcodec_alloc_context3.\n");
			continue;
		}

		result = avcodec_copy_context(ctx, origin_ctx);
    	if (result) {
			Console_Error("avcodec_alloc_context3.\n");
			continue;
		}

		/*打开解码器*/
		result = avcodec_open2(ctx, pCodec, NULL);
    	if (result < 0) {
			Console_Error("Could not avcodec_open2.\n");
			continue;
		}

		pFrame = av_frame_alloc();
    	if (!pFrame) {
			Console_Error("Could not av_frame_alloc .\n");
			continue;
		}

		/*指定格式图像所需的大小*/
		byte_buffer_size = av_image_get_buffer_size(AV_PIX_FMT_YUV420P, ctx->coded_width, ctx->coded_height, 1);
	    byte_buffer = av_malloc(byte_buffer_size);
	    if (!byte_buffer) {
			Console_Error("Could not av_malloc_byte_buffer .\n");
			continue;
		}
		
    	        i = 0;
		av_init_packet(&packet);
		
	do 
	{
	        if (!end_of_stream)
        	{
			if (av_read_frame(fmt_ctx, &packet) < 0)
	                end_of_stream = 1;
        	}
	           
	        if (end_of_stream) {
	            packet.data = NULL;
	            packet.size = 0;
	        }
	        if (packet.stream_index == video_stream || end_of_stream) 
		{
	            got_frame = 0;
				
	            if (packet.pts == AV_NOPTS_VALUE)
	                packet.pts = packet.dts = i;
				
				
				
	            result = avcodec_decode_video2(ctx, pFrame, &got_frame, &packet);
	            if (result < 0) {
	                printf("Error decoding frame\n");
	                continue ;
	            }
	            if (got_frame) {
			byte_buffer_size = av_image_copy_to_buffer(byte_buffer, byte_buffer_size,
					(const UINT8* const *)pFrame->data, (const int*) pFrame->linesize,
						AV_PIX_FMT_YUV420P, ctx->coded_width, ctx->coded_height, 1);
			if (byte_buffer_size < 0) {
				printf("Can't copy image to buffer\n");
				return byte_buffer_size;
			}                                                                                                                   //dosomethinghere
	            }
	            av_packet_unref(&packet);
	            av_init_packet(&packet);
	        }
	        i++;
    } while (!end_of_stream || got_frame);

	av_packet_unref(&packet);
    av_frame_free(&pFrame);
    avcodec_close(ctx);
    avformat_close_input(&fmt_ctx);
    avcodec_free_context(&ctx);
    av_freep(&byte_buffer);
    }
    return 0;
}

一些说明:在使用av_packet_alloc创建packet的时候,并没有给数据域分配空间,数据域的空间实在av_read_frame内分配的,所以在每次循环的结束不能忘记调用av_packet_unref减少数据域的引用技术,当引用技术减为0时,会自动释放数据域所占用的空间。在循环结束后,调用av_packet_free来释放AVPacket本身所占用的空间。

附:音视频解码播放代码,100%解决了内存增加问题,完整释放各种动态申请的变量:



INT32 videoPlay(void)
{
	AVPacket packet;
    AVFormatContext *pfmt_ctx = NULL;

	AVFrame *pFrame = NULL;
	AVCodec *pCodec = NULL;
    AVCodecContext *porigin_ctx = NULL, *pctx= NULL;
    
	AVFrame *paudioFrame = NULL;
	AVCodecContext  *paudioCodecCtxOrig 	= NULL;
	AVCodecContext  *paudioCodecCtx			= NULL;
	AVCodec         *paudioCodec 			= NULL;

    INT32 nvideo_stream =-1;
	INT32 naudio_stream =-1;
	
    INT32 ngot_frame = 0;
    INT32 nbyte_buffer_size = 0;
	INT32 number_of_written_bytes = 0;
    INT32 ni 		= 0;
    INT32 nresult 	=-1;
    INT32 nend_of_stream 		= 0;
	UINT32 nCnt = 0,naudioCnt = 0;
	INT8* ptmp = NULL;
	UINT8 *pucbyte_buffer = NULL;
	ULONG unTmpFrameSize 	= 0;
	ULONG unFrameSize 		= 0;


	/*打开输入文件*/
	nresult = avformat_open_input(&pfmt_ctx, g_Advers.ucCurrentPlayAvderName, NULL, NULL);
        if (nresult < 0) {
		   Console_Error("Couldn't open input stream.\n");
		   /*进入这里表名文件已更改,所以需要重新更新广告列表*/
		   ni = 0;
		   adver_listUpdate(ptmp,ptmp,ni);
		   return -1;
	 }

	/*获取文件视频流信息*/
	nresult = avformat_find_stream_info(pfmt_ctx, NULL);
	if (nresult < 0) {
		   Console_Error("Couldn't find stream information.\n");
		   return -1;
	}

	/*获取视频编码格式*/
	nvideo_stream = av_find_best_stream(pfmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
	naudio_stream = av_find_best_stream(pfmt_ctx, AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0);
	if (nvideo_stream < 0|| naudio_stream < 0) {
		Console_Error("Didn't find a video stream.\n");
		return -1;
	}

	/*查找解码器*/
	porigin_ctx = pfmt_ctx->streams[nvideo_stream]->codec;
	paudioCodecCtxOrig = pfmt_ctx->streams[naudio_stream]->codec;

        pCodec = avcodec_find_decoder(porigin_ctx->codec_id);
	paudioCodec = avcodec_find_decoder(paudioCodecCtxOrig->codec_id);
        if (!pCodec||!paudioCodec) {
		Console_Error("Codec not found.\n");
		return -1;
	}

	pctx = avcodec_alloc_context3(pCodec);
	paudioCodecCtx = avcodec_alloc_context3(paudioCodec);
       if (!pctx||!paudioCodecCtx) {
		Console_Error("avcodec_alloc_context3 error.\n");
		return -1;
	}

	nresult = avcodec_copy_context(pctx, porigin_ctx);
	if (nresult) {
		Console_Error("avcodec_copy_context error.\n");
		return -1;
	}
	
	nresult = avcodec_copy_context(paudioCodecCtx, paudioCodecCtxOrig);
       if (nresult) {
		Console_Error("avcodec_copy_context error.\n");
		return -1;
	}

	/*打开解码器*/
	nresult = avcodec_open2(pctx, pCodec, NULL);
       if (nresult < 0) {
		Console_Error("videoCodec_open2 error.\n");
		return -1;
	}
	
	nresult = avcodec_open2(paudioCodecCtx, paudioCodec, NULL);
       if (nresult < 0) {
		Console_Error("audioCodec_open2 error.\n");
		return -1;
	}

	pFrame = av_frame_alloc();
	paudioFrame = av_frame_alloc();
        if (!pFrame||!paudioFrame) {
		Console_Error("av_frame_alloc error.\n");
		return -1;
	}

	/*指定格式图像所需的大小*/
	nbyte_buffer_size = av_image_get_buffer_size(pctx->pix_fmt, pctx->coded_width, pctx->coded_height, 1);
        pucbyte_buffer = av_malloc(nbyte_buffer_size);
       if (!pucbyte_buffer) {
		Console_Error("Could not av_malloc_byte_buffer .\n");
		return -1;
	}

	avpicture_fill((AVPicture *) pFrame, pucbyte_buffer, pctx->pix_fmt,
				pctx->coded_width, pctx->coded_height);
	
        av_init_packet(&packet);
	/*读取视频*/
	do 
	{
		if (!nend_of_stream)
		{
			 if (av_read_frame(pfmt_ctx, &packet) < 0)
				nend_of_stream = 1;
		}
		if (nend_of_stream) {
			packet.data = NULL;
			packet.size = 0;
		}
		if (packet.stream_index == nvideo_stream || nend_of_stream) 
		{
			ngot_frame = 0;
			
			if (packet.pts == AV_NOPTS_VALUE)
				packet.pts = packet.dts = ni;
			
			nresult = avcodec_decode_video2(pctx, pFrame, &ngot_frame, &packet);
			if (nresult < 0) {
				printf("Error decoding frame\n");
				continue ;
			}
			if (ngot_frame) {
				 number_of_written_bytes = av_image_copy_to_buffer(pucbyte_buffer, nbyte_buffer_size,
	                                        (const UINT8* const *)pFrame->data, (const int*) pFrame->linesize,
	                                        pctx->pix_fmt, pctx->coded_width, pctx->coded_height, 1);
	                if (number_of_written_bytes < 0) {
	                    printf("Can't copy image to buffer\n");
	                    continue;
	                }
				/*将解码出来的视频流传送到显示模块*/
				//displayWrite(ADVER_HANDLE_ID,pucbyte_buffer,&picFrameInfo);
			}
			av_packet_unref(&packet);
			av_init_packet(&packet);
		}
		else if(packet.stream_index == naudio_stream||nend_of_stream)
		{
			
		       /*在这里给帧提供paudioCodecCtx和paudioFrame,已经解好码了,等音频模块对解码后的数据进行加工*/
			nresult = audioplaystream(paudioCodecCtx, &packet);

			av_packet_unref(&packet);
			av_init_packet(&packet);
		}

	} while (!nend_of_stream || ngot_frame);
	
	
	/*释放资源*/
	av_packet_unref(&packet);
	av_free_packet(&packet);
        av_frame_free(&pFrame);
	av_frame_free(&paudioFrame);
	
        avcodec_close(pctx);
	avcodec_close(porigin_ctx);
	avcodec_close(paudioCodecCtx);
	avcodec_close(paudioCodecCtxOrig);
	
	avcodec_free_context(&pctx);
	avcodec_free_context(&paudioCodecCtx);
	
        avformat_close_input(&pfmt_ctx);
	avformat_free_context(pfmt_ctx);
	
        av_freep(&pucbyte_buffer);
	return 0;
}




FFmpeg 硬件加速(硬解码)介绍 概述本文主要针对ffmpeg支持的硬解码做一个总结阐述。许多平台提供对专用硬件的访问,以执行一系列与视频相关的任务。使用此类硬件可以更快地完成某些操作,例如解码、编码或过滤,或者使用更少的其他资源(尤其是 CPU),但可能会产生不同或较差的结果,或者施加仅使用软件时不存在的额外限制。在类似 PC 的平台上,视频硬件通常集成到 GPU(来自 AMD、Intel 或 NVIDIA)中,而在移动 SoC 类型的平台上,它通常是一个独立的 IP 核(许多不同的供应商)。 阅读详情

相关推荐

FFmpeg的软、硬解码方式梳理

背景 项目中使用QT开发监控软件,集成海康、宇视、大华、以及网络流设备。品牌设备使用SDK控制,网络流设备自己使用FFmpeg库来解决。如果同时解码多路播放,会出现CPU占用较高的情况。如果视频流路数更多如16路,或编码更为复杂的如H265,那么软件CPU将无力支持,软件卡顿异常崩溃也是很可能的。 问题分析 ...

周小哥的博客 7313

记使用ffmpeg播放视频,内存不断增加的解决过程

 一、 播放视频的程序中涉及内存管理的大概有3部分 1)用av_read_frame从buffer中获取数据 while(bStart) { pAvPkt=(AVPacket *)malloc(sizeof(AVPacket)); memset(pAvPkt,0,sizeof(AVPacket)); av_init_packet(pAvPkt); if(av...

u010518621的博客 7412

FFmpeg 'avcodec_copy_context' deprecated (视频裁剪)

在学习一些代码的时候发现有些已经弃用了:记录一下新的写法: 1,avcodec_copy_context 以前的写法: ret = avcodec_copy_context(outStream->codec, inStream->codec); if (ret < 0) { fprintf(stderr, "Failed to copy contex...

u010141160的博客 1225

关于ffmpeg库 使用av_frame_free之类操作后内存不会减少的现象

出现的问题: 最近使用ffmpeg+qt制作音视频播放器的解码模块时出现了内存占用过高的情况,想通过av_frame_free等操作减少内存内存占用,但内存上涨之后调用这类操作内存占用并不会减少. 原因: 内存占用没减少的原因并不是因为av_frame_free操作未生效,实际上,如果不调用free指令,内存是会不断上升的,调用清理内存的指令的话内存在上涨到一定程度时就不会上涨了. 因为ffmpeg内部分配内存和清理内存时采用了 “缓存池” 的机制,内存不够时会增加池的大小,而调用者欲释放内存时,池并不会立

MCCreeper的博客 1851

CUDA和FFMPEG硬件解码视频流

其他博客给出的教程要么只是给出了伪代码,非常的模糊,要么是基于D3D进行显示,使得给出的源码非常复杂,而无法看出CUDA解码的核心框架,而本文将其他非核心部分剥离出去,视频播放部分通过opencv调用cv::mat显示。示例中NvDecodeD3D9.cpp实现了D3D环境的创建,CUDA模块的初始化,其中取视频帧图像显示的函数如下,该函数实现了从解码图像队列取出图像(实际上是显存指针),完成格式转换(NV12到ARGB),最后映射到D3D的Texture进行显示等功能,代码中我给出了关键部位的解释。

yinshipin007的博客 2167

MediaPipe+FFmpeg实现无绿幕视频背景替换方案

计算机视觉中的图像分割技术是实现视频特效的基础,其中人像分割作为关键子领域,通过深度学习模型精准分离前景与背景。MediaPipe框架提供的轻量级Selfie Segmentation模型,结合FFmpeg强大的视频处理能力,构建出高效的软件绿幕解决方案。该技术方案采用多线程流水线设计,利用OpenGL硬件加速渲染,在移动端实现实时处理。典型应用场景包括视频会议虚拟背景、短视频特效制作等,相比传统方案可降低300%硬件成本。通过三重缓冲机制和JNI优化,系统在骁龙865设备上达到45fps的1080P处理性

weixin_29065659的博客 326

ffmpeg解码案例

基于ffmpeg 4.11版本实现打开本地文件,网络文件与编解码。ffmpeg 4.x.x版本后,函数已经被移除。从 FFmpeg 3.x 开始,不再需要手动调用来注册所有可用的编解码器和协议。取而代之的是,注册过程是自动完成的。在 FFmpeg 的早期版本(例如 2.x)中,AVStream结构体中有一个名为codec的成员,它是一个指向的指针。因此,的类型是。从 FFmpeg 3.x 开始,AVStream结构体中的codec成员已经被移除,取而代之的是codecpar,它是一个指向的指针。

qq_39806129的博客 863

FFmpeg解码H264视频流

解码H264视频流数据,支持输出RGB24或YUV420格式,非解码视频文件; 代码如下: FFmpegVideoDecoder.h #include <libavcodec/avcodec.h> /** 视频流解码器初始化 @param ctx 解码参数结构体AVCodecParameters @see FFmpeg_H264DecoderInit,此为解码...

程序猿老樊的博客 3130

ffmpeg解码h265,并用Qt显示

学习ffmpeg有一段时间了,由于身边没有人可以请教,所有基本上都是出了问题就上网查资料。到现在勉强能完成工作任务了。

沾衣欲湿杏花雨,吹面不寒杨柳风。 5328

Xilinx Aurora 8B/10B IP核详解和仿真

Xilinx Aurora 8b/10b IP核的详解,以及使用与仿真示例,对IP核的配置和如何仿真有非常详细的说明,除了对IP核官方文档的内容进行了解析以外,还对GTX引脚的选择等比较容易混淆和不好理解的地方进行了说明。最后对IP核的仿真运行进行了STEP BY STEP 的说明,对仿真的结果也进行了简要的说明。 该文档对Xilinx FPGA和ZYNQ SOC下 AURORA 8B/10B IP核的使用提供了一个快速上手的指导。

weixin_43354598的博客 1万+

Python 格点数据插值到站点 最邻近插值 双线性插值

python 气象数据格点数据插值到站点,最邻近插值法,双线性插值法

好记性不如烂笔头 8465

FFmpeg解码H264视频裸流(直接可用)

此文章主要包含解码H264视频流数据:Annex B格式、H264视频裸流、支持输出RGB24或YUV420格式;

W2Y的专栏 2万+

modelsim软件安装教程及踩坑(极简版)

1.安装的网盘链接:链接:https://pan.baidu.com/s/1ltUfssyXlCnqDmLhWyhlwA提取码:jery 2.步骤(参考博文):https://blog.csdn.net/weixin_42693097/article/details/90523692?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163521788716780357213801%2522%252C%2522scm%2522%253A%2522

subtitle_的博客 3787

Qt + FFmpeg实现播放器(FFmpeg可以解码的格式基本都可以播放)。

一、开发环境的准备 Linux下移植ffmpeg开源库。 二、代码实现播放功能 在界面上放置一个 QLabel 和 QPushButton 控件,当点击按钮时播放视频。程序主要分为以下几方面: 1、打开音视频流并获取音视频流信息; 2、查找视频流位置以及查找并打开视频解码器; 3、视频解码的同时处理图片像素数据; 4、最后要释放申请的内存空间。 #include "widget.h" #include "ui_widget.h" #include <QTime> // 调用FFmpeg的头文件

爱捣蛋的小仙儿。 5669

COMSOL实现裂缝性储层油水两相流模拟的关键技术

多孔介质中的流体流动模拟是油气藏开发的核心技术,其基本原理基于达西定律和质量守恒方程。在裂缝性储层中,离散裂缝网络与基质系统的耦合流动带来了特殊的数值挑战。通过COMSOL Multiphysics平台实现的多物理场耦合技术,可以精确模拟油水两相在复杂裂缝系统中的渗流行为。该技术采用Level Set方法表征裂缝几何形态,结合自适应网格生成技术解决狭窄裂缝的网格剖分难题,并创新性地引入Bang-Larsen毛管压力滞后模型,显著提高了采收率预测精度。这些方法在致密油藏开发、水驱优化等工程实践中具有重要应用价

weixin_34005090的博客 236

Jetson Orin NX深度学习环境配置全攻略:从JetPack到PyTorch避坑指南

本文提供Jetson Orin NX深度学习环境配置的完整避坑指南。重点讲解如何正确利用JetPack SDK作为系统基石,使用Miniforge管理Python环境,并安装与CUDA版本严格匹配的PyTorch特供版本。通过详细的步骤和验证方法,帮助开发者在ARM架构的嵌入式平台上高效搭建稳定的AI开发工作站。

yolo5detector的博客 279

FFmpeg 4.x 从入门到精通(二)—— QT 中用 FFmpeg 实现硬解码并使用QImage显示

背景 上篇文章我们详细阐述了windows环境下使用ffmpeg进行软解码的步骤,并给出了完整代码。 FFmpeg 4.x 从入门到精通(一)—— QT 中如何用 FFmpeg 实现软件解码 接下来这篇文章继续进行深入,带大家学习使用FFmpeg实现windows下的硬解码。 FFmpeg下载地址(粉丝免费下载): https://download.csdn.net/download/u012534831/14045436 本文的语言环境基于C++,界面部分是 QT。 流程分析 老规矩,在开始看代码之前,我

q2nAmor 5657

Social-Auto-Upload实战:如何用Python+Playwright实现抖音/B站/小红书一键三连发?

本文详细介绍了如何使用Python和Playwright框架构建Social-Auto-Upload自动化上传工具,实现抖音、B站、小红书等平台的一键多发布。通过模拟真实用户操作和Cookie管理技术,该工具能有效解决内容创作者跨平台发布的重复劳动问题,提升工作效率。

day7的博客 1408

FFmpeg内存IO模式

ffmpeg 支持从网络流 或者本地文件读取数据,然后拿去丢给解码器解码,但是有一种特殊情况,就是数据不是从网络来的,也不再本地文件里面,而是在某块内存里面的。这时候 av_read_frame() 函数怎样才能从内存把 AVPacket 读出来呢?

u012117034的博客 1719

多模型对抗性审查:用AI辩论提升技术文档质量

在软件工程领域,技术文档是团队协作和项目成功的关键基础。传统的文档评审依赖人工经验,存在盲区和效率瓶颈。通过引入多模型对抗性审查机制,不同大语言模型从各自视角对文档进行批判性分析,模拟现实中的专家评审过程。这种技术方法的核心价值在于利用模型间的思维差异,自动发现单个视角容易忽略的边界情况、逻辑漏洞和隐含假设。在应用场景上,特别适合产品需求文档和技术规格书这类需要多角度审视的复杂文档。adversarial-spec工具通过Claude协调多模型辩论,实现从概念到实现的完整文档质量保障,显著提升文档的完整性和

weixin_42531579的博客 388

Skill的嵌套

Skill的嵌套就很简单,直接引用其他的Skill就好了。在一个 Skill 的 SKILL.md 中,可以明确指示 Claude 去读取另一个 Skill 的文档。

Criss@陈磊 977

从0到1实现Web端H.265播放器:视频解码篇

说明 本文转载自:从0到1实现Web端H.265播放器:视频解码篇 什么是H.265? 本文在这里就不对H.265做介绍了。感兴趣的朋友可以看下面的文章了解详情。(第一篇是我们在2019年3月发布的文章,距今已有2年,时间过得真快)《Web端H.265播放器研发解密》[1] WebAssembly的发展 看了上面那篇2年前的文章应该清楚了浏览器对于H.265支持程度。好消息是经过两年发展,Webassembly发布了1.1版本,增加了很多新特性,性能也有了提升。坏消息是浏览器依然不支持H.265,估计以后也

学习前端这门手艺,栈底到栈顶依次是:浏览器架构、Web 网络、事件循环机制、JavaScript 核心、V8 的内存管理、浏览器的渲染流程、Web 安全、CSS、React、Vue、Node、构建工具链等 3348

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

FFmpeg 4.2 从入门到精通(二)—— QT 中用 FFmpeg 实现硬解码并使用QImage显示

读取码流中的音频若干帧或者视频一帧,av_read_frame()函数是新型ffmpeg的用法,对 av_read_packet 进行了封装,旧用法之所以被抛弃,就是因为以前获取的数据可能不是完整的,而av_read_frame()保证了视频数据一帧的完整性,使读出的数据总是完整的一帧。为 AVFormatContext 分配空间,打开输入的视频数据并且探测视频的格式,这个函数里面包含了复杂的格式解析与探测算法,可解析的内容包括:视频流、音频流、视频流参数、音频流参数、视频帧索引等。

irainsa的博客 1079

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

FFmpeg+SDL 接收H264码流解码并以YUV420p方式显示

最近开始看音视频方面的知识点,也开始接触到了FFmpeg了,但不是很懂,所以也在网上找了一篇文章来练习一下,然后得到自己想要的功能效果,所以做一下记录以及分享避免到时候忘记了。 首先这里分为两个步骤 1、使用FFmpeg对H264码流解码 2、把解码得到的YUV420p数据用SDL把图片显示出来 关于如何把YUV420p数据用SDL把图片显示的可以参考 https://blog.csdn.net/qq_36351159/article/details/109542687 关于使用FFmpeg如何解H264码

Feng的博客 1529

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

音视频入门(学习ffmpeg tutorial之 iOS视频解码及展示)

使用ffmpeg进行解码的流程是固定的,就如同iOS开发一样,从viewDidLoad,viewWillApear,viewDidAppear,苹果都已经把需要调用的方法顺序告诉我们了,需要我们做的就是把自己业务代码合理的放到对应的位置。 视频解码基本流程 注册需要支持的文件格式以及对应的编解码器 打开文件 从文件中提取数据流信息 从数据流(视频数据流/音频数据流/字幕数据流)中找到对应的视频数...

无聊的专栏 427
上一篇: ffmpeg 视频解码 vformat_find_stream_info() 后获取视频分辨率错误问题
下一篇: uboot修改启动logo-sunxi
Chasing_Chasing
博客等级 码龄10年 233粉丝 87原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址