Skip to content

Commit 11832f7

Browse files
authored
Merge pull request #39 from mutablelogic/ffmpeg71
Update to ffmpeg 7.1
2 parents c3b80a5 + 0d63566 commit 11832f7

File tree

151 files changed

+7409
-4031
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+7409
-4031
lines changed

Makefile

Lines changed: 99 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
GO=$(shell which go)
33
DOCKER=$(shell which docker)
44

5+
# Current ffmpeg version and config
6+
FFMPEG_VERSION=ffmpeg-7.1.1
7+
# Empty variable to collect FFmpeg configuration options - will be populated dynamically
8+
FFMPEG_CONFIG=
9+
510
# Build flags
611
BUILD_MODULE := $(shell cat go.mod | head -1 | cut -d ' ' -f 2)
712
BUILD_LD_FLAGS += -X $(BUILD_MODULE)/pkg/version.GitSource=${BUILD_MODULE}
@@ -21,11 +26,65 @@ DOCKER_REGISTRY ?= ghcr.io/mutablelogic
2126
BUILD_DIR := "build"
2227
CMD_DIR := $(filter-out cmd/ffmpeg/README.md, $(wildcard cmd/ffmpeg/*))
2328
BUILD_TAG := ${DOCKER_REGISTRY}/go-media-${OS}-${ARCH}:${VERSION}
29+
PREFIX ?= ${BUILD_DIR}/install
30+
31+
###############################################################################
32+
# TARGETS
2433

25-
all: clean cmds
34+
.PHONY: all
35+
all: clean ffinstall cli
2636

37+
.PHONY: cmds
2738
cmds: $(CMD_DIR)
2839

40+
.PHONY: cli
41+
cli: go-dep mkdir
42+
@echo Build media tool
43+
@PKG_CONFIG_PATH="$(shell realpath ${PREFIX})/lib/pkgconfig" CGO_LDFLAGS_ALLOW="-(W|D).*" ${GO} build ${BUILD_FLAGS} -o ${BUILD_DIR}/media ./cmd/media
44+
45+
$(CMD_DIR): go-dep mkdir
46+
@echo Build cmd $(notdir $@)
47+
@PKG_CONFIG_PATH="$(shell realpath ${PREFIX})/lib/pkgconfig" CGO_LDFLAGS_ALLOW="-(W|D).*" ${GO} build ${BUILD_FLAGS} -o ${BUILD_DIR}/$(notdir $@) ./$@
48+
49+
###############################################################################
50+
# FFMPEG
51+
52+
# Download ffmpeg sources
53+
${BUILD_DIR}/${FFMPEG_VERSION}:
54+
@if [ ! -d "$(BUILD_DIR)/$(FFMPEG_VERSION)" ]; then \
55+
echo "Downloading $(FFMPEG_VERSION)"; \
56+
mkdir -p $(BUILD_DIR)/${FFMPEG_VERSION}; \
57+
curl -L -o $(BUILD_DIR)/ffmpeg.tar.gz https://ffmpeg.org/releases/$(FFMPEG_VERSION).tar.gz; \
58+
tar -xzf $(BUILD_DIR)/ffmpeg.tar.gz -C $(BUILD_DIR); \
59+
rm -f $(BUILD_DIR)/ffmpeg.tar.gz; \
60+
fi
61+
62+
# Configure ffmpeg
63+
.PHONY: ffmpeg
64+
ffmpeg: mkdir ${BUILD_DIR}/${FFMPEG_VERSION} ffmpeg-dep
65+
@echo "Configuring ${FFMPEG_VERSION} => ${PREFIX}"
66+
@cd ${BUILD_DIR}/${FFMPEG_VERSION} && ./configure \
67+
--enable-static --disable-doc --disable-programs \
68+
--prefix="$(shell realpath ${PREFIX})" \
69+
--pkg-config-flags="--static" \
70+
--extra-libs="-lpthread" \
71+
--enable-gpl --enable-nonfree ${FFMPEG_CONFIG}
72+
73+
# Build ffmpeg
74+
.PHONY: ffbuild
75+
ffbuild: ffmpeg
76+
@echo "Building ${FFMPEG_VERSION}"
77+
@cd $(BUILD_DIR)/$(FFMPEG_VERSION) && make
78+
79+
# Install ffmpeg
80+
.PHONY: ffinstall
81+
ffinstall: ffbuild
82+
@echo "Installing ${FFMPEG_VERSION}"
83+
@cd $(BUILD_DIR)/$(FFMPEG_VERSION) && make install
84+
85+
###############################################################################
86+
# DOCKER
87+
2988
docker: docker-dep
3089
@echo build docker image: ${BUILD_TAG} for ${OS}/${ARCH}
3190
@${DOCKER} build \
@@ -40,43 +99,40 @@ docker-push: docker-dep
4099
@echo push docker image: ${BUILD_TAG}
41100
@${DOCKER} push ${BUILD_TAG}
42101

102+
###############################################################################
103+
# TESTS
104+
43105
test: go-dep
44106
@echo Test
45107
@${GO} mod tidy
46-
@echo ... test sys/ffmpeg61
47-
@${GO} test ./sys/ffmpeg61
48-
@echo ... test pkg/ffmpeg
49-
@${GO} test -v ./pkg/ffmpeg
50-
@echo ... test sys/chromaprint
51-
@${GO} test ./sys/chromaprint
52-
@echo ... test pkg/chromaprint
53-
@${GO} test ./pkg/chromaprint
54-
@echo ... test pkg/file
55-
@${GO} test ./pkg/file
56-
@echo ... test pkg/generator
57-
@${GO} test ./pkg/generator
58-
@echo ... test pkg/image
59-
@${GO} test ./pkg/image
60-
@echo ... test pkg
61-
@${GO} test ./pkg/...
108+
@echo ... test sys/ffmpeg71
109+
@PKG_CONFIG_PATH=$(shell realpath ${PREFIX})/lib/pkgconfig ${GO} test ./sys/ffmpeg71
110+
# @echo ... test pkg/ffmpeg
111+
# @${GO} test -v ./pkg/ffmpeg
112+
# @echo ... test sys/chromaprint
113+
# @${GO} test ./sys/chromaprint
114+
# @echo ... test pkg/chromaprint
115+
# @${GO} test ./pkg/chromaprint
116+
# @echo ... test pkg/file
117+
# @${GO} test ./pkg/file
118+
# @echo ... test pkg/generator
119+
# @${GO} test ./pkg/generator
120+
# @echo ... test pkg/image
121+
# @${GO} test ./pkg/image
122+
# @echo ... test pkg
123+
# @${GO} test ./pkg/...
62124

63125
container-test: go-dep
64126
@echo Test
65127
@${GO} mod tidy
66-
@${GO} test --tags=container ./sys/ffmpeg61
128+
@${GO} test --tags=container ./sys/ffmpeg71
67129
@${GO} test --tags=container ./sys/chromaprint
68130
@${GO} test --tags=container ./pkg/...
69131
@${GO} test --tags=container .
70132

71-
cli: go-dep mkdir
72-
@echo Build media tool
73-
@${GO} build ${BUILD_FLAGS} -o ${BUILD_DIR}/media ./cmd/cli
74133

75-
$(CMD_DIR): go-dep mkdir
76-
@echo Build cmd $(notdir $@)
77-
@${GO} build ${BUILD_FLAGS} -o ${BUILD_DIR}/$(notdir $@) ./$@
78-
79-
FORCE:
134+
###############################################################################
135+
# DEPENDENCIES, ETC
80136

81137
go-dep:
82138
@test -f "${GO}" && test -x "${GO}" || (echo "Missing go binary" && exit 1)
@@ -87,9 +143,26 @@ docker-dep:
87143
mkdir:
88144
@echo Mkdir ${BUILD_DIR}
89145
@install -d ${BUILD_DIR}
146+
@install -d ${PREFIX}
90147

91148
clean:
92149
@echo Clean
93150
@rm -fr $(BUILD_DIR)
94151
@${GO} mod tidy
95152
@${GO} clean
153+
154+
# Check for FFmpeg dependencies
155+
.PHONY: ffmpeg-dep
156+
ffmpeg-dep:
157+
$(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG) $(shell pkg-config --exists libass && echo "--enable-libass"))
158+
$(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG) $(shell pkg-config --exists fdk-aac && echo "--enable-libfdk-aac"))
159+
$(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG) $(shell pkg-config --exists lame && echo "--enable-libmp3lame"))
160+
$(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG) $(shell pkg-config --exists freetype2 && echo "--enable-libfreetype"))
161+
$(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG) $(shell pkg-config --exists theora && echo "--enable-libtheora"))
162+
$(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG) $(shell pkg-config --exists vorbis && echo "--enable-libvorbis"))
163+
$(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG) $(shell pkg-config --exists vpx && echo "--enable-libvpx"))
164+
$(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG) $(shell pkg-config --exists x264 && echo "--enable-libx264"))
165+
$(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG) $(shell pkg-config --exists x265 && echo "--enable-libx265"))
166+
$(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG) $(shell pkg-config --exists opus && echo "--enable-libopus"))
167+
$(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG) $(shell pkg-config --exists xvid && echo "--enable-libxvid"))
168+
@echo "FFmpeg configuration: $(FFMPEG_CONFIG)"

README.md

Lines changed: 31 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
This module provides an interface for media services, including:
55

6-
* Bindings in golang for [FFmpeg 6.1](https://ffmpeg.org/);
6+
* Bindings in golang for [FFmpeg 7.1](https://ffmpeg.org/);
77
* Opening media files, devices and network sockets for reading and writing;
88
* Retrieving metadata and artwork from audio and video media;
99
* Re-multiplexing media files from one format to another;
@@ -16,79 +16,49 @@ you are interested in, please see below "Contributing & Distribution" below.
1616

1717
## Requirements
1818

19-
In order to build the examples, you'll need the library and header files
20-
for [FFmpeg 6](https://ffmpeg.org/download.html) installed.The `chromaprint` library is also
21-
required for fingerprinting audio files and SDL2 for the video player.
22-
23-
### MacOS
24-
25-
On Macintosh with [homebrew](http://bew.sh/), for example:
19+
If you're building for docker, then you can simply run the following command. This creates a docker
20+
image with all the dependencies installed.
2621

2722
```bash
28-
brew install ffmpeg@6 chromaprint make
29-
brew link ffmpeg@6
23+
DOCKER_REGISTRY=docker.io/user make docker
3024
```
3125

32-
### Debian
33-
34-
If you're using Debian you may not be able to get the ffmpeg 6 unless you first of all add the debi-multimedia repository.
35-
You can do this by adding the following line to your `/etc/apt/sources.list` file:
26+
However, it's more likely that you want to build the bindings. To do so, compile the FFmpeg libraries
27+
first:
3628

3729
```bash
38-
# Run commands as privileged user
39-
echo "deb https://www.deb-multimedia.org $(lsb_release -sc) main" >> /etc/apt/sources.list
40-
apt update -y -oAcquire::AllowInsecureRepositories=true
41-
apt install -y --force-yes deb-multimedia-keyring
30+
# Debian/Ubuntu
31+
apt install libfreetype-dev libmp3lame-dev libopus-dev libvorbis-dev libvpx-dev libx264-dev libx265-dev libnuma-dev
32+
git clone github.com/mutablelogic/go-media
33+
cd go-media
34+
make ffmpeg
4235
```
4336

44-
Then you can proceed to install the ffmpeg 6 and the other dependencies:
45-
4637
```bash
47-
# Run commands as privileged user
48-
apt install -y libavcodec-dev libavdevice-dev libavfilter-dev libavutil-dev libswscale-dev libswresample-dev
49-
apt install -y libchromaprint-dev
50-
apt install -y libsdl2-dev
38+
# Fedora
39+
dnf install freetype-devel lame-devel opus-devel libvorbis-devel libvpx-devel x264-devel x265-devel numactl-devel
40+
git clone github.com/mutablelogic/go-media
41+
cd go-media
42+
make ffmpeg
5143
```
5244

53-
### Docker Container
54-
55-
TODO
56-
57-
## Examples
58-
59-
There are some examples in the `cmd` folder of the main repository on how to use
60-
the package. The various make targets are:
61-
62-
* `make all` will perform tests, build all examples and the backend API;
63-
* `make test` will perform tests;
64-
* `make cmd` will build example command-line tools into the `build` folder;
65-
* `make clean` will remove all build artifacts.
66-
67-
There are also some targets to build a docker image:
68-
69-
* `DOCKER_REGISTRY=docker.io/user make docker` will build a docker image;
70-
* `DOCKER_REGISTRY=docker.io/user make docker-push` will push the docker image to the registry.
71-
72-
For example,
73-
7445
```bash
75-
git clone git@github.com:djthorpe/go-media.git
46+
# Homebrew
47+
brew install freetype lame opus libvorbis libvpx x264 x265
48+
git clone github.com/mutablelogic/go-media
7649
cd go-media
77-
DOCKER_REGISTRY=ghcr.io/mutablelogic make docker
50+
make ffmpeg
7851
```
7952

80-
There are a variety of types of object needed as part of media processing.
81-
All examples require a `Manager` to be created, which is used to enumerate all supported formats
82-
and open media files and byte streams.
53+
This will place the static libraries in the `build/install` folder which you can refer to when compiling your
54+
golang code. For example, here's a typical compile or run command on a Mac:
8355

84-
* `Manager` is the main entry point for the package. It is used to open media files and byte streams,
85-
and enumerate supported formats, codecs, pixel formats, etc.
86-
* `Media` is a hardware device, file or byte stream. It contains metadata, artwork, and streams.
87-
* `Decoder` is used to demultiplex media streams. Create a decoder and enumerate the streams which
88-
you'd like to demultiplex. Provide the audio and video parameters if you want to resample or
89-
reformat the streams.
90-
* `Encoder` is used to multiplex media streams. Create an encoder and send the output of the
91-
decoder to reencode the streams.
56+
```bash
57+
PKG_CONFIG_PATH="${PWD}/build/install/lib/pkgconfig" \
58+
LD_LIBRARY_PATH="/opt/homebrew/lib" \
59+
CGO_LDFLAGS_ALLOW="-(W|D).*" \
60+
go build -o build/media ./cmd/media
61+
```
9262

9363
### Demultiplexing
9464

@@ -360,12 +330,12 @@ repository for more information:
360330

361331
> __go-media__\
362332
> [https://github.com/mutablelogic/go-media/](https://github.com/mutablelogic/go-media/)\
363-
> Copyright (c) 2021-2024 David Thorpe, All rights reserved.
333+
> Copyright (c) 2021-2025 David Thorpe, All rights reserved.
364334
365335
This software links to shared libraries of [FFmpeg](http://ffmpeg.org/) licensed under
366336
the [LGPLv2.1](http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
367337

368338
## References
369339

370-
* https://ffmpeg.org/doxygen/6.1/index.html
371-
* https://pkg.go.dev/github.com/mutablelogic/go-media
340+
* <https://ffmpeg.org/doxygen/7.0/index.html>
341+
* <https://pkg.go.dev/github.com/mutablelogic/go-media>

_old/cli/context.go

Lines changed: 0 additions & 33 deletions
This file was deleted.

_old/cli/decode.go

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)