03-编码篇-x264编译与介绍
使用FFMPEG作编码操作时,会涉及到将yuv数据编码成h264数据,FFmpeg的libavcodec中的libx264.c会调用x264库的源码作编码:
1.x264库编译
下载X264,地址为:http://www.videolan.org/developers/x264.html,并解压。
mkdir my_build
./configure --enable-shared --prefix=./my_build/
make -j4
make install
2.编译后可以查看 my_build目录
.
|-- bin
| `-- x264
|-- include
| |-- x264.h
| `-- x264_config.h
`-- lib|-- libx264.so -> libx264.so.164|-- libx264.so.164`-- pkgconfig`-- x264.pc
其中bin目录下x264为可执行文件,我们通过此可执行文件来分析x264库的相关功能
3.运行
通过-h信令,我们大致可以了解x264的主要功能和使用方法
./x264 -h
$ ./x264 -h
x264 core:164
Syntax: x264 [options] -o outfile infileInfile can be raw (in which case resolution is required),or YUV4MPEG (*.y4m),or Avisynth if compiled with support (yes).or libav* formats if compiled with lavf support (no) or ffms support (no).
Outfile type is selected by filename:.264 -> Raw bytestream.mkv -> Matroska.flv -> Flash Video.mp4 -> MP4 if compiled with GPAC or L-SMASH support (no)
Output bit depth: 8/10Options:-h, --help List basic options--longhelp List more options--fullhelp List all optionsExample usage:Constant quality mode:x264 --crf 24 -o <output> <input>Two-pass with a bitrate of 1000kbps:x264 --pass 1 --bitrate 1000 -o <output> <input>x264 --pass 2 --bitrate 1000 -o <output> <input>Lossless:x264 --qp 0 -o <output> <input>Maximum PSNR at the cost of speed and visual quality:x264 --preset placebo --tune psnr -o <output> <input>Constant bitrate at 1000kbps with a 2 second-buffer:x264 --vbv-bufsize 2000 --bitrate 1000 -o <output> <input>Presets:--profile <string> Force the limits of an H.264 profileOverrides all settings.- baseline, main, high, high10, high422, high444--preset <string> Use a preset to select encoding settings [medium]Overridden by user settings.- ultrafast,superfast,veryfast,faster,fast- medium,slow,slower,veryslow,placebo--tune <string> Tune the settings for a particular type of sourceor situationOverridden by user settings.Multiple tunings are separated by commas.Only one psy tuning can be used at a time.- psy tunings: film,animation,grain,stillimage,psnr,ssim- other tunings: fastdecode,zerolatencyFrame-type options:-I, --keyint <integer or "infinite"> Maximum GOP size [250]--tff Enable interlaced mode (top field first)--bff Enable interlaced mode (bottom field first)--pulldown <string> Use soft pulldown to change frame rate- none, 22, 32, 64, double, triple, euro (requires cfr input)Ratecontrol:-B, --bitrate <integer> Set bitrate (kbit/s)--crf <float> Quality-based VBR (-12-51) [23.0]--vbv-maxrate <integer> Max local bitrate (kbit/s) [0]--vbv-bufsize <integer> Set size of the VBV buffer (kbit) [0]-p, --pass <integer> Enable multipass ratecontrol- 1: First pass, creates stats file- 2: Last pass, does not overwrite stats fileInput/Output:-o, --output <string> Specify output file--sar width:height Specify Sample Aspect Ratio--fps <float|rational> Specify framerate--seek <integer> First frame to encode--frames <integer> Maximum number of frames to encode--level <string> Specify level (as defined by Annex A)--quiet Quiet ModeFiltering:--vf, --video-filter <filter0>/<filter1>/... Apply video filtering to the input fileFilter options may be specified in <filter>:<option>=<value> format.Available filters:crop:left,top,right,bottomselect_every:step,offset1[,...]
4.建立一个工程,用于将YUV转成H264
编写测试程序
代码结构
.
|-- Makefile
|-- in420.yuv
|-- inc
|-- obj
| `-- test.o
|-- out.h264
|-- src
| `-- test.cpp
|-- third_lib
| `-- x264
| |-- include
| | |-- x264.h
| | `-- x264_config.h
| `-- lib
| `-- libx264.so
`-- video_prj
test.cpp内容:
#include <stdio.h>
#include <stdlib.h>#include "stdint.h"#if defined ( __cplusplus)
extern "C"
{
#include "x264.h"
};
#else
#include "x264.h"
#endifint main(int argc, char** argv)
{int ret;int y_size;int i,j;FILE* fp_src = fopen("./in420.yuv", "rb");FILE* fp_dst = fopen("out.h264", "wb");int frame_num=50;int csp=X264_CSP_I420;int width=640,height=360;int iNal = 0;x264_nal_t* pNals = NULL;x264_t* pHandle = NULL;x264_picture_t* pPic_in = (x264_picture_t*)malloc(sizeof(x264_picture_t));x264_picture_t* pPic_out = (x264_picture_t*)malloc(sizeof(x264_picture_t));x264_param_t* pParam = (x264_param_t*)malloc(sizeof(x264_param_t));//Checkif(fp_src==NULL||fp_dst==NULL){printf("Error open files.\n");return -1;}x264_param_default(pParam);pParam->i_width = width;pParam->i_height = height;pParam->i_csp=csp;x264_param_apply_profile(pParam, x264_profile_names[5]);pHandle = x264_encoder_open(pParam);x264_picture_init(pPic_out);x264_picture_alloc(pPic_in, csp, pParam->i_width, pParam->i_height);y_size = pParam->i_width * pParam->i_height;//detect frame numberif(frame_num==0){fseek(fp_src,0,SEEK_END);switch(csp){case X264_CSP_I444:frame_num=ftell(fp_src)/(y_size*3);break;case X264_CSP_I420:frame_num=ftell(fp_src)/(y_size*3/2);break;default:printf("Colorspace Not Support.\n");return -1;}fseek(fp_src,0,SEEK_SET);}//Loop to Encodefor( i=0;i<frame_num;i++){switch(csp){case X264_CSP_I444:{fread(pPic_in->img.plane[0],y_size,1,fp_src); //Yfread(pPic_in->img.plane[1],y_size,1,fp_src); //Ufread(pPic_in->img.plane[2],y_size,1,fp_src); //Vbreak;}case X264_CSP_I420:{fread(pPic_in->img.plane[0],y_size,1,fp_src); //Yfread(pPic_in->img.plane[1],y_size/4,1,fp_src); //Ufread(pPic_in->img.plane[2],y_size/4,1,fp_src); //Vbreak;}default:{printf("Colorspace Not Support.\n");return -1;}}pPic_in->i_pts = i;ret = x264_encoder_encode(pHandle, &pNals, &iNal, pPic_in, pPic_out);if (ret< 0){printf("Error.\n");return -1;}printf("Succeed encode frame: %5d\n",i);for ( j = 0; j < iNal; ++j){fwrite(pNals[j].p_payload, 1, pNals[j].i_payload, fp_dst);}}i=0;//flush encoderwhile(1){ret = x264_encoder_encode(pHandle, &pNals, &iNal, NULL, pPic_out);if(ret==0){break;}printf("Flush 1 frame.\n");for (j = 0; j < iNal; ++j){fwrite(pNals[j].p_payload, 1, pNals[j].i_payload, fp_dst);}i++;}x264_picture_clean(pPic_in);x264_encoder_close(pHandle);pHandle = NULL;free(pPic_in);free(pPic_out);free(pParam);fclose(fp_src);fclose(fp_dst);return 0;
}
相关文章:
03-编码篇-x264编译与介绍
使用FFMPEG作编码操作时,会涉及到将yuv数据编码成h264数据,FFmpeg的libavcodec中的libx264.c会调用x264库的源码作编码: 1.x264库编译 下载X264,地址为:http://www.videolan.org/developers/x264.html,并解…...
生活自来水厂污水处理设备需要哪些
生活自来水厂是确保我们日常用水质量安全的重要设施。在自来水的生产过程中,污水处理设备是不可或缺的环节。那么,生活自来水厂的污水处理设备都有哪些呢?本文将为您详细介绍。 首先,生活自来水厂的污水处理设备主要包括预处理设备…...
Full names for abbreviations of Linux Commands
synopsis Towards/On Full names for abbreviations of Linux Commands I) website addressII) Mapping between full names and abbreviations I) website address II) Mapping between full names and abbreviations su:Swith user 切换用户,切换到ro…...
kafka下载安装部署
Apache kafka 是一个分布式的基于push-subscribe的消息系统,它具备快速、可扩展、可持久化的特点。它现在是Apache旗下的一个开源系统,作为hadoop生态系统的一部分,被各种商业公司广泛应用。它的最大的特性就是可以实时的处理大量数据以满足各…...
python包管理工具:pipenv的基本使用
很多语言都提供了环境隔离的支持,例如nodejs的node_module,golang的go mod,python也有virtualenv和pyvenv等机制。 为了建立依赖快照,通常会用pip freeze > requirements.txt 命令生成一个requirements.txt文件,在…...
AI系统ChatGPT网站系统源码AI绘画详细搭建部署教程,支持GPT语音对话+DALL-E3文生图+GPT-4多模态模型识图理解
一、前言 SparkAi创作系统是基于ChatGPT进行开发的Ai智能问答系统和Midjourney绘画系统,支持OpenAI-GPT全模型国内AI全模型。本期针对源码系统整体测试下来非常完美,可以说SparkAi是目前国内一款的ChatGPT对接OpenAI软件系统。那么如何搭建部署AI创作Ch…...
MC-4/11/03/400步进电机驱动器的主要驱动方式有哪些?
MC-4/11/03/400步进电机驱动器的主要驱动方式有哪些? 步进电机驱动器是一种将电脉冲转化为角位移的执行机构。当步进驱动器接收到一个脉冲信号,它就驱动步进电机按设定的方向转动一个固定的角度,这个固定的角度被称为“步距角”。步进电机不能…...
大数据技术原理与应用期末复习(林子雨)
大数据技术原理与应用期末复习(林子雨) Hadoop的特性HBase编程实践NoSQL的四大类型键值数据库优点:缺点: 列族数据库优点:缺点: 文档数据库优点:缺点: 图数据库优点:缺点…...
C练习——魔术师猜三位数
题目: 有一种室内互动游戏,魔术师要每位观众心里想一个三位数abc(a、b、c分别是百位、十位和个位数字),然后魔术师让观众心中记下acb、bac、bca、cab、cba五个数以及这5个数的和值。只要观众说出这个和是多少…...
three.js 使用 tweenjs绘制相机运动动画
效果: 代码: <template><div><el-container><el-main><div class"box-card-left"><div id"threejs" style"border: 1px solid red"></div><div class"box-right"…...
Oracle VARCHAR和VARCHAR2区别
在Oracle数据库中,VARCHAR和VARCHAR2是两种不同的数据类型,它们的区别如下: 1.存储空间 VARCHAR和VARCHAR2在存储空间上有所不同。在Oracle 7及以下版本中,VARCHAR类型的长度是固定的,如果存储的数据长度小于定义的长…...
HarmonyOS 开发基础(八)Row和Column
HarmonyOS 开发基础(八)Row和Column 一、Column 容器 1、容器说明: 纵向容器主轴方向:从上到下纵向交叉轴方向:从左到右横向 2、容器属性: justifyContent:设置子元素在主轴方向的对齐格式…...
Visual Studio中项目添加链接文件
这个需求在VS里面使用还真不多见,只是最近在做项目的版本编号的时候遇到一个头大的问题,我一个解决方案下面有几十个类库,再发布的时候这几十个类库的版本号必须要统一,之前我们都是在单个的AssemblyInfo.cs里面去改相关的信息&am…...
做一个个人博客第一步该怎么做?
做一个个人博客第一步该怎么做? 好多零基础的同学们不知道怎么迈出第一步。 那么,就找一个现成的模板学一学呗,毕竟我们是高贵的Ctrl c v 工程师。 但是这样也有个问题,那就是,那些模板都,太!…...
vue前端开发自学练习,Props数据传递-类型校验,默认值的设置!
vue前端开发自学练习,Props数据传递-类型校验,默认值的设置! 实际上,vue开发框架的时候,充分考虑到了前端开发人员可能会遇到的各种各样的情况,比如大家经常遇到的,数据类型的校验,再比如,默认…...
Fooocus 使用笔记
目录 换装,换脸,修复畸形 比较和使用教程: 安装教程: github地址: 换装,换脸,修复畸形 🔥迄今最全!Fooocus AI绘图 详细教程 AI换装 AI换脸 AI修复畸形 - 西瓜视频 …...
18. 从零用Rust编写正反向代理, 主动式健康检查源码实现
wmproxy wmproxy是由Rust编写,已实现http/https代理,socks5代理, 反向代理,静态文件服务器,内网穿透,配置热更新等, 后续将实现websocket代理等,同时会将实现过程分享出来ÿ…...
[DM8] 达梦8配置兼容Oracle
查看版本信息 select *,id_code from v$version; 查询解释: DM Database Server 64 V8 1-1-190-21.03.12-136419-ENT 64 版本位数标识,64表示为64位版本,无64则表示为32位版本 V8 大版本号,目前主要是V7、V8 1-1-190…...
【Pytorch简介】1.Introduction 简介
Introduction 简介 大多数机器学习工作流涉及处理数据、创建模型、使用超参数优化模型,以及保存,然后推理已训练的模型。 本模块介绍在 PyTorch(一种常用的 Python ML 框架)中实现的完整机器学习 (ML) 工作流。 我们使用 Fashio…...
什么是Session以及如何在 NestJS 项目中的优雅管理 Session
前言 Web开发中一个常见的问题是用户身份的管理和状态保持。Session 就是处理这个问题的一个传统技术。在这篇文章中,我们将探讨Session是什么,为什么我们需要Session,以及在NestJS项目中如何优雅地管理Session。 什么是Session 众所周知&…...
后进先出(LIFO)详解
LIFO 是 Last In, First Out 的缩写,中文译为后进先出。这是一种数据结构的工作原则,类似于一摞盘子或一叠书本: 最后放进去的元素最先出来 -想象往筒状容器里放盘子: (1)你放进的最后一个盘子(…...
Java 语言特性(面试系列2)
一、SQL 基础 1. 复杂查询 (1)连接查询(JOIN) 内连接(INNER JOIN):返回两表匹配的记录。 SELECT e.name, d.dept_name FROM employees e INNER JOIN departments d ON e.dept_id d.dept_id; 左…...
golang循环变量捕获问题
在 Go 语言中,当在循环中启动协程(goroutine)时,如果在协程闭包中直接引用循环变量,可能会遇到一个常见的陷阱 - 循环变量捕获问题。让我详细解释一下: 问题背景 看这个代码片段: fo…...
Cesium1.95中高性能加载1500个点
一、基本方式: 图标使用.png比.svg性能要好 <template><div id"cesiumContainer"></div><div class"toolbar"><button id"resetButton">重新生成点</button><span id"countDisplay&qu…...
SCAU期末笔记 - 数据分析与数据挖掘题库解析
这门怎么题库答案不全啊日 来简单学一下子来 一、选择题(可多选) 将原始数据进行集成、变换、维度规约、数值规约是在以下哪个步骤的任务?(C) A. 频繁模式挖掘 B.分类和预测 C.数据预处理 D.数据流挖掘 A. 频繁模式挖掘:专注于发现数据中…...
Python爬虫实战:研究feedparser库相关技术
1. 引言 1.1 研究背景与意义 在当今信息爆炸的时代,互联网上存在着海量的信息资源。RSS(Really Simple Syndication)作为一种标准化的信息聚合技术,被广泛用于网站内容的发布和订阅。通过 RSS,用户可以方便地获取网站更新的内容,而无需频繁访问各个网站。 然而,互联网…...
STM32标准库-DMA直接存储器存取
文章目录 一、DMA1.1简介1.2存储器映像1.3DMA框图1.4DMA基本结构1.5DMA请求1.6数据宽度与对齐1.7数据转运DMA1.8ADC扫描模式DMA 二、数据转运DMA2.1接线图2.2代码2.3相关API 一、DMA 1.1简介 DMA(Direct Memory Access)直接存储器存取 DMA可以提供外设…...
SpringTask-03.入门案例
一.入门案例 启动类: package com.sky;import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cache.annotation.EnableCach…...
C++ 设计模式 《小明的奶茶加料风波》
👨🎓 模式名称:装饰器模式(Decorator Pattern) 👦 小明最近上线了校园奶茶配送功能,业务火爆,大家都在加料: 有的同学要加波霸 🟤,有的要加椰果…...
Java后端检查空条件查询
通过抛出运行异常:throw new RuntimeException("请输入查询条件!");BranchWarehouseServiceImpl.java // 查询试剂交易(入库/出库)记录Overridepublic List<BranchWarehouseTransactions> queryForReagent(Branch…...
