Skip to content

Commit

Permalink
Remove code related to precompiled ffmpeg
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 committed Jul 27, 2024
1 parent 8d22f81 commit f609bfe
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 91 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/build_ffmpeg.yml

This file was deleted.

12 changes: 2 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,14 @@ XAV_DIR = c_src/xav
PRIV_DIR = $(MIX_APP_PATH)/priv
XAV_SO = $(PRIV_DIR)/libxav.so

FFMPEG_INCLUDE_DIR = ffmpeg_build/include
FFMPEG_LIB_DIR = ffmpeg_build/lib

# uncomment to compile with debug logs
# XAV_DEBUG_LOGS = -DXAV_DEBUG=1

HEADERS = $(XAV_DIR)/reader.h $(XAV_DIR)/decoder.h $(XAV_DIR)/utils.h
SOURCES = $(XAV_DIR)/xav_nif.c $(XAV_DIR)/reader.c $(XAV_DIR)/decoder.c $(XAV_DIR)/utils.c

ifeq ($(USE_BUNDLED_FFMPEG), true)
CFLAGS = -fPIC -I$(ERTS_INCLUDE_DIR) -I${FFMPEG_INCLUDE_DIR} -I${XAV_DIR} -shared $(XAV_DEBUG_LOGS)
LDFLAGS = -L$(FFMPEG_LIB_DIR) -Wl,--whole-archive -lavcodec -lswscale -lavutil -lavformat -Wl,--no-whole-archive
else
CFLAGS = -fPIC -I$(ERTS_INCLUDE_DIR) -I${XAV_DIR} -shared $(XAV_DEBUG_LOGS)
LDFLAGS = -lavcodec -lswscale -lavutil -lavformat -lavdevice -lswresample
endif
CFLAGS = -fPIC -I$(ERTS_INCLUDE_DIR) -I${XAV_DIR} -shared $(XAV_DEBUG_LOGS)
LDFLAGS = -lavcodec -lswscale -lavutil -lavformat -lavdevice -lswresample

ifeq ($(shell uname -s),Darwin)
CFLAGS += -undefined dynamic_lookup
Expand Down
1 change: 0 additions & 1 deletion ffmpeg-version

This file was deleted.

58 changes: 6 additions & 52 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
defmodule Xav.MixProject do
use Mix.Project

# https://github.com/mickel8/releases/download/0.1.0/ffmpeg_5.0.1-x86_64-linux.tar.gz

@precompiled_ffmpeg_platforms []

def project do
[
app: :xav,
Expand All @@ -14,7 +10,6 @@ defmodule Xav.MixProject do
description: "Elixir media library built on top of FFmpeg",
package: package(),
compilers: [:native] ++ Mix.compilers(),
make_env: %{"USE_BUNDLED_FFMPEG" => "#{get_platform() in @precompiled_ffmpeg_platforms}"},
aliases: [
"compile.native": &native/1
],
Expand Down Expand Up @@ -46,56 +41,15 @@ defmodule Xav.MixProject do
]
end

defp get_platform() do
:erlang.system_info(:system_architecture)
|> List.to_string()
|> String.split("-")
|> case do
["x86_64" = arch, _vendor, "linux" = system, _abi] ->
{arch, system}

[arch, _vendor, "darwin" <> _ | _] ->
{arch, "darwin"}

["win32"] ->
{"x86_64", "windows"}
end
end

defp native(_) do
{arch, system} = platform = get_platform()

if platform in @precompiled_ffmpeg_platforms do
download_ffmpeg(arch, system)
else
Mix.shell().info("""
Xav requires FFmpeg development packages to be installed on your system. \
Make sure paths to ffmpeg header and library files are in C_INCLUDE_PATH, \
LIBRARY_PATH and LD_LIBRARY_PATH. For more information refer to Xav README \
under: https://github.com/mickel8/xav#installation \
""")
end
Mix.shell().info("""
Xav requires FFmpeg development packages to be installed on your system. \
Make sure paths to ffmpeg header and library files are in C_INCLUDE_PATH, \
LIBRARY_PATH and LD_LIBRARY_PATH. For more information refer to Xav README \
under: https://github.com/mickel8/xav#installation \
""")

Mix.Tasks.Compile.ElixirMake.run([])
:ok
end

defp download_ffmpeg(arch, system) do
ffmpeg_version = File.read!("ffmpeg-version") |> String.trim()
Mix.shell().info("Downloading precompiled ffmpeg for #{arch}-#{system}")
# TODO
Mix.shell().info("Unpacking precompiled ffmpeg")

ffmpeg_archive_path = Path.join(__DIR__, "ffmpeg_#{ffmpeg_version}-#{arch}-#{system}.tar.gz")

case :erl_tar.extract(ffmpeg_archive_path, [:compressed]) do
:ok ->
:ok

{:error, reason} ->
Mix.raise("Failed to extract ffmpeg archive, reason: #{inspect(reason)}")
end

:ok
end
end

0 comments on commit f609bfe

Please sign in to comment.