Skip to content

Instantly share code, notes, and snippets.

@Sean-Der
Created June 12, 2023 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sean-Der/e933796555a29ab513998a575723bea1 to your computer and use it in GitHub Desktop.
Save Sean-Der/e933796555a29ab513998a575723bea1 to your computer and use it in GitHub Desktop.
FFMpeg Homebrew Formula with Opus FLV Support
class Ffmpeg < Formula
desc "Play, record, convert, and stream audio and video"
homepage "https://ffmpeg.org/"
url "https://ffmpeg.org/releases/ffmpeg-6.0.tar.xz"
sha256 "57be87c22d9b49c112b6d24bc67d42508660e6b718b3db89c44e47e289137082"
# None of these parts are used by default, you have to explicitly pass `--enable-gpl`
# to configure to activate them. In this case, FFmpeg's license changes to GPL v2+.
license "GPL-2.0-or-later"
head "https://github.com/FFmpeg/FFmpeg.git", branch: "master"
livecheck do
url "https://ffmpeg.org/download.html"
regex(/href=.*?ffmpeg[._-]v?(\d+(?:\.\d+)+)\.t/i)
end
depends_on "pkg-config" => :build
depends_on "aom"
depends_on "aribb24"
depends_on "dav1d"
depends_on "fontconfig"
depends_on "freetype"
depends_on "frei0r"
depends_on "gnutls"
depends_on "lame"
depends_on "libass"
depends_on "libbluray"
depends_on "librist"
depends_on "libsoxr"
depends_on "libvidstab"
depends_on "libvmaf"
depends_on "libvorbis"
depends_on "libvpx"
depends_on "opencore-amr"
depends_on "openjpeg"
depends_on "opus"
depends_on "rav1e"
depends_on "rubberband"
depends_on "sdl2"
depends_on "snappy"
depends_on "speex"
depends_on "srt"
depends_on "svt-av1"
depends_on "tesseract"
depends_on "theora"
depends_on "webp"
depends_on "x264"
depends_on "x265"
depends_on "xvid"
depends_on "xz"
depends_on "zeromq"
depends_on "zimg"
uses_from_macos "bzip2"
uses_from_macos "libxml2"
uses_from_macos "zlib"
on_linux do
depends_on "alsa-lib"
depends_on "libxv"
end
on_intel do
depends_on "nasm" => :build
end
fails_with gcc: "5"
patch :DATA
def install
args = %W[
--prefix=#{prefix}
--enable-shared
--enable-pthreads
--enable-version3
--cc=#{ENV.cc}
--host-cflags=#{ENV.cflags}
--host-ldflags=#{ENV.ldflags}
--enable-ffplay
--enable-gnutls
--enable-gpl
--enable-libaom
--enable-libaribb24
--enable-libbluray
--enable-libdav1d
--enable-libmp3lame
--enable-libopus
--enable-librav1e
--enable-librist
--enable-librubberband
--enable-libsnappy
--enable-libsrt
--enable-libsvtav1
--enable-libtesseract
--enable-libtheora
--enable-libvidstab
--enable-libvmaf
--enable-libvorbis
--enable-libvpx
--enable-libwebp
--enable-libx264
--enable-libx265
--enable-libxml2
--enable-libxvid
--enable-lzma
--enable-libfontconfig
--enable-libfreetype
--enable-frei0r
--enable-libass
--enable-libopencore-amrnb
--enable-libopencore-amrwb
--enable-libopenjpeg
--enable-libspeex
--enable-libsoxr
--enable-libzmq
--enable-libzimg
--disable-libjack
--disable-indev=jack
]
# Needs corefoundation, coremedia, corevideo
args += %w[--enable-videotoolbox --enable-audiotoolbox] if OS.mac?
args << "--enable-neon" if Hardware::CPU.arm?
system "./configure", *args
system "make", "install"
# Build and install additional FFmpeg tools
system "make", "alltools"
bin.install Dir["tools/*"].select { |f| File.executable? f }
# Fix for Non-executables that were installed to bin/
mv bin/"python", pkgshare/"python", force: true
end
test do
# Create an example mp4 file
mp4out = testpath/"video.mp4"
system bin/"ffmpeg", "-filter_complex", "testsrc=rate=1:duration=1", mp4out
assert_predicate mp4out, :exist?
end
end
__END__
diff --git a/libavformat/flv.h b/libavformat/flv.h
index 3571b90279..e061a209d6 100644
--- a/libavformat/flv.h
+++ b/libavformat/flv.h
@@ -99,6 +99,7 @@ enum {
FLV_CODECID_PCM_MULAW = 8 << FLV_AUDIO_CODECID_OFFSET,
FLV_CODECID_AAC = 10<< FLV_AUDIO_CODECID_OFFSET,
FLV_CODECID_SPEEX = 11<< FLV_AUDIO_CODECID_OFFSET,
+ FLV_CODECID_OPUS = 13<< FLV_AUDIO_CODECID_OFFSET,
};
enum {
diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index d83edff727..6a6f30f77d 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -237,6 +237,11 @@ static int flv_same_audio_codec(AVCodecParameters *apar, int flags)
case FLV_CODECID_PCM_ALAW:
return apar->sample_rate == 8000 &&
apar->codec_id == AV_CODEC_ID_PCM_ALAW;
+ case FLV_CODECID_OPUS:
+ return apar->sample_rate == 48000 &&
+ apar->channels == 2 &&
+ apar->bits_per_coded_sample == 16 &&
+ apar->codec_id == AV_CODEC_ID_OPUS;
default:
return apar->codec_tag == (flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
}
@@ -295,6 +300,12 @@ static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream,
apar->sample_rate = 8000;
apar->codec_id = AV_CODEC_ID_PCM_ALAW;
break;
+ case FLV_CODECID_OPUS:
+ apar->sample_rate = 48000;
+ apar->channels = 2;
+ apar->bits_per_coded_sample = 16;
+ apar->codec_id = AV_CODEC_ID_OPUS;
+ break;
default:
avpriv_request_sample(s, "Audio codec (%x)",
flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 721f062811..f95472e6cb 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -60,6 +60,7 @@ static const AVCodecTag flv_audio_codec_ids[] = {
{ AV_CODEC_ID_PCM_MULAW, FLV_CODECID_PCM_MULAW >> FLV_AUDIO_CODECID_OFFSET },
{ AV_CODEC_ID_PCM_ALAW, FLV_CODECID_PCM_ALAW >> FLV_AUDIO_CODECID_OFFSET },
{ AV_CODEC_ID_SPEEX, FLV_CODECID_SPEEX >> FLV_AUDIO_CODECID_OFFSET },
+ { AV_CODEC_ID_OPUS, FLV_CODECID_OPUS >> FLV_AUDIO_CODECID_OFFSET },
{ AV_CODEC_ID_NONE, 0 }
};
@@ -128,7 +129,10 @@ static int get_audio_flags(AVFormatContext *s, AVCodecParameters *par)
if (par->codec_id == AV_CODEC_ID_AAC) // specs force these parameters
return FLV_CODECID_AAC | FLV_SAMPLERATE_44100HZ |
FLV_SAMPLESSIZE_16BIT | FLV_STEREO;
- else if (par->codec_id == AV_CODEC_ID_SPEEX) {
+ else if (par->codec_id == AV_CODEC_ID_OPUS) {
+ return FLV_CODECID_OPUS | FLV_SAMPLERATE_44100HZ |
+ FLV_SAMPLESSIZE_16BIT | FLV_STEREO;
+ } else if (par->codec_id == AV_CODEC_ID_SPEEX) {
if (par->sample_rate != 16000) {
av_log(s, AV_LOG_ERROR,
"FLV only supports wideband (16kHz) Speex audio\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment