Skip to content

Add codec ffmpeg #621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ jobs:
libvpx-dev \
libx11-dev \
libx264-dev \
libxext-dev
libxext-dev \
nasm \
yasm
- name: Run Test Suite
run: make test
run: |
make test \
&& cd pkg/codec/ffmpeg \
&& make test
- uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down Expand Up @@ -65,7 +70,10 @@ jobs:
libvpx \
x264
- name: Run Test Suite
run: make test
run: |
make test \
&& cd pkg/codec/ffmpeg \
&& make test
- uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,24 @@ An open source API that allows applications such as VLC media player or GStreame
* Installation:
* Ubuntu: `apt install libva-dev`

#### Video codecs implemented using ffmpeg

* Package: [github.com/pion/mediadevices/pkg/codec/ffmpeg](https://pkg.go.dev/github.com/pion/mediadevices/pkg/codec/ffmpeg)
* Installation: You need to enable CGO, and provide the ffmpeg headers and libraries when compiling. For more detail, checkout
https://github.com/asticode/go-astiav?tab=readme-ov-file#install-ffmpeg-from-source.
* NVENC: If you want to use nvenc, you need to install [FFmpeg/nv-codec-headers](https://github.com/FFmpeg/nv-codec-headers) too.
Make sure that your driver's version is supported by the nv-codec-headers version you are installing.
To install it, clone the repo, checkout to wanted version, and `sudo make install`.

> Currently, only ffmpeg n7.0 and n7.1 are supported.

##### nvenc

Requires ffmpeg build with `--enable-nonfree --enable-nvenc`.

##### x264

Requires ffmpeg build with `--enable-libx264 --enable-gpl`.

#### Audio Codecs

Expand Down
1 change: 1 addition & 0 deletions pkg/codec/ffmpeg/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tmp
18 changes: 18 additions & 0 deletions pkg/codec/ffmpeg/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version=n7.0
srcPath=tmp/$(version)/src
CGO_CFLAGS := -I$(CURDIR)/tmp/$(version)/include/
CGO_LDFLAGS := -L$(CURDIR)/tmp/$(version)/lib/
PKG_CONFIG_PATH := $(CURDIR)/tmp/$(version)/lib/pkgconfig
configure := --enable-libx264 --enable-gpl

test: $(srcPath)
PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go test -v .

$(srcPath):
rm -rf $(srcPath)
mkdir -p $(srcPath)
cd $(srcPath) && git clone https://github.com/FFmpeg/FFmpeg .
cd $(srcPath) && git checkout $(version)
cd $(srcPath) && ./configure --prefix=.. $(configure)
cd $(srcPath) && make -j4
cd $(srcPath) && make install
18 changes: 18 additions & 0 deletions pkg/codec/ffmpeg/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ffmpeg

import (
"errors"
)

var (
errFailedToCreateHwDevice = errors.New("ffmpeg: failed to create device")
errCodecNotFound = errors.New("ffmpeg: codec not found")
errFailedToCreateCodecCtx = errors.New("ffmpeg: failed to allocate codec context")
errFailedToCreateHwFramesCtx = errors.New("ffmpeg: failed to create hardware frames context")
errFailedToInitHwFramesCtx = errors.New("ffmpeg: failed to initialize hardware frames context")
errFailedToOpenCodecCtx = errors.New("ffmpeg: failed to open codec context")
errFailedToAllocFrame = errors.New("ffmpeg: failed to allocate frame")
errFailedToAllocSwBuf = errors.New("ffmpeg: failed to allocate software buffer")
errFailedToAllocHwBuf = errors.New("ffmpeg: failed to allocate hardware buffer")
errFailedToAllocPacket = errors.New("ffmpeg: failed to allocate packet")
)
Loading
Loading