mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
483bfdacd1
@ -1,57 +1,27 @@
|
||||
Docker 指南:Docker 化 Python Django 应用程序
|
||||
如何 Docker 化 Python Django 应用程序
|
||||
======
|
||||
|
||||
### 目录
|
||||
|
||||
1. [我们要做什么?][6]
|
||||
|
||||
2. [步骤 1 - 安装 Docker-ce][7]
|
||||
|
||||
3. [步骤 2 - 安装 Docker-compose][8]
|
||||
|
||||
4. [步骤 3 - 配置项目环境][9]
|
||||
1. [创建一个新的 requirements.txt 文件][1]
|
||||
|
||||
2. [创建 Nginx 虚拟主机文件 django.conf][2]
|
||||
|
||||
3. [创建 Dockerfile][3]
|
||||
|
||||
4. [创建 Docker-compose 脚本][4]
|
||||
|
||||
5. [配置 Django 项目][5]
|
||||
|
||||
5. [步骤 4 - 构建并运行 Docker 镜像][10]
|
||||
|
||||
6. [步骤 5 - 测试][11]
|
||||
|
||||
7. [参考][12]
|
||||
|
||||
|
||||
Docker 是一个开源项目,为开发人员和系统管理员提供了一个开放平台,作为一个轻量级容器,它可以在任何地方构建,打包和运行应用程序。Docker 在软件容器中自动部署应用程序。
|
||||
Docker 是一个开源项目,为开发人员和系统管理员提供了一个开放平台,可以将应用程序构建、打包为一个轻量级容器,并在任何地方运行。Docker 会在软件容器中自动部署应用程序。
|
||||
|
||||
Django 是一个用 Python 编写的 Web 应用程序框架,遵循 MVC(模型-视图-控制器)架构。它是免费的,并在开源许可下发布。它速度很快,旨在帮助开发人员尽快将他们的应用程序上线。
|
||||
|
||||
在本教程中,我将逐步向你展示在 Ubuntu 16.04 如何为现有的 Django 应用程序创建 docker 镜像。我们将学习如何 docker 化一个 Python Django 应用程序,然后使用一个 docker-compose 脚本将应用程序作为容器部署到 docker 环境。
|
||||
在本教程中,我将逐步向你展示在 Ubuntu 16.04 中如何为现有的 Django 应用程序创建 docker 镜像。我们将学习如何 docker 化一个 Python Django 应用程序,然后使用一个 `docker-compose` 脚本将应用程序作为容器部署到 docker 环境。
|
||||
|
||||
为了部署我们的 Python Django 应用程序,我们需要其他 docker 镜像:一个用于 Web 服务器的 nginx docker 镜像和用于数据库的 PostgreSQL 镜像。
|
||||
为了部署我们的 Python Django 应用程序,我们需要其它 docker 镜像:一个用于 Web 服务器的 nginx docker 镜像和用于数据库的 PostgreSQL 镜像。
|
||||
|
||||
### 我们要做什么?
|
||||
|
||||
1. 安装 Docker-ce
|
||||
|
||||
2. 安装 Docker-compose
|
||||
|
||||
3. 配置项目环境
|
||||
|
||||
4. 构建并运行
|
||||
|
||||
5. 测试
|
||||
|
||||
### 步骤 1 - 安装 Docker-ce
|
||||
|
||||
在本教程中,我们将重 docker 仓库安装 docker-ce 社区版。我们将安装 docker-ce 社区版和 docker-compose,其支持 compose 文件版本 3(to 校正者:此处不太明白具体意思)。
|
||||
在本教程中,我们将从 docker 仓库安装 docker-ce 社区版。我们将安装 docker-ce 社区版和 `docker-compose`(其支持 compose 文件版本 3)。
|
||||
|
||||
在安装 docker-ce 之前,先使用 apt 命令安装所需的 docker 依赖项。
|
||||
在安装 docker-ce 之前,先使用 `apt` 命令安装所需的 docker 依赖项。
|
||||
|
||||
```
|
||||
sudo apt install -y \
|
||||
@ -71,7 +41,7 @@ sudo add-apt-repository \
|
||||
stable"
|
||||
```
|
||||
|
||||
[![安装 Docker-ce](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/1.png)][14]
|
||||
[![安装 Docker-ce](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/1.png)][14]
|
||||
|
||||
更新仓库并安装 docker-ce。
|
||||
|
||||
@ -87,16 +57,16 @@ systemctl start docker
|
||||
systemctl enable docker
|
||||
```
|
||||
|
||||
接着,我们将添加一个名为 'omar' 的新用户并将其添加到 docker 组。
|
||||
接着,我们将添加一个名为 `omar` 的新用户并将其添加到 `docker` 组。
|
||||
|
||||
```
|
||||
useradd -m -s /bin/bash omar
|
||||
usermod -a -G docker omar
|
||||
```
|
||||
|
||||
[![启动 Docker](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/2.png)][15]
|
||||
[![启动 Docker](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/2.png)][15]
|
||||
|
||||
以 omar 用户身份登录并运行 docker 命令,如下所示。
|
||||
以 `omar` 用户身份登录并运行 `docker` 命令,如下所示。
|
||||
|
||||
```
|
||||
su - omar
|
||||
@ -107,13 +77,13 @@ docker run hello-world
|
||||
|
||||
[![检查 Docker 安装](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/3.png)][16]
|
||||
|
||||
Docker-ce 安装已经完成。
|
||||
Docker-ce 安装已经完成。
|
||||
|
||||
### 步骤 2 - 安装 Docker-compose
|
||||
### 步骤 2 - 安装 Docker-compose
|
||||
|
||||
在本教程中,我们将使用最新的 docker-compose 支持 compose 文件版本 3。我们将手动安装 docker-compose。
|
||||
在本教程中,我们将使用支持 compose 文件版本 3 的最新 `docker-compose`。我们将手动安装 `docker-compose`。
|
||||
|
||||
使用 curl 命令将最新版本的 docker-compose 下载到 `/usr/local/bin` 目录,并使用 chmod 命令使其有执行权限。
|
||||
使用 `curl` 命令将最新版本的 `docker-compose` 下载到 `/usr/local/bin` 目录,并使用 `chmod` 命令使其有执行权限。
|
||||
|
||||
运行以下命令:
|
||||
|
||||
@ -122,7 +92,7 @@ sudo curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-c
|
||||
sudo chmod +x /usr/local/bin/docker-compose
|
||||
```
|
||||
|
||||
现在检查 docker-compose 版本。
|
||||
现在检查 `docker-compose` 版本。
|
||||
|
||||
```
|
||||
docker-compose version
|
||||
@ -132,26 +102,26 @@ docker-compose version
|
||||
|
||||
[![安装 Docker-compose](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/4.png)][17]
|
||||
|
||||
已安装支持 compose 文件版本 3 的 docker-compose 最新版本。
|
||||
已安装支持 compose 文件版本 3 的 `docker-compose` 最新版本。
|
||||
|
||||
### 步骤 3 - 配置项目环境
|
||||
|
||||
在这一步中,我们将配置 Python Django 项目环境。我们将创建新目录 'guide01',并使其成为我们项目文件的主目录,例如 Dockerfile,Django 项目,nginx 配置文件等。
|
||||
在这一步中,我们将配置 Python Django 项目环境。我们将创建新目录 `guide01`,并使其成为我们项目文件的主目录,例如包括 Dockerfile、Django 项目、nginx 配置文件等。
|
||||
|
||||
登录到 'omar' 用户。
|
||||
登录到 `omar` 用户。
|
||||
|
||||
```
|
||||
su - omar
|
||||
```
|
||||
|
||||
创建一个新目录 'guide01',并进入目录。
|
||||
创建一个新目录 `guide01`,并进入目录。
|
||||
|
||||
```
|
||||
mkdir -p guide01
|
||||
cd guide01/
|
||||
```
|
||||
|
||||
现在在 'guide01' 目录下,创建两个新目录 'project' 和 'config'。
|
||||
现在在 `guide01` 目录下,创建两个新目录 `project` 和 `config`。
|
||||
|
||||
```
|
||||
mkdir project/ config/
|
||||
@ -159,118 +129,151 @@ mkdir project/ config/
|
||||
|
||||
注意:
|
||||
|
||||
* 'project' 目录:我们所有的 python Django 项目文件都将放在该目录中。
|
||||
* `project` 目录:我们所有的 python Django 项目文件都将放在该目录中。
|
||||
* `config` 目录:项目配置文件的目录,包括 nginx 配置文件、python pip 的`requirements.txt` 文件等。
|
||||
|
||||
* 'config' 目录:项目配置文件的目录,包括 nginx 配置文件,python pip requirements 文件等。
|
||||
#### 创建一个新的 requirements.txt 文件
|
||||
|
||||
### 创建一个新的 requirements.txt 文件
|
||||
|
||||
接下来,使用 vim 命令在 'config' 目录中创建一个新的 requirements.txt 文件
|
||||
接下来,使用 `vim` 命令在 `config` 目录中创建一个新的 `requirements.txt` 文件。
|
||||
|
||||
```
|
||||
vim config/requirements.txt
|
||||
```
|
||||
|
||||
粘贴下面的配置。
|
||||
粘贴下面的配置:
|
||||
|
||||
```
|
||||
Django==2.0.4
|
||||
gunicorn==19.7.0
|
||||
psycopg2==2.7.4
|
||||
gunicorn==19.7.0
|
||||
psycopg2==2.7.4
|
||||
```
|
||||
|
||||
保存并退出。
|
||||
|
||||
### 创建 Dockerfile
|
||||
#### 创建 Nginx 虚拟主机文件 django.conf
|
||||
|
||||
在 'guide01' 目录下创建新文件 'Dockerfile'。
|
||||
在 `config` 目录下创建 nginx 配置目录并添加虚拟主机配置文件 `django.conf`。
|
||||
|
||||
运行以下命令。
|
||||
```
|
||||
mkdir -p config/nginx/
|
||||
vim config/nginx/django.conf
|
||||
```
|
||||
|
||||
粘贴下面的配置:
|
||||
|
||||
```
|
||||
upstream web {
|
||||
ip_hash;
|
||||
server web:8000;
|
||||
}
|
||||
|
||||
# portal
|
||||
server {
|
||||
location / {
|
||||
proxy_pass http://web/;
|
||||
}
|
||||
listen 8000;
|
||||
server_name localhost;
|
||||
|
||||
location /static {
|
||||
autoindex on;
|
||||
alias /src/static/;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
保存并退出。
|
||||
|
||||
#### 创建 Dockerfile
|
||||
|
||||
在 `guide01` 目录下创建新文件 `Dockerfile`。
|
||||
|
||||
运行以下命令:
|
||||
|
||||
```
|
||||
vim Dockerfile
|
||||
```
|
||||
|
||||
现在粘贴下面的 Dockerfile 脚本。
|
||||
现在粘贴下面的 Dockerfile 脚本:
|
||||
|
||||
```
|
||||
FROM python:3.5-alpine
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
|
||||
RUN apk update && \
|
||||
apk add --virtual build-deps gcc python-dev musl-dev && \
|
||||
apk add postgresql-dev bash
|
||||
RUN apk update && \
|
||||
apk add --virtual build-deps gcc python-dev musl-dev && \
|
||||
apk add postgresql-dev bash
|
||||
|
||||
RUN mkdir /config
|
||||
ADD /config/requirements.txt /config/
|
||||
RUN pip install -r /config/requirements.txt
|
||||
RUN mkdir /src
|
||||
WORKDIR /src
|
||||
RUN mkdir /config
|
||||
ADD /config/requirements.txt /config/
|
||||
RUN pip install -r /config/requirements.txt
|
||||
RUN mkdir /src
|
||||
WORKDIR /src
|
||||
```
|
||||
|
||||
保存并退出。
|
||||
|
||||
注意:
|
||||
|
||||
我们想要为我们的 Django 项目构建基于 Alpine Linux 的 Docker 镜像,Alpine 是最小的 Linux 版本。我们的 Django 项目将运行在带有 Python3.5 的 Alpine Linux 上,并添加 postgresql-dev 包以支持 PostgreSQL 数据库。然后,我们将使用 python pip 命令安装在 'requirements.txt' 上列出的所有 Python 包,并为我们的项目创建新目录 '/src'。
|
||||
我们想要为我们的 Django 项目构建基于 Alpine Linux 的 Docker 镜像,Alpine 是最小的 Linux 版本。我们的 Django 项目将运行在带有 Python 3.5 的 Alpine Linux 上,并添加 postgresql-dev 包以支持 PostgreSQL 数据库。然后,我们将使用 python `pip` 命令安装在 `requirements.txt` 上列出的所有 Python 包,并为我们的项目创建新目录 `/src`。
|
||||
|
||||
### 创建 Docker-compose 脚本
|
||||
#### 创建 Docker-compose 脚本
|
||||
|
||||
使用 [vim][18] 命令在 'guide01' 目录下创建 'docker-compose.yml' 文件。
|
||||
使用 [vim][18] 命令在 `guide01` 目录下创建 `docker-compose.yml` 文件。
|
||||
|
||||
```
|
||||
vim docker-compose.yml
|
||||
```
|
||||
|
||||
粘贴以下配置内容。
|
||||
粘贴以下配置内容:
|
||||
|
||||
```
|
||||
version: '3'
|
||||
services:
|
||||
db:
|
||||
image: postgres:10.3-alpine
|
||||
container_name: postgres01
|
||||
nginx:
|
||||
image: nginx:1.13-alpine
|
||||
container_name: nginx01
|
||||
ports:
|
||||
- "8000:8000"
|
||||
volumes:
|
||||
- ./project:/src
|
||||
- ./config/nginx:/etc/nginx/conf.d
|
||||
depends_on:
|
||||
- web
|
||||
web:
|
||||
build: .
|
||||
container_name: django01
|
||||
command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py collectstatic --noinput && gunicorn hello_django.wsgi -b 0.0.0.0:8000"
|
||||
depends_on:
|
||||
- db
|
||||
volumes:
|
||||
- ./project:/src
|
||||
expose:
|
||||
- "8000"
|
||||
restart: always
|
||||
services:
|
||||
db:
|
||||
image: postgres:10.3-alpine
|
||||
container_name: postgres01
|
||||
nginx:
|
||||
image: nginx:1.13-alpine
|
||||
container_name: nginx01
|
||||
ports:
|
||||
- "8000:8000"
|
||||
volumes:
|
||||
- ./project:/src
|
||||
- ./config/nginx:/etc/nginx/conf.d
|
||||
depends_on:
|
||||
- web
|
||||
web:
|
||||
build: .
|
||||
container_name: django01
|
||||
command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py collectstatic --noinput && gunicorn hello_django.wsgi -b 0.0.0.0:8000"
|
||||
depends_on:
|
||||
- db
|
||||
volumes:
|
||||
- ./project:/src
|
||||
expose:
|
||||
- "8000"
|
||||
restart: always
|
||||
```
|
||||
|
||||
保存并退出。
|
||||
|
||||
注意:
|
||||
|
||||
使用这个 docker-compose 文件脚本,我们将创建三个服务。使用 PostgreSQL alpine Linux 创建名为 'db' 的数据库服务,再次使用 Nginx alpine Linux 创建 'nginx' 服务,并使用从 Dockerfile 生成的自定义 docker 镜像创建我们的 python Django 容器。
|
||||
使用这个 `docker-compose` 文件脚本,我们将创建三个服务。使用 alpine Linux 版的 PostgreSQL 创建名为 `db` 的数据库服务,再次使用 alpine Linux 版的 Nginx 创建 `nginx` 服务,并使用从 Dockerfile 生成的自定义 docker 镜像创建我们的 python Django 容器。
|
||||
|
||||
[![配置项目环境](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/5.png)][19]
|
||||
[![配置项目环境](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/5.png)][19]
|
||||
|
||||
### 配置 Django 项目
|
||||
#### 配置 Django 项目
|
||||
|
||||
将 Django 项目文件复制到 'project' 目录。
|
||||
将 Django 项目文件复制到 `project` 目录。
|
||||
|
||||
```
|
||||
cd ~/django
|
||||
cp -r * ~/guide01/project/
|
||||
```
|
||||
|
||||
进入 'project' 目录并编辑应用程序设置 'settings.py'。
|
||||
进入 `project` 目录并编辑应用程序设置 `settings.py`。
|
||||
|
||||
```
|
||||
cd ~/guide01/project/
|
||||
@ -279,29 +282,29 @@ vim hello_django/settings.py
|
||||
|
||||
注意:
|
||||
|
||||
我们将部署名为 'hello_django' 的简单 Django 应用程序。
|
||||
我们将部署名为 “hello_django” 的简单 Django 应用程序。
|
||||
|
||||
在 'ALLOW_HOSTS' 行中,添加服务名称 'web'。
|
||||
在 `ALLOW_HOSTS` 行中,添加服务名称 `web`。
|
||||
|
||||
```
|
||||
ALLOW_HOSTS = ['web']
|
||||
```
|
||||
|
||||
现在更改数据库设置,我们将使用 PostgreSQL 数据库,'db' 数据库作为服务运行,使用默认用户和密码。
|
||||
现在更改数据库设置,我们将使用 PostgreSQL 数据库来运行名为 `db` 的服务,使用默认用户和密码。
|
||||
|
||||
```
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||
'NAME': 'postgres',
|
||||
'USER': 'postgres',
|
||||
'HOST': 'db',
|
||||
'PORT': 5432,
|
||||
}
|
||||
}
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||
'NAME': 'postgres',
|
||||
'USER': 'postgres',
|
||||
'HOST': 'db',
|
||||
'PORT': 5432,
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
至于 'STATIC_ROOT' 配置目录,将此行添加到文件行的末尾。
|
||||
至于 `STATIC_ROOT` 配置目录,将此行添加到文件行的末尾。
|
||||
|
||||
```
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
|
||||
@ -309,21 +312,21 @@ STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
|
||||
|
||||
保存并退出。
|
||||
|
||||
[![配置 Django 项目](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/6.png)][20]
|
||||
[![配置 Django 项目](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/6.png)][20]
|
||||
|
||||
现在我们准备在 docker 容器下构建和运行 Django 项目。
|
||||
|
||||
### 步骤 4 - 构建并运行 Docker 镜像
|
||||
|
||||
在这一步中,我们想要使用 'guide01' 目录中的配置为我们的 Django 项目构建一个 Docker 镜像。
|
||||
在这一步中,我们想要使用 `guide01` 目录中的配置为我们的 Django 项目构建一个 Docker 镜像。
|
||||
|
||||
进入 'guide01' 目录。
|
||||
进入 `guide01` 目录。
|
||||
|
||||
```
|
||||
cd ~/guide01/
|
||||
```
|
||||
|
||||
现在使用 docker-compose 命令构建 docker 镜像。
|
||||
现在使用 `docker-compose` 命令构建 docker 镜像。
|
||||
|
||||
```
|
||||
docker-compose build
|
||||
@ -331,7 +334,7 @@ docker-compose build
|
||||
|
||||
[![运行 docker 镜像](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/7.png)][21]
|
||||
|
||||
启动 docker-compose 脚本中的所有服务。
|
||||
启动 `docker-compose` 脚本中的所有服务。
|
||||
|
||||
```
|
||||
docker-compose up -d
|
||||
@ -348,7 +351,7 @@ docker-compose ps
|
||||
docker-compose images
|
||||
```
|
||||
|
||||
现在,你将在系统上运行三个容器并列出 Docker 镜像,如下所示。
|
||||
现在,你将在系统上运行三个容器,列出 Docker 镜像,如下所示。
|
||||
|
||||
[![docke-compose ps 命令](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/9.png)][23]
|
||||
|
||||
@ -356,17 +359,19 @@ docker-compose images
|
||||
|
||||
### 步骤 5 - 测试
|
||||
|
||||
打开 Web 浏览器并使用端口 8000 键入服务器地址,我的是:http://ovh01:8000/
|
||||
打开 Web 浏览器并使用端口 8000 键入服务器地址,我的是:`http://ovh01:8000/`。
|
||||
|
||||
现在你将获得默认的 Django 主页。
|
||||
现在你将看到默认的 Django 主页。
|
||||
|
||||
[![默认 Django 项目主页](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/10.png)][24]
|
||||
|
||||
接下来,通过在 URL 上添加 “/admin” 路径来测试管理页面。
|
||||
接下来,通过在 URL 上添加 `/admin` 路径来测试管理页面。
|
||||
|
||||
```
|
||||
http://ovh01:8000/admin/
|
||||
```
|
||||
|
||||
然后你将会看到 Django admin 登录页面。
|
||||
然后你将会看到 Django 管理登录页面。
|
||||
|
||||
[![Django administration](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/11.png)][25]
|
||||
|
||||
@ -383,7 +388,7 @@ via: https://www.howtoforge.com/tutorial/docker-guide-dockerizing-python-django-
|
||||
|
||||
作者:[Muhammad Arul][a]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,113 +0,0 @@
|
||||
Grave Accent翻译中 How To Enable Hardware Accelerated Video Decoding In Chromium On Ubuntu Or Linux Mint
|
||||
======
|
||||
You may have noticed that watching HD videos from Youtube and other similar websites in Google Chrome or Chromium browsers on Linux considerably increases your CPU usage and, if you use a laptop, it gets quite hot and the battery drains very quickly. That's because Chrome / Chromium (Firefox too but there's no way to force this) doesn't support hardware accelerated video decoding on Linux.
|
||||
|
||||
**This article explains how to install a Chromium development build which includes a patch that enables VA-API on Linux, bringing support for GPU accelerated video decoding, which should significantly decrease the CPU usage when watching HD videos online. The instructions cover only Intel and Nvidia graphics cards, as I don't have an ATI/AMD graphics card to try this, nor do I have experience with such graphics cards.**
|
||||
|
||||
This is Chromium from the Ubuntu (18.04) repositories without GPU accelerated video decoding playing a 1080p YouTube video:
|
||||
|
||||
![](https://4.bp.blogspot.com/-KtUQni2PMvE/W3KlJ62yLLI/AAAAAAAABW4/NrNVFaTAkZ8AmwqWwRvWD6czT51ni-R-gCLcBGAs/s1600/chromium-default-no-accel.png)
|
||||
|
||||
The same 1080p YouTube video playing in Chromium with the VA-API patch and hardware accelerated video decode enabled on Ubuntu 18.04:
|
||||
|
||||
![](https://4.bp.blogspot.com/-0c-wb4UNhW8/W3KlQBfeFnI/AAAAAAAABW8/WVUAYzM6hA8wRTlCcrPXPMpoXoFVR6b1QCLcBGAs/s1600/chromium-hardware-acceleration-enabled.png)
|
||||
|
||||
Notice the CPU usage in the screenshots. Both screenshots were taken on my old, but still quite powerful desktop. On my laptop, the Chromium CPU usage without hardware acceleration goes way higher.
|
||||
|
||||
The _Enable VAVDA, VAVEA and VAJDA on linux with VAAPI only_ " was was initially submitted to Chromium more than a year ago, but it has yet to be merged.
|
||||
|
||||
Chrome has an option to override the software rendering list (
|
||||
|
||||
`#ignore-gpu-blacklist`
|
||||
|
||||
), but this option does not enable hardware accelerated video decoding. After enabling this option, you may find the following when visiting
|
||||
|
||||
`chrome://gpu`
|
||||
|
||||
: " _Video Decode: Hardware accelerated_ ", but this does not mean it actually works. Open a HD video on YouTube and check the CPU usage in a tool such as
|
||||
|
||||
`htop`
|
||||
|
||||
(this is what I'm using in the screenshots above to check the CPU usage) - you should see high CPU usage because GPU video decoding is not actually enabled. There's also a section below for how to check if you're actually using hardware accelerated video decoding.
|
||||
|
||||
**The patches used by the Chromium Ubuntu builds with VA-API enabled used in this article are available[here][1].**
|
||||
|
||||
### Installing and using Chromium browser with VA-API support on Ubuntu or Linux Mint
|
||||
|
||||
**It should be clear to everyone reading this that Chromium Dev Branch is not considered stable. So you might find bugs, it may crash, etc. It works fine right now but who knows what may happen after some update.**
|
||||
|
||||
**What's more, the Chromium Dev Branch PPA requires you to perform some extra steps if you want to enable Widevine support** (so you can play Netflix videos and paid YouTube videos, etc.), **or if you need features like Sync** (which needs registering an API key and setting it up on your system). Instructions for performing these tweaks are explained in the
|
||||
|
||||
Chromium with the VA-API patch is also available for some other Linux distributions, in third-party repositories, like
|
||||
|
||||
**1\. Install Chromium Dev Branch with VA-API support.**
|
||||
|
||||
There's a Chromium Beta PPA with the VA-API patch, but it lacks vdpau-video for Ubuntu 18.04. If you want, you can use the `vdpau-va-driver` from the You can add the Chromium
|
||||
```
|
||||
sudo add-apt-repository ppa:saiarcot895/chromium-dev
|
||||
sudo apt-get update
|
||||
sudo apt install chromium-browser
|
||||
|
||||
```
|
||||
|
||||
**2\. Install the VA-API driver**
|
||||
|
||||
For Intel graphics cards, you'll need to install the `i965-va-driver` package (it may already be installed):
|
||||
```
|
||||
sudo apt install i965-va-driver
|
||||
|
||||
```
|
||||
|
||||
For Nvidia graphics cards (it should work with both the open source Nouveau drivers and the proprietary Nvidia drivers), install `vdpau-va-driver` :
|
||||
```
|
||||
sudo apt install vdpau-va-driver
|
||||
|
||||
```
|
||||
|
||||
**3\. Enable the Hardware-accelerated video option in Chromium.**
|
||||
|
||||
Copy and paste the following in the Chrome URL bar: `chrome://flags/#enable-accelerated-video` (or search for the `Hardware-accelerated video` option in `chrome://flags`) and enable it, then restart Chromium browser.
|
||||
|
||||
On a default Google Chrome / Chromium build, this option shows as unavailable, but you'll be able to enable it now because we've used the VA-API enabled Chromium build.
|
||||
|
||||
**4\. Install[h264ify][2] Chrome extension.**
|
||||
|
||||
YouTube (and probably some other websites as well) uses VP8 or VP9 video codecs by default, and many GPUs don't support hardware decoding for this codec. The h264ify extension will force YouTube to use H.264, which should be supported by most GPUs, instead of VP8/VP9.
|
||||
|
||||
This extension can also block 60fps videos, useful on lower end machines.
|
||||
|
||||
You can check the codec used by a YouTube video by right clicking on the video and selecting `Stats for nerds` . With the h264ify extension enabled, you should see avc / mp4a as the codecs. Without this extension, the codec should be something like vp09 / opus.
|
||||
|
||||
### How to check if Chromium is using GPU video decoding
|
||||
|
||||
Open a video on YouTube. Next, open a new tab in Chromium and enter the following in the URL bar: `chrome://media-internals` .
|
||||
|
||||
On the `chrome://media-internals` tab, click on the video url (in order to expand it), scroll down and look under `Player Properties` , and you should find the `video_decoder` property. If the `video_decoder` value is `GpuVideoDecoder` it means that the video that's currently playing on YouTube in the other tab is using hardware-accelerated video decoding.
|
||||
|
||||
![](https://4.bp.blogspot.com/-COBJWVT_Y0Q/W3KnG7AeHsI/AAAAAAAABXM/W2XAJA_S0BIHug4eQKTMOdIfXHhgkXhhQCLcBGAs/s1600/chromium-gpuvideodecoder-linux.png)
|
||||
|
||||
If it says `FFmpegVideoDecoder` or `VpxVideoDecoder` , accelerated video decoding is not working, or maybe you forgot to install or disabled the h264ify Chrome extension.
|
||||
|
||||
If it's not working, you could try to debug it by running `chromium-browser` from the command line and see if it shows any VA-API related errors. You can also run `vainfo` (install it in Ubuntu or Linux Mint: `sudo apt install vainfo`) and `vdpauinfo` (for Nvidia; install it in Ubuntu or Linux Mint: `sudo apt install vdpauinfo`) and see if it shows an error.
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linuxuprising.com/2018/08/how-to-enable-hardware-accelerated.html
|
||||
|
||||
作者:[Logix][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://plus.google.com/118280394805678839070
|
||||
[1]:https://github.com/saiarcot895/chromium-ubuntu-build/tree/master/debian/patches
|
||||
[2]:https://chrome.google.com/webstore/detail/h264ify/aleakchihdccplidncghkekgioiakgal
|
||||
[3]:https://chromium-review.googlesource.com/c/chromium/src/+/532294
|
||||
[4]:https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-dev
|
||||
[5]:https://aur.archlinux.org/packages/?O=0&SeB=nd&K=chromium+vaapi&outdated=&SB=n&SO=a&PP=50&do_Search=Go
|
||||
[6]:https://aur.archlinux.org/packages/libva-vdpau-driver-chromium/
|
||||
[7]:https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-beta
|
||||
[8]:https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-dev/+packages
|
@ -1,345 +0,0 @@
|
||||
idea2act translating
|
||||
|
||||
Turn your vi editor into a productivity powerhouse
|
||||
======
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/checklist_hands_team_collaboration.png?itok=u82QepPk)
|
||||
|
||||
A versatile and powerful editor, vi includes a rich set of potent commands that make it a popular choice for many users. This article specifically looks at commands that are not enabled by default in vi but are nevertheless useful. The commands recommended here are expected to be set in a vi configuration file. Though it is possible to enable commands individually from each vi session, the purpose of this article is to create a highly productive environment out of the box.
|
||||
|
||||
### Before you begin
|
||||
|
||||
While "vim" is the technically correct name of the newer version of the vi editor, this article refers to it as "vi." vimrc is the configuration file used by vim.
|
||||
|
||||
The commands or configurations discussed here go into the vi startup configuration file, vimrc, located in the user home directory. Follow the instructions below to set the commands in vimrc:
|
||||
|
||||
(Note: The vimrc file is also used for system-wide configurations in Linux, such as `/etc/vimrc` or `/etc/vim/vimrc`. In this article, we'll consider only user-specific vimrc, present in user home folder.)
|
||||
|
||||
In Linux:
|
||||
|
||||
* Open the file with `vi $HOME/.vimrc`
|
||||
* Type or copy/paste the commands in the cheat sheet at the end of this article
|
||||
* Save and close (`:wq`)
|
||||
|
||||
|
||||
|
||||
In Windows:
|
||||
|
||||
* First, [install gvim][1]
|
||||
* Open gvim
|
||||
* Click Edit --> Startup settings, which opens the _vimrc file
|
||||
* Type or copy/paste the commands in the cheat sheet at the end of this article
|
||||
* Click File --> Save
|
||||
|
||||
|
||||
|
||||
Let's delve into the individual vi productivity commands. These commands are classified into the following categories:
|
||||
|
||||
1. Indentation & Tabs
|
||||
2. Display & Format
|
||||
3. Search
|
||||
4. Browse & Scroll
|
||||
5. Spell
|
||||
6. Miscellaneous
|
||||
|
||||
|
||||
|
||||
### 1\. Indentation & Tabs
|
||||
|
||||
To automatically align the indentation of a line in a file:
|
||||
```
|
||||
set autoindent
|
||||
|
||||
```
|
||||
|
||||
Smart Indent uses the code syntax and style to align:
|
||||
```
|
||||
set smartindent
|
||||
|
||||
```
|
||||
|
||||
Tip: vi is language-aware and provides a default setting that works efficiently based on the programming language used in your file. There are many default configuration commands, including `axs cindent`, `cinoptions`, `indentexpr`, etc., which are not explained here. `syn` is a helpful command that shows or sets the file syntax.
|
||||
|
||||
To set the number of spaces to display for a tab:
|
||||
```
|
||||
set tabstop=4
|
||||
|
||||
```
|
||||
|
||||
To set the number of spaces to display for a “shift operation” (such as ‘>>’ or ‘<<’):
|
||||
```
|
||||
set shiftwidth=4
|
||||
|
||||
```
|
||||
|
||||
If you prefer to use spaces instead of tabs, this option inserts spaces when the Tab key is pressed. This may cause problems for languages such as Python that rely on tabs instead of spaces. In such cases, you may set this option based on the file type (see `autocmd`).
|
||||
```
|
||||
set expandtab
|
||||
|
||||
```
|
||||
|
||||
### 2\. Display & Format
|
||||
|
||||
To show line numbers:
|
||||
```
|
||||
set number
|
||||
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture01.png)
|
||||
|
||||
To wrap text when it crosses the maximum line width:
|
||||
```
|
||||
set textwidth=80
|
||||
|
||||
```
|
||||
|
||||
To wrap text based on a number of columns from the right side:
|
||||
```
|
||||
set wrapmargin=2
|
||||
|
||||
```
|
||||
|
||||
To identify open and close brace positions when you traverse through the file:
|
||||
```
|
||||
set showmatch
|
||||
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture02-03.jpg)
|
||||
|
||||
### 3\. Search
|
||||
|
||||
To highlight the searched term in a file:
|
||||
```
|
||||
set hlsearch
|
||||
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture04.png)
|
||||
|
||||
To perform incremental searches as you type:
|
||||
```
|
||||
set incsearch
|
||||
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/picture05.png)
|
||||
|
||||
To search ignoring case (many users prefer not to use this command; set it only if you think it will be useful):
|
||||
```
|
||||
set ignorecase
|
||||
|
||||
```
|
||||
|
||||
To search without considering `ignorecase` when both `ignorecase` and `smartcase` are set and the search pattern contains uppercase:
|
||||
```
|
||||
set smartcase
|
||||
|
||||
```
|
||||
|
||||
For example, if the file contains:
|
||||
|
||||
test
|
||||
Test
|
||||
|
||||
When both `ignorecase` and `smartcase` are set, a search for “test” finds and highlights both:
|
||||
|
||||
test
|
||||
Test
|
||||
|
||||
A search for “Test” highlights or finds only the second line:
|
||||
|
||||
test
|
||||
Test
|
||||
|
||||
### 4. Browse & Scroll
|
||||
|
||||
For a better visual experience, you may prefer to have the cursor somewhere in the middle rather than on the first line. The following option sets the cursor position to the 5th row.
|
||||
```
|
||||
set scrolloff=5
|
||||
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
The first image is with scrolloff=0 and the second image is with scrolloff=5.
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture06-07.jpg)
|
||||
|
||||
Tip: `set sidescrolloff` is useful if you also set `nowrap.`
|
||||
|
||||
To display a permanent status bar at the bottom of the vi screen showing the filename, row number, column number, etc.:
|
||||
```
|
||||
set laststatus=2
|
||||
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/picture08.png)
|
||||
|
||||
### 5. Spell
|
||||
|
||||
vi has a built-in spell-checker that is quite useful for text editing as well as coding. vi recognizes the file type and checks the spelling of comments only in code. Use the following command to turn on spell-check for the English language:
|
||||
```
|
||||
set spell spelllang=en_us
|
||||
|
||||
```
|
||||
|
||||
### 6. Miscellaneous
|
||||
|
||||
Disable creating backup file: When this option is on, vi creates a backup of the previous edit. If you do not want this feature, disable it as shown below. Backup files are named with a tilde (~) at the end of the filename.
|
||||
```
|
||||
set nobackup
|
||||
|
||||
```
|
||||
|
||||
Disable creating a swap file: When this option is on, vi creates a swap file that exists until you start editing the file. Swapfile is used to recover a file in the event of a crash or a use conflict. Swap files are hidden files that begin with `.` and end with `.swp`.
|
||||
```
|
||||
set noswapfile
|
||||
|
||||
```
|
||||
|
||||
Suppose you need to edit multiple files in the same vi session and switch between them. An annoying feature that's not readily apparent is that the working directory is the one from which you opened the first file. Often it is useful to automatically switch the working directory to that of the file being edited. To enable this option:
|
||||
```
|
||||
set autochdir
|
||||
|
||||
```
|
||||
|
||||
vi maintains an undo history that lets you undo changes. By default, this history is active only until the file is closed. vi includes a nifty feature that maintains the undo history even after the file is closed, which means you may undo your changes even after the file is saved, closed, and reopened. The undo file is a hidden file saved with the `.un~` extension.
|
||||
```
|
||||
set undofile
|
||||
|
||||
```
|
||||
|
||||
To set audible alert bells (which sound a warning if you try to scroll beyond the end of a line):
|
||||
```
|
||||
set errorbells
|
||||
|
||||
```
|
||||
|
||||
If you prefer, you may set visual alert bells:
|
||||
```
|
||||
set visualbell
|
||||
|
||||
```
|
||||
|
||||
### Bonus
|
||||
|
||||
vi provides long-format as well as short-format commands. Either format can be used to set or unset the configuration.
|
||||
|
||||
Long format for the `autoindent` command:
|
||||
```
|
||||
set autoindent
|
||||
|
||||
```
|
||||
|
||||
Short format for the `autoindent` command:
|
||||
```
|
||||
set ai
|
||||
|
||||
```
|
||||
|
||||
To see the current configuration setting of a command without changing its current value, use `?` at the end:
|
||||
```
|
||||
set autoindent?
|
||||
|
||||
```
|
||||
|
||||
To unset or turn off a command, most commands take `no` as a prefix:
|
||||
```
|
||||
set noautoindent
|
||||
|
||||
```
|
||||
|
||||
It is possible to set a command for one file but not for the global configuration. To do this, open the file and type `:`, followed by the `set` command. This configuration is effective only for the current file editing session.
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture09.png)
|
||||
|
||||
For help on a command:
|
||||
```
|
||||
:help autoindent
|
||||
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture10-11.jpg)
|
||||
|
||||
Note: The commands listed here were tested on Linux with Vim version 7.4 (2013 Aug 10) and Windows with Vim 8.0 (2016 Sep 12).
|
||||
|
||||
These useful commands are sure to enhance your vi experience. Which other commands do you recommend?
|
||||
|
||||
### Cheat sheet
|
||||
|
||||
Copy/paste this list of commands in your vimrc file:
|
||||
```
|
||||
" Indentation & Tabs
|
||||
|
||||
set autoindent
|
||||
|
||||
set smartindent
|
||||
|
||||
set tabstop=4
|
||||
|
||||
set shiftwidth=4
|
||||
|
||||
set expandtab
|
||||
|
||||
set smarttab
|
||||
|
||||
" Display & format
|
||||
|
||||
set number
|
||||
|
||||
set textwidth=80
|
||||
|
||||
set wrapmargin=2
|
||||
|
||||
set showmatch
|
||||
|
||||
" Search
|
||||
|
||||
set hlsearch
|
||||
|
||||
set incsearch
|
||||
|
||||
set ignorecase
|
||||
|
||||
set smartcase
|
||||
|
||||
" Browse & Scroll
|
||||
|
||||
set scrolloff=5
|
||||
|
||||
set laststatus=2
|
||||
|
||||
" Spell
|
||||
|
||||
set spell spelllang=en_us
|
||||
|
||||
" Miscellaneous
|
||||
|
||||
set nobackup
|
||||
|
||||
set noswapfile
|
||||
|
||||
set autochdir
|
||||
|
||||
set undofile
|
||||
|
||||
set visualbell
|
||||
|
||||
set errorbells
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/9/vi-editor-productivity-powerhouse
|
||||
|
||||
作者:[Girish Managoli][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/gammay
|
||||
[1]: https://www.vim.org/download.php#pc
|
@ -0,0 +1,112 @@
|
||||
如何在 Ubuntu 或 Linux Mint 启用硬件加速的视频解码
|
||||
======
|
||||
你或许已经注意到了,在 Linux 上使用 Google Chrome 或 Chromium 浏览器在 YouTube 或其它类似网站观看高清视频会增加你的 CPU 使用率,如果你用的是笔记本,电脑会发热而且电池会很快用完。这是因为Chrome/Chromium(Firefox 也是如此,但是 Firefox 的问题没有办法解决)在 Linux 上不支持硬件加速的视频解码。
|
||||
|
||||
**这篇文章讲述了如何在 Linux 环境安装带有 VA-API 补丁的 Chromium 开发版,它支持 GPU 加速的视频解码,可以显著减少观看在线高清视频时的 CPU 使用率,这篇教程只适用于 Intel 和 Nvidia 的显卡,我没有 ATI/AMD 的显卡可以试验,也没有使用过这几种显卡。**
|
||||
|
||||
这是 Chromium 浏览器在 Ubuntu18.04 中,没有 GPU 加速视频解码时正在播放一个 1080p 的 YouTube 视频:
|
||||
|
||||
![](https://4.bp.blogspot.com/-KtUQni2PMvE/W3KlJ62yLLI/AAAAAAAABW4/NrNVFaTAkZ8AmwqWwRvWD6czT51ni-R-gCLcBGAs/s1600/chromium-default-no-accel.png)
|
||||
|
||||
这是带有 VA-API 补丁的 Chromium 浏览器在 Ubuntu18.04 中,GPU 加速视频解码时正在播放同样的 1080p 的 YouTube 视频:
|
||||
|
||||
![](https://4.bp.blogspot.com/-0c-wb4UNhW8/W3KlQBfeFnI/AAAAAAAABW8/WVUAYzM6hA8wRTlCcrPXPMpoXoFVR6b1QCLcBGAs/s1600/chromium-hardware-acceleration-enabled.png)
|
||||
|
||||
注意截图中的 CPU 使用率。两张截图都是在我老旧而依然强大的桌面上捕捉的。在我的笔记本上,没有硬件加速的 Chromium 带来更高的CPU使用率。
|
||||
|
||||
"只需 VAAPI 即可在 Linux 启用 VAVDA,VAVEA 和 VAJDA" 这篇文章在一年多以前就提交给了Chromium,但是它还没有合并请求。
|
||||
|
||||
Chrome有一个选项可以覆盖软件渲染列表(
|
||||
|
||||
`#ignore-gpu-blacklist`
|
||||
|
||||
),但是这个选项不能启用硬件加速的视频解码。启用这个选项以后,你或许会在访问
|
||||
|
||||
`chrome://gpu`
|
||||
|
||||
时发现这些信息:“_Video Decode: Hardware accelerated_ “,然而这个并不意味着真的有效。在 YouTube 打开一个高清视频并用工具查看CPU使用率如
|
||||
|
||||
`htop`
|
||||
|
||||
(这是我在以上截图中用来查看 CPU 使用率的)。因为 GPU 视频解码没有真的被启用,你应该看到较高的 CPU 使用率。下面有一个部分是关于你是否真的在使用硬件加速的视频解码的。
|
||||
|
||||
**文中使用的 Chromium 浏览器 Ubuntu 版启用 VA-API 的补丁在[这个地址][1]可以获得**
|
||||
|
||||
### 在 Ubuntu 和 Linux Mint 安装和使用带有 VA-API 支持的 Chromium 浏览器
|
||||
|
||||
**每个人都该知道 Chromium 开发版本没有理想中那么稳定。所以你可能发现 bug,它可能会发生崩溃等情况。它现在可能正常运行,但是谁知道几次更新以后会发生什么。**
|
||||
|
||||
**还有,如果你想启用 Widevine 支持(这样你才能观看 Netflix 视频和 YouTube 付费视频),Chromium dev 分支 PPA 要求你执行一些额外步骤。 ** **如果你想要一些功能,比如同步,也是如此**(需要注册 API key还要在你的系统上设置好)。执行这些任务的说明在本文中被详细解释了。
|
||||
|
||||
带有 VA-API 补丁的 Chromium 在其它Linux发行版本也可以获得,但是这里选择 Ubuntu。
|
||||
|
||||
**1\. 安装带有 VA-API 补丁的 Chromium **
|
||||
|
||||
有一个带 VA-API 补丁的 Chromium Beta,但是它缺少适用于 Ubuntu 18.04 的 vdpau-video。
|
||||
```
|
||||
sudo add-apt-repository ppa:saiarcot895/chromium-dev
|
||||
sudo apt-get update
|
||||
sudo apt install chromium-browser
|
||||
|
||||
```
|
||||
|
||||
**2\. 安装 VA-API 驱动**
|
||||
|
||||
对于Intel的显卡,你需要安装 `i965-va-driver` 这个包(它可能早就安装好了)
|
||||
```
|
||||
sudo apt install i965-va-driver
|
||||
```
|
||||
|
||||
对于 Nvidia 的显卡(在开源和闭源的 Nvidia 驱动上,它应该都有效), 安装`vdpau-va-driver` :
|
||||
```
|
||||
sudo apt install vdpau-va-driver
|
||||
```
|
||||
|
||||
**3\. 在 Chromium 启用硬件加速视频选项**
|
||||
|
||||
复制这串地址,粘贴进 Chromium 的 URL 栏: `chrome://flags/#enable-accelerated-video` (或者在 `chrome://flags` 搜索 `Hardware-accelerated video` )并启用它,然后重启 Chromium 浏览器。
|
||||
|
||||
在默认的 Google Chrome / Chromium 版本,这个选项不可用,但是你可以在启用了 VP-API 的 Chromium 版本启用它。
|
||||
|
||||
**4\. 安装 [h264ify][2] Chrome 扩展**
|
||||
|
||||
YouTube(可能还有其它一些网址也是如此)默认使用 VP8 或 VP9 编码解码器,许多 GPU 不支持这种编码解码器的硬件解码。h264ify 会强制 YouTube 使用大多数 GPU 都支持的 H.264 而不是 VP8/VP9。
|
||||
|
||||
这个扩展还能阻塞 60fps 的视频,对低性能机器有用。
|
||||
|
||||
你可以点击这个视频并且选择 `Stats for nerds` 以查看编码解码器,如果启用了 h264ify 扩展,你可以看到编码解码器是 avc / mp4a。如果没有启用,编码解码器应该是 vp09 / opus。
|
||||
|
||||
### 如何检查 Chromium 是否在使用 GPU 视频解码
|
||||
|
||||
在 YouTube 打开一个视频,然后,在 Chromium 打开一个新的标签页并将以下地址输入 URL 栏:
|
||||
|
||||
`chrome://media-internals`
|
||||
|
||||
在 `chrome://media-internals` 标签页中,点击视频的URL(为了展开它), 往下滚动查看 `Player Properties` 的下面,你应该可以找到 `video_decoder` 属性。如果`video_decoder` 的值是 `GpuVideoDecoder` ,这说明当前在另一个标签页播放的 YouTube 视频正在使用硬件加速的的视频解码。
|
||||
|
||||
![](https://4.bp.blogspot.com/-COBJWVT_Y0Q/W3KnG7AeHsI/AAAAAAAABXM/W2XAJA_S0BIHug4eQKTMOdIfXHhgkXhhQCLcBGAs/s1600/chromium-gpuvideodecoder-linux.png)
|
||||
|
||||
如果它显示的是 `FFmpegVideoDecoder` 或 `VpxVideoDecoder` ,说明加速视频解码无效或者你忘记安装或禁用了 h264ify 这个 Chrome 扩展。
|
||||
|
||||
如果无效,你可以通过在命令行运行 `chromium-browser` ,通过查看是否有 VA-API 相关的错误显示出来以调试。你也可以运行`vainfo` (在 Ubuntu 或 Linux Mint 安装:`sudo apt install vainfo`)和 `vdpauinfo` (对于 Nvidia,在 Ubuntu 或 Linux Mint 安装:`sudo apt install vdpauinfo`)并且查看是否有显示任何错误。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linuxuprising.com/2018/08/how-to-enable-hardware-accelerated.html
|
||||
|
||||
作者:[Logix][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[GraveAccent](https://github.com/GraveAccent)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://plus.google.com/118280394805678839070
|
||||
[1]:https://github.com/saiarcot895/chromium-ubuntu-build/tree/master/debian/patches
|
||||
[2]:https://chrome.google.com/webstore/detail/h264ify/aleakchihdccplidncghkekgioiakgal
|
||||
[3]:https://chromium-review.googlesource.com/c/chromium/src/+/532294
|
||||
[4]:https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-dev
|
||||
[5]:https://aur.archlinux.org/packages/?O=0&SeB=nd&K=chromium+vaapi&outdated=&SB=n&SO=a&PP=50&do_Search=Go
|
||||
[6]:https://aur.archlinux.org/packages/libva-vdpau-driver-chromium/
|
||||
[7]:https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-beta
|
||||
[8]:https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-dev/+packages
|
@ -0,0 +1,356 @@
|
||||
|
||||
|
||||
增强 Vim 编辑器,提高编辑效率
|
||||
======
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/checklist_hands_team_collaboration.png?itok=u82QepPk)
|
||||
|
||||
编者注:标题和文章最初提到的 `vi` 编辑器,现已更新为编辑器的正确名称:`Vim`。
|
||||
|
||||
`Vim` 作为一款功能强大、选项丰富的编辑器,为许多用户所热爱。本文介绍了一些在 `Vim` 中默认未启用但实际非常有用的选项。虽然可以在每个 `Vim` 会话中单独启用,但为了创建一个开箱即用的高效编辑环境,还是建议在 `Vim` 的配置文件中配置这些命令。
|
||||
|
||||
## 开始前的准备
|
||||
|
||||
这里所说的选项或配置均位于用户主目录中的 `Vim` 启动配置文件 `.vimrc`。 按照下面的说明在 `.vimrc` 中设置选项:
|
||||
|
||||
(注意:`vimrc` 文件也用于 `Linux` 中的全局配置,如 `/etc/vimrc` 或 `/etc/vim/vimrc`。本文所说的 `.vimrc` 均是指位于用户主目录中的 `.vimrc` 文件。)
|
||||
|
||||
`Linux` 系统中:
|
||||
|
||||
* 用 `Vim` 打开 `.vimrc` 文件: `vim ~/.vimrc`
|
||||
* 复制本文最后的 `选项列表` 粘贴到 `.vimrc` 文件
|
||||
* 保存并关闭 (`:wq`)
|
||||
|
||||
译者注:此处不建议使用 `Vim` 编辑 `.vimrc` 文件,因为很可能无法粘贴成功,可以选择 `gedit` 编辑器编辑 `.vimrc` 文件。
|
||||
|
||||
`Windows` 系统中:
|
||||
|
||||
* 首先,[安装 gvim][1]
|
||||
* 打开 `gvim`
|
||||
* 单击 `编辑` -> `启动设置`,打开 `.vimrc` 文件
|
||||
* 复制本文最后的 `选项列表` 粘贴到 `.vimrc` 文件
|
||||
* 单击 `文件` -> `保存`
|
||||
|
||||
译者注:此处应注意不要使用 `Windows` 自带的记事本编辑该 `.vimrc` 文件。
|
||||
|
||||
下面,我们将深入研究提高 `Vim` 编辑效率的选项。主要分为以下几类:
|
||||
|
||||
1. 缩进 & 制表符
|
||||
2. 显示 & 格式化
|
||||
3. 搜索
|
||||
4. 浏览 & 滚动
|
||||
5. 拼写
|
||||
6. 其他选项
|
||||
|
||||
## 1. 缩进 & 制表符
|
||||
|
||||
使 `Vim` 在创建新行的时候使用与上一行同样的缩进:
|
||||
|
||||
```vim
|
||||
set autoindent
|
||||
```
|
||||
|
||||
创建新行时使用智能缩进,主要用于 `C` 语言一类的程序。通常,打开 `smartindent` 时也应该打开 `autoindent`:
|
||||
|
||||
```vim
|
||||
set smartindent
|
||||
```
|
||||
|
||||
注意:`Vim` 具有语言感知功能,且其默认设置可以基于文件中的编程语言来改变配置以提高效率。有许多默认的配置选项,包括 `axs cindent`,`cinoptions`,`indentexpr` 等,没有在这里说明。 `syn` 是一个非常有用的命令,用于设置文件的语法以更改显示模式。
|
||||
|
||||
译者注:这里的 `syn` 是指 `syntax`,可用于设置文件所用的编程语言,开启对应的语法高亮,以及执行自动事件 (`autocmd`)。
|
||||
|
||||
设置文件里的制表符 `(TAB)` 的宽度(以空格的数量表示):
|
||||
|
||||
```vim
|
||||
set tabstop=4
|
||||
```
|
||||
|
||||
设置移位操作 `>>` 或 `<<` 的缩进长度(以空格的数量表示):
|
||||
|
||||
```vim
|
||||
set shiftwidth=4
|
||||
```
|
||||
|
||||
如果你更喜欢在编辑文件时使用空格而不是制表符,设置以下选项可以使 `Vim` 在你按下 `Tab` 键时用空格代替制表符。
|
||||
|
||||
```vim
|
||||
set expandtab
|
||||
```
|
||||
|
||||
注意:这可能会导致依赖于制表符的 `Python` 等编程语言出现问题。这时,你可以根据文件类型设置该选项(请参考 `autocmd`)。
|
||||
|
||||
## 2. 显示 & 格式化
|
||||
|
||||
要在每行的前面显示行号:
|
||||
|
||||
```vim
|
||||
set number
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture01.png)
|
||||
|
||||
要在文本行超过一定长度时自动换行:
|
||||
|
||||
```vim
|
||||
set textwidth=80
|
||||
```
|
||||
|
||||
要根据从窗口右侧向左数的列数来自动换行:
|
||||
|
||||
```vim
|
||||
set wrapmargin=2
|
||||
```
|
||||
|
||||
译者注:如果 `textwidth` 选项不等于零,本选项无效。
|
||||
|
||||
插入括号时,短暂地跳转到匹配的括号:
|
||||
|
||||
```vim
|
||||
set showmatch
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture02-03.jpg)
|
||||
|
||||
## 3. 搜索
|
||||
|
||||
高亮搜索内容的所有匹配位置:
|
||||
|
||||
```vim
|
||||
set hlsearch
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture04.png)
|
||||
|
||||
搜索过程中动态显示匹配内容:
|
||||
|
||||
```vim
|
||||
set incsearch
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/picture05.png)
|
||||
|
||||
搜索时忽略大小写:
|
||||
|
||||
```vim
|
||||
set ignorecase
|
||||
```
|
||||
|
||||
在打开 `ignorecase` 选项的条件下,搜索内容包含部分大写字符时,要使搜索大小写敏感:
|
||||
|
||||
```vim
|
||||
set smartcase
|
||||
```
|
||||
|
||||
例如,如果文件内容是:
|
||||
|
||||
> test\
|
||||
> Test
|
||||
|
||||
当打开 `ignorecase` 和 `smartcase` 选项时,搜索 `test` 时的突出显示:
|
||||
|
||||
> <font color=yellow>test</font>\
|
||||
> <font color=yellow>Test</font>
|
||||
|
||||
搜索 `Test` 时的突出显示:
|
||||
|
||||
> test\
|
||||
> <font color=yellow>Test</font>
|
||||
|
||||
## 4. 浏览 & 滚动
|
||||
|
||||
为获得更好的视觉体验,你可能希望将光标放在窗口中间而不是第一行,以下选项使光标距窗口上下保留 5 行。
|
||||
|
||||
```vim
|
||||
set scrolloff=5
|
||||
```
|
||||
|
||||
一个例子:
|
||||
|
||||
第一张图中 `scrolloff=0`,第二张图中 `scrolloff=5`。
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture06-07.jpg)
|
||||
|
||||
提示:如果你没有设置选项 `nowrap`,那么设置 `sidescrolloff` 将非常有用。
|
||||
|
||||
在 `Vim` 窗口底部显示一个永久状态栏,可以显示文件名、行号和列号等内容:
|
||||
|
||||
```vim
|
||||
set laststatus=2
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/picture08.png)
|
||||
|
||||
## 5. 拼写
|
||||
|
||||
`Vim` 有一个内置的拼写检查器,对于文本编辑和编码非常有用。`Vim` 可以识别文件类型并仅对代码中的注释进行拼写检查。使用下面的选项打开英语拼写检查:
|
||||
|
||||
```vim
|
||||
set spell spelllang=en_us
|
||||
```
|
||||
|
||||
译者注:中文、日文或其它东亚语字符通常会在打开拼写检查时被标为拼写错误,因为拼写检查不支持这些语种,可以在 `spelllang` 选项中加入 `cjk` 来忽略这些错误标注。
|
||||
|
||||
## 6. 其他选项
|
||||
|
||||
禁止创建备份文件:启用此选项后,`Vim` 将在覆盖文件前创建一个备份,文件成功写入后保留该备份。如果不想保留该备份文件,可以按下面的方式关闭:
|
||||
|
||||
```vim
|
||||
set nobackup
|
||||
```
|
||||
|
||||
禁止创建交换文件:启用此选项后,`Vim` 将在编辑该文件时创建一个交换文件。 交换文件用于在崩溃或发生使用冲突时恢复文件。交换文件是以 `.` 开头并以 `.swp` 结尾的隐藏文件。
|
||||
|
||||
```vim
|
||||
set noswapfile
|
||||
```
|
||||
|
||||
如果需要在同一个 `Vim` 窗口中编辑多个文件并进行切换。默认情况下,工作目录是打开的第一个文件的目录。而将工作目录自动切换到正在编辑的文件的目录是非常有用的。要自动切换工作目录:
|
||||
|
||||
```vim
|
||||
set autochdir
|
||||
```
|
||||
|
||||
`Vim` 自动维护编辑的历史记录,允许撤消更改。默认情况下,该历史记录仅在文件关闭之前有效。`Vim` 包含一个增强功能,使得即使在文件关闭后也可以维护撤消历史记录,这意味着即使在保存、关闭和重新打开文件后,也可以撤消之前的更改。历史记录文件是使用 `.un~` 扩展名保存的隐藏文件。
|
||||
|
||||
```vim
|
||||
set undofile
|
||||
```
|
||||
|
||||
错误信息响铃,只对错误信息起作用:
|
||||
|
||||
```vim
|
||||
set errorbells
|
||||
```
|
||||
|
||||
如果你愿意,还可以设置错误视觉提示:
|
||||
|
||||
```vim
|
||||
set visualbell
|
||||
```
|
||||
|
||||
## 惊喜
|
||||
|
||||
vi provides long-format as well as short-format commands. Either format can be used to set or unset the configuration.
|
||||
|
||||
`Vim` 提供长格式和短格式命令,两种格式都可用于设置或取消选项配置。
|
||||
|
||||
`autoindent` 选项的长格式是:
|
||||
|
||||
```vim
|
||||
set autoindent
|
||||
```
|
||||
|
||||
`autoindent` 选项的短格式是:
|
||||
|
||||
```vim
|
||||
set ai
|
||||
```
|
||||
|
||||
To see the current configuration setting of a command without changing its current value, use `?` at the end:
|
||||
|
||||
要在不更改选项当前值的情况下查看其当前设置,可以在 `Vim` 的命令行上使用在末尾加上 `?` 的命令:
|
||||
|
||||
```vim
|
||||
set autoindent?
|
||||
```
|
||||
|
||||
在大多数选项前加上 `no` 前缀可以取消或关闭选项:
|
||||
|
||||
```vim
|
||||
set noautoindent
|
||||
```
|
||||
|
||||
可以为单独的文件配置选项,而不必修改全局配置文件。需要的话,请打开文件并输入 `:`,然后键入 `set`命令。这样的话,配置仅对当前的文件编辑会话有效。
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture09.png)
|
||||
|
||||
使用命令行获取帮助:
|
||||
|
||||
```vim
|
||||
:help autoindent
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture10-11.jpg)
|
||||
|
||||
注意:此处列出的命令仅对 `Linux` 上的 `Vim 7.4` 版本和 `Windows` 上的 `Vim 8.0` 版本进行了测试。
|
||||
|
||||
这些有用的命令肯定会增强您的 `Vim` 使用体验。你会推荐哪些其他有用的命令?
|
||||
|
||||
## 选项列表
|
||||
|
||||
复制该选项列表粘贴到 `.vimrc` 文件中:
|
||||
|
||||
```vim
|
||||
" Indentation & Tabs
|
||||
|
||||
set autoindent
|
||||
|
||||
set smartindent
|
||||
|
||||
set tabstop=4
|
||||
|
||||
set shiftwidth=4
|
||||
|
||||
set expandtab
|
||||
|
||||
set smarttab
|
||||
|
||||
" Display & format
|
||||
|
||||
set number
|
||||
|
||||
set textwidth=80
|
||||
|
||||
set wrapmargin=2
|
||||
|
||||
set showmatch
|
||||
|
||||
" Search
|
||||
|
||||
set hlsearch
|
||||
|
||||
set incsearch
|
||||
|
||||
set ignorecase
|
||||
|
||||
set smartcase
|
||||
|
||||
" Browse & Scroll
|
||||
|
||||
set scrolloff=5
|
||||
|
||||
set laststatus=2
|
||||
|
||||
" Spell
|
||||
|
||||
set spell spelllang=en_us
|
||||
|
||||
" Miscellaneous
|
||||
|
||||
set nobackup
|
||||
|
||||
set noswapfile
|
||||
|
||||
set autochdir
|
||||
|
||||
set undofile
|
||||
|
||||
set visualbell
|
||||
|
||||
set errorbells
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/9/vi-editor-productivity-powerhouse
|
||||
|
||||
作者:[Girish Managoli][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[idea2act](https://github.com/idea2act)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/gammay
|
||||
[1]: https://www.vim.org/download.php#pc
|
Loading…
Reference in New Issue
Block a user