Skip to content

Commit 16f049b

Browse files
committed
Add codec ffmpeg
1 parent ec6a4b6 commit 16f049b

10 files changed

Lines changed: 1158 additions & 3 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@ jobs:
3434
libvpx-dev \
3535
libx11-dev \
3636
libx264-dev \
37-
libxext-dev
37+
libxext-dev \
38+
nasm \
39+
yasm
3840
- name: Run Test Suite
39-
run: make test
41+
run: |
42+
make test \
43+
&& cd pkg/codec/ffmpeg \
44+
&& make test
4045
- uses: codecov/codecov-action@v5
4146
with:
4247
token: ${{ secrets.CODECOV_TOKEN }}
@@ -65,7 +70,10 @@ jobs:
6570
libvpx \
6671
x264
6772
- name: Run Test Suite
68-
run: make test
73+
run: |
74+
make test \
75+
&& cd pkg/codec/ffmpeg \
76+
&& make test
6977
- uses: codecov/codecov-action@v5
7078
with:
7179
token: ${{ secrets.CODECOV_TOKEN }}

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,24 @@ An open source API that allows applications such as VLC media player or GStreame
164164
* Installation:
165165
* Ubuntu: `apt install libva-dev`
166166

167+
#### Video codecs implemented using ffmpeg
168+
169+
* Package: [github.com/pion/mediadevices/pkg/codec/ffmpeg](https://pkg.go.dev/github.com/pion/mediadevices/pkg/codec/ffmpeg)
170+
* Installation: You need to enable CGO, and provide the ffmpeg headers and libraries when compiling. For more detail, checkout
171+
https://github.com/asticode/go-astiav?tab=readme-ov-file#install-ffmpeg-from-source.
172+
* NVENC: If you want to use nvenc, you need to install [FFmpeg/nv-codec-headers](https://github.com/FFmpeg/nv-codec-headers) too.
173+
Make sure that your driver's version is supported by the nv-codec-headers version you are installing.
174+
To install it, clone the repo, checkout to wanted version, and `sudo make install`.
175+
176+
> Currently, only ffmpeg n7.0 and n7.1 are supported.
177+
178+
##### nvenc
179+
180+
Requires ffmpeg build with `--enable-nonfree --enable-nvenc`.
181+
182+
##### x264
183+
184+
Requires ffmpeg build with `--enable-libx264 --enable-gpl`.
167185

168186
#### Audio Codecs
169187

pkg/codec/ffmpeg/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tmp

pkg/codec/ffmpeg/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version=n7.0
2+
srcPath=tmp/$(version)/src
3+
CGO_CFLAGS := -I$(CURDIR)/tmp/$(version)/include/
4+
CGO_LDFLAGS := -L$(CURDIR)/tmp/$(version)/lib/
5+
PKG_CONFIG_PATH := $(CURDIR)/tmp/$(version)/lib/pkgconfig
6+
configure := --enable-libx264 --enable-gpl
7+
8+
test: $(srcPath)
9+
PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go test -v .
10+
11+
$(srcPath):
12+
rm -rf $(srcPath)
13+
mkdir -p $(srcPath)
14+
cd $(srcPath) && git clone https://github.com/FFmpeg/FFmpeg .
15+
cd $(srcPath) && git checkout $(version)
16+
cd $(srcPath) && ./configure --prefix=.. $(configure)
17+
cd $(srcPath) && make -j4
18+
cd $(srcPath) && make install

pkg/codec/ffmpeg/errors.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package ffmpeg
2+
3+
import (
4+
"errors"
5+
)
6+
7+
var (
8+
errFailedToCreateHwDevice = errors.New("ffmpeg: failed to create device")
9+
errCodecNotFound = errors.New("ffmpeg: codec not found")
10+
errFailedToCreateCodecCtx = errors.New("ffmpeg: failed to allocate codec context")
11+
errFailedToCreateHwFramesCtx = errors.New("ffmpeg: failed to create hardware frames context")
12+
errFailedToInitHwFramesCtx = errors.New("ffmpeg: failed to initialize hardware frames context")
13+
errFailedToOpenCodecCtx = errors.New("ffmpeg: failed to open codec context")
14+
errFailedToAllocFrame = errors.New("ffmpeg: failed to allocate frame")
15+
errFailedToAllocSwBuf = errors.New("ffmpeg: failed to allocate software buffer")
16+
errFailedToAllocHwBuf = errors.New("ffmpeg: failed to allocate hardware buffer")
17+
errFailedToAllocPacket = errors.New("ffmpeg: failed to allocate packet")
18+
)

0 commit comments

Comments
 (0)