android free命令,free命令的详细说明

1,free命令

-b/-k/-m: 以Byte/KB/MB为单位显示内存使用情况。

-o: 不显示缓冲区调节列。

-s: 持续观察内存使用状况

-t 显示内存总和列

执行free之后各字段说明

c5011cb1673b

free.PNG

系统的总物理内存是18270760KB,但系统当前真正可用的内存小并不是第一行free标记的1559072KB,它仅代表没被分配的内存。

第一行 Mem :表示物理内存的缓存统计

total:表示物理内存总量

used:表示总计分配给缓存(包含buffers与cach)使用的数量,但其中可能有部分缓存并未实际使用。

free:未被分配的内存

shared:共享内存

bufers:系统已分配但未被使用的buffers数量

cached:系统已分配但未被使用的cache数量

buffer是指作为buffer cache的内存,即块设备的读写缓冲区,cache是指作为page cache的内存,即文件系统的cache。如果cache的值很大,则说明cache主的文件数量很多。如果频繁访问到的文件都能被cache住,那么磁盘的读I/O必定会非常小,但是过大的文件cache可能会影响到内存的使用效率,导致操作系统上其他进程的内存不够大,甚至还会使用到swap空间。

total =used + free

第二行 -/+ buffers/cache :表示物理内存的缓存统计

used:也就是第一行中的userd-buffers-cached,也是实际使用的内存总量

free:未被使用的buffers与cache和未被分配的内存之和=第一行的(buffers+cached+free),这就是系统当前实际可用的内存。

第三行 Swap:表示硬盘上交换分区的使用情况。

第二行所指的是从应用程序的角度来看,对应用程序来讲,buffers/cache是等同可用的,当程序使用内存时,buffers/cache会很快地被使用。从应用程序的角度来说,可用内存=第一行的(buffers+cached+free)

第一行的Mem是对操作系统来讲的,buffers/cache都是属于被使用的,所以它认为free只有1559072KB

我们一般理解的free输出应该从应用程序的角度去理解,应该管制第二行的free输出,因为那些buffers和cache是可能被重用的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android中使用FFmpeg提取MP4中的H264视频流,可以使用FFmpeg的C库,以下是基本的步骤: 1. 在 Android 项目中添加 FFmpeg C库文件和头文件。 2. 使用 FFmpeg 的 API 打开 MP4 文件并解析出 H264 视频流的信息,例如视频流的宽度、高度、码率、帧率等。 3. 使用 FFmpeg 的 API 打开视频流并解码每一帧视频,将解码后的视频帧保存到文件或渲染到 Android 的 SurfaceView 上。 4. 关闭 FFmpeg 解码器和输入文件。 下面是一个简单的示例代码,可以帮助你开始使用 FFmpeg 解码 H264 视频流: ``` #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> #include <sys/types.h> #include <sys/stat.h> // FFmpeg 头文件 #include "libavcodec/avcodec.h" #include "libavformat/avformat.h" #include "libswscale/swscale.h" int main(int argc, char* argv[]) { // 初始化 FFmpeg 库 av_register_all(); // 打开 MP4 文件 AVFormatContext *pFormatCtx = NULL; if (avformat_open_input(&pFormatCtx, "input.mp4", NULL, NULL) != 0) { printf("Error: could not open input file.\n"); return -1; } // 查找视频流信息 if (avformat_find_stream_info(pFormatCtx, NULL) < 0) { printf("Error: could not find stream information.\n"); return -1; } // 查找视频流索引 int videoStream = -1; for (int i = 0; i < pFormatCtx->nb_streams; i++) { if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { videoStream = i; break; } } if (videoStream == -1) { printf("Error: could not find video stream.\n"); return -1; } // 获取视频流解码器 AVCodecParameters *pCodecPar = pFormatCtx->streams[videoStream]->codecpar; AVCodec *pCodec = avcodec_find_decoder(pCodecPar->codec_id); if (pCodec == NULL) { printf("Error: unsupported codec.\n"); return -1; } // 打开视频流解码器 AVCodecContext *pCodecCtx = avcodec_alloc_context3(pCodec); if (avcodec_parameters_to_context(pCodecCtx, pCodecPar) < 0) { printf("Error: could not copy codec parameters to decoder context.\n"); return -1; } if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) { printf("Error: could not open codec.\n"); return -1; } // 分配视频帧缓冲区 AVFrame *pFrame = av_frame_alloc(); AVFrame *pFrameRGB = av_frame_alloc(); if (pFrameRGB == NULL || pFrame == NULL) { printf("Error: could not allocate frame.\n"); return -1; } // 计算视频帧大小 int numBytes = av_image_get_buffer_size(AV_PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height, 1); uint8_t *buffer = (uint8_t *)av_malloc(numBytes * sizeof(uint8_t)); // 初始化视频帧缓冲区 av_image_fill_arrays(pFrameRGB->data, pFrameRGB->linesize, buffer, AV_PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height, 1); // 创建视频转换器 struct SwsContext *sws_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, AV_PIX_FMT_RGB24, SWS_BILINEAR, NULL, NULL, NULL); // 读取视频帧并解码 AVPacket packet; while (av_read_frame(pFormatCtx, &packet) >= 0) { if (packet.stream_index == videoStream) { avcodec_send_packet(pCodecCtx, &packet); while (avcodec_receive_frame(pCodecCtx, pFrame) == 0) { // 将视频帧转换为 RGB 格式 sws_scale(sws_ctx, (const uint8_t * const*)pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize); // 处理 RGB 格式的视频帧,例如保存到文件或渲染到 SurfaceView 上 // ... // 释放视频帧资源 av_frame_unref(pFrame); } } av_packet_unref(&packet); } // 释放资源 av_free(buffer); av_frame_free(&pFrameRGB); av_frame_free(&pFrame); avcodec_close(pCodecCtx); avcodec_free_context(&pCodecCtx); avformat_close_input(&pFormatCtx); return 0; } ``` 这只是一个简单的示例代码,你需要根据自己的需求进行修改和扩展。同时,需要注意的是,FFmpeg 的使用需要遵循相关的协议和法律规定,不要用于非法用途。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值