一直想自己做个小项目,能后开源拿出来用那种,想来想去还是从最熟悉的开始,最近 nginx 和 sox 用的比较多,就拿这俩练手吧。

sox 确实真的坑有点多呀,现在基本上也没人维护,提 patch 都没人看了,看来还是 FFmpeg 才是未来呀。

nginx-transcode-module

Nginx module for media transcoding

Description

This project is used as nginx third-party module.

Accept HTTP requests, find the files according to the configuration, transcode it and return it in the required format.

Install

  1. Clone project

git clone https://github.com/HiSunzhenliang/nginx-transcode-module.git

  1. Requirements

    • Nginx
    • libsox
  2. Compile Nginx with nginx-transcode-module

./configure --add-dynamic-module=/.../nginx-transcode-module

make && make install

Usage

In nginx config file:

1
2
3
4
5
location ~ / {
nginx-transcode-module;
transcode_root "/path/audios";
transcode_output_format "mp3";
}
1
2
$ ls /path/audios
a.wav b.wav c.wav ...

Send request like:

1
curl -v http://127.0.0.1:8000/a.wav -o a.mp3`

Get a.mp3 transcoded from a.wav.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
MIT License

Copyright (c) 2021 sunzhenliang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.