mirror of
https://github.com/asticode/go-astiav.git
synced 2025-10-29 18:51:46 +08:00
Now compatible with n7.0
This commit is contained in:
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -15,7 +15,7 @@ jobs:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
|
||||
env:
|
||||
FFMPEG_VERSION: n6.1.1
|
||||
FFMPEG_VERSION: n7.0
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
|
||||
2
Makefile
2
Makefile
@@ -1,4 +1,4 @@
|
||||
version=n6.1.1
|
||||
version=n7.0
|
||||
srcPath=tmp/$(version)/src
|
||||
patchPath=
|
||||
platform=
|
||||
|
||||
26
README.md
26
README.md
@@ -5,7 +5,7 @@
|
||||
|
||||
`astiav` is a Golang library providing C bindings for [ffmpeg](https://github.com/FFmpeg/FFmpeg)
|
||||
|
||||
It's only compatible with `ffmpeg` `n6.1.1`.
|
||||
It's only compatible with `ffmpeg` `n7.0`.
|
||||
|
||||
Its main goals are to:
|
||||
|
||||
@@ -14,23 +14,23 @@ Its main goals are to:
|
||||
- typed constants and flags
|
||||
- struct-based functions
|
||||
- ...
|
||||
- [x] provide the GO version of [ffmpeg examples](https://github.com/FFmpeg/FFmpeg/tree/n6.1.1/doc/examples)
|
||||
- [x] provide the GO version of [ffmpeg examples](https://github.com/FFmpeg/FFmpeg/tree/n7.0/doc/examples)
|
||||
- [x] be fully tested
|
||||
|
||||
# Examples
|
||||
|
||||
Examples are located in the [examples](examples) directory and mirror as much as possible the [ffmpeg examples](https://github.com/FFmpeg/FFmpeg/tree/n6.1.1/doc/examples).
|
||||
Examples are located in the [examples](examples) directory and mirror as much as possible the [ffmpeg examples](https://github.com/FFmpeg/FFmpeg/tree/n7.0/doc/examples).
|
||||
|
||||
|name|astiav|ffmpeg|
|
||||
|---|---|---|
|
||||
|BitStream Filtering|[see](examples/bit_stream_filtering/main.go)|X
|
||||
|Custom IO Demuxing|[see](examples/custom_io_demuxing/main.go)|[see](https://github.com/FFmpeg/FFmpeg/blob/n6.1.1/doc/examples/avio_reading.c)
|
||||
|Demuxing/Decoding|[see](examples/demuxing_decoding/main.go)|[see](https://github.com/FFmpeg/FFmpeg/blob/n6.1.1/doc/examples/demuxing_decoding.c)
|
||||
|Filtering|[see](examples/filtering/main.go)|[see](https://github.com/FFmpeg/FFmpeg/blob/n6.1.1/doc/examples/filtering_video.c)
|
||||
|Hardware Decoding|[see](examples/hardware_decoding/main.go)|[see](https://github.com/FFmpeg/FFmpeg/blob/n6.1.1/doc/examples/hw_decode.c)
|
||||
|Remuxing|[see](examples/remuxing/main.go)|[see](https://github.com/FFmpeg/FFmpeg/blob/n6.1.1/doc/examples/remuxing.c)
|
||||
|Scaling|[see](examples/scaling/main.go)|[see](https://github.com/FFmpeg/FFmpeg/blob/n6.1.1/doc/examples/scaling_video.c)
|
||||
|Transcoding|[see](examples/transcoding/main.go)|[see](https://github.com/FFmpeg/FFmpeg/blob/n6.1.1/doc/examples/transcoding.c)
|
||||
|Custom IO Demuxing|[see](examples/custom_io_demuxing/main.go)|[see](https://github.com/FFmpeg/FFmpeg/blob/n7.0/doc/examples/avio_reading.c)
|
||||
|Demuxing/Decoding|[see](examples/demuxing_decoding/main.go)|[see](https://github.com/FFmpeg/FFmpeg/blob/n7.0/doc/examples/demuxing_decoding.c)
|
||||
|Filtering|[see](examples/filtering/main.go)|[see](https://github.com/FFmpeg/FFmpeg/blob/n7.0/doc/examples/filtering_video.c)
|
||||
|Hardware Decoding|[see](examples/hardware_decoding/main.go)|[see](https://github.com/FFmpeg/FFmpeg/blob/n7.0/doc/examples/hw_decode.c)
|
||||
|Remuxing|[see](examples/remuxing/main.go)|[see](https://github.com/FFmpeg/FFmpeg/blob/n7.0/doc/examples/remuxing.c)
|
||||
|Scaling|[see](examples/scaling/main.go)|[see](https://github.com/FFmpeg/FFmpeg/blob/n7.0/doc/examples/scaling_video.c)
|
||||
|Transcoding|[see](examples/transcoding/main.go)|[see](https://github.com/FFmpeg/FFmpeg/blob/n7.0/doc/examples/transcoding.c)
|
||||
|
||||
*Tip: you can use the video sample located in the `testdata` directory for your tests*
|
||||
|
||||
@@ -49,9 +49,9 @@ For your GO code to pick up `ffmpeg` dependency automatically, you'll need to ad
|
||||
(don't forget to replace `{{ path to your working directory }}` with the absolute path to your working directory)
|
||||
|
||||
```sh
|
||||
export CGO_LDFLAGS="-L{{ path to your working directory }}/tmp/n6.1.1/lib/",
|
||||
export CGO_CFLAGS="-I{{ path to your working directory }}/tmp/n6.1.1/include/",
|
||||
export PKG_CONFIG_PATH="{{ path to your working directory }}/tmp/n6.1.1/lib/pkgconfig",
|
||||
export CGO_LDFLAGS="-L{{ path to your working directory }}/tmp/n7.0/lib/",
|
||||
export CGO_CFLAGS="-I{{ path to your working directory }}/tmp/n7.0/include/",
|
||||
export PKG_CONFIG_PATH="{{ path to your working directory }}/tmp/n7.0/lib/pkgconfig",
|
||||
```
|
||||
|
||||
# Why astiav?
|
||||
|
||||
@@ -95,7 +95,7 @@ func newChannelLayoutFromC(c *C.struct_AVChannelLayout) ChannelLayout {
|
||||
return ChannelLayout{c: c}
|
||||
}
|
||||
|
||||
func (l ChannelLayout) NbChannels() int {
|
||||
func (l ChannelLayout) Channels() int {
|
||||
return int(l.c.nb_channels)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
func TestChannelLayout(t *testing.T) {
|
||||
cl := ChannelLayoutStereo
|
||||
require.Equal(t, 2, cl.NbChannels())
|
||||
require.Equal(t, 2, cl.Channels())
|
||||
require.Equal(t, "stereo", cl.String())
|
||||
require.True(t, cl.Valid())
|
||||
require.True(t, cl.Equal(ChannelLayoutStereo))
|
||||
|
||||
@@ -83,14 +83,6 @@ func (cc *CodecContext) SetBitRate(bitRate int64) {
|
||||
cc.c.bit_rate = C.int64_t(bitRate)
|
||||
}
|
||||
|
||||
func (cc *CodecContext) Channels() int {
|
||||
return int(cc.c.channels)
|
||||
}
|
||||
|
||||
func (cc *CodecContext) SetChannels(channels int) {
|
||||
cc.c.channels = C.int(channels)
|
||||
}
|
||||
|
||||
func (cc *CodecContext) ChannelLayout() ChannelLayout {
|
||||
l, _ := newChannelLayoutFromC(&cc.c.ch_layout).clone()
|
||||
return l
|
||||
|
||||
@@ -53,7 +53,6 @@ func TestCodecContext(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 161 kb/s", cc2.String())
|
||||
require.Equal(t, int64(161052), cc2.BitRate())
|
||||
require.Equal(t, 2, cc2.Channels())
|
||||
require.True(t, cc2.ChannelLayout().Equal(ChannelLayoutStereo))
|
||||
require.Equal(t, CodecIDAac, cc2.CodecID())
|
||||
require.Equal(t, 1024, cc2.FrameSize())
|
||||
@@ -81,7 +80,6 @@ func TestCodecContext(t *testing.T) {
|
||||
defer cc4.Free()
|
||||
cc4.SetBitRate(1)
|
||||
cc4.SetChannelLayout(ChannelLayout21)
|
||||
cc4.SetChannels(3)
|
||||
cc4.SetFlags(NewCodecContextFlags(4))
|
||||
cc4.SetFlags2(NewCodecContextFlags2(5))
|
||||
cc4.SetFramerate(NewRational(6, 1))
|
||||
@@ -102,7 +100,6 @@ func TestCodecContext(t *testing.T) {
|
||||
cc4.SetExtraHardwareFrames(4)
|
||||
require.Equal(t, int64(1), cc4.BitRate())
|
||||
require.True(t, cc4.ChannelLayout().Equal(ChannelLayout21))
|
||||
require.Equal(t, 3, cc4.Channels())
|
||||
require.Equal(t, NewCodecContextFlags(4), cc4.Flags())
|
||||
require.Equal(t, NewCodecContextFlags2(5), cc4.Flags2())
|
||||
require.Equal(t, NewRational(6, 1), cc4.Framerate())
|
||||
@@ -127,14 +124,14 @@ func TestCodecContext(t *testing.T) {
|
||||
defer cc5.Free()
|
||||
err = cc5.FromCodecParameters(s2.CodecParameters())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 2, cc5.Channels())
|
||||
require.Equal(t, s2.CodecParameters().CodecID(), cc5.CodecID())
|
||||
|
||||
cp1 := AllocCodecParameters()
|
||||
require.NotNil(t, cp1)
|
||||
defer cp1.Free()
|
||||
err = cc5.ToCodecParameters(cp1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 2, cp1.Channels())
|
||||
require.Equal(t, cc5.CodecID(), cp1.CodecID())
|
||||
|
||||
cc6 := AllocCodecContext(nil)
|
||||
require.NotNil(t, cc6)
|
||||
|
||||
@@ -78,7 +78,6 @@ const (
|
||||
CodecIDAvrp = CodecID(C.AV_CODEC_ID_AVRP)
|
||||
CodecIDAvs = CodecID(C.AV_CODEC_ID_AVS)
|
||||
CodecIDAvui = CodecID(C.AV_CODEC_ID_AVUI)
|
||||
CodecIDAyuv = CodecID(C.AV_CODEC_ID_AYUV)
|
||||
CodecIDBethsoftvid = CodecID(C.AV_CODEC_ID_BETHSOFTVID)
|
||||
CodecIDBfi = CodecID(C.AV_CODEC_ID_BFI)
|
||||
CodecIDBinData = CodecID(C.AV_CODEC_ID_BIN_DATA)
|
||||
|
||||
@@ -37,14 +37,6 @@ func (cp *CodecParameters) SetChannelLayout(l ChannelLayout) {
|
||||
l.copy(&cp.c.ch_layout) //nolint: errcheck
|
||||
}
|
||||
|
||||
func (cp *CodecParameters) Channels() int {
|
||||
return int(cp.c.channels)
|
||||
}
|
||||
|
||||
func (cp *CodecParameters) SetChannels(c int) {
|
||||
cp.c.channels = C.int(c)
|
||||
}
|
||||
|
||||
func (cp *CodecParameters) CodecID() CodecID {
|
||||
return CodecID(cp.c.codec_id)
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ func TestCodecParameters(t *testing.T) {
|
||||
|
||||
cp2 := s2.CodecParameters()
|
||||
require.Equal(t, int64(161052), cp2.BitRate())
|
||||
require.Equal(t, 2, cp2.Channels())
|
||||
require.True(t, cp2.ChannelLayout().Equal(ChannelLayoutStereo))
|
||||
require.Equal(t, CodecIDAac, cp2.CodecID())
|
||||
require.Equal(t, CodecTag(0x6134706d), cp2.CodecTag())
|
||||
@@ -47,21 +46,21 @@ func TestCodecParameters(t *testing.T) {
|
||||
defer cp3.Free()
|
||||
err = cp2.Copy(cp3)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 2, cp3.Channels())
|
||||
require.Equal(t, cp2.CodecID(), cp3.CodecID())
|
||||
|
||||
cc4 := AllocCodecContext(nil)
|
||||
require.NotNil(t, cc4)
|
||||
defer cc4.Free()
|
||||
err = cp2.ToCodecContext(cc4)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 2, cc4.Channels())
|
||||
require.Equal(t, cp2.CodecID(), cc4.CodecID())
|
||||
|
||||
cp5 := AllocCodecParameters()
|
||||
require.NotNil(t, cp5)
|
||||
defer cp5.Free()
|
||||
err = cp5.FromCodecContext(cc4)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 2, cp5.Channels())
|
||||
require.Equal(t, cc4.CodecID(), cp5.CodecID())
|
||||
|
||||
cp6 := AllocCodecParameters()
|
||||
require.NotNil(t, cp6)
|
||||
@@ -69,8 +68,6 @@ func TestCodecParameters(t *testing.T) {
|
||||
cp6.SetChannelLayout(ChannelLayout21)
|
||||
require.True(t, cp6.ChannelLayout().Equal(ChannelLayout21))
|
||||
defer cp6.Free()
|
||||
cp6.SetChannels(3)
|
||||
require.Equal(t, 3, cp6.Channels())
|
||||
cp6.SetCodecID(CodecIDRawvideo)
|
||||
require.Equal(t, CodecIDRawvideo, cp6.CodecID())
|
||||
cp6.SetCodecTag(CodecTag(2))
|
||||
|
||||
@@ -269,7 +269,6 @@ func openOutputFile() (err error) {
|
||||
} else {
|
||||
s.encCodecContext.SetChannelLayout(s.decCodecContext.ChannelLayout())
|
||||
}
|
||||
s.encCodecContext.SetChannels(s.decCodecContext.Channels())
|
||||
s.encCodecContext.SetSampleRate(s.decCodecContext.SampleRate())
|
||||
if v := s.encCodec.SampleFormats(); len(v) > 0 {
|
||||
s.encCodecContext.SetSampleFormat(v[0])
|
||||
|
||||
@@ -33,7 +33,7 @@ func TestFormatContext(t *testing.T) {
|
||||
|
||||
sdp, err := fc1.SDPCreate()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "v=0\r\no=- 0 0 IN IP4 127.0.0.1\r\ns=Big Buck Bunny\r\nt=0 0\r\na=tool:libavformat 60.16.100\r\nm=video 0 RTP/AVP 96\r\nb=AS:441\r\na=rtpmap:96 H264/90000\r\na=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z0LADasgKDPz4CIAAAMAAgAAAwBhHihUkA==,aM48gA==; profile-level-id=42C00D\r\na=control:streamid=0\r\nm=audio 0 RTP/AVP 97\r\nb=AS:161\r\na=rtpmap:97 MPEG4-GENERIC/48000/2\r\na=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=1190\r\na=control:streamid=1\r\n", sdp)
|
||||
require.Equal(t, "v=0\r\no=- 0 0 IN IP4 127.0.0.1\r\ns=Big Buck Bunny\r\nt=0 0\r\na=tool:libavformat 61.1.100\r\nm=video 0 RTP/AVP 96\r\nb=AS:441\r\na=rtpmap:96 H264/90000\r\na=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z0LADasgKDPz4CIAAAMAAgAAAwBhHihUkA==,aM48gA==; profile-level-id=42C00D\r\na=control:streamid=0\r\nm=audio 0 RTP/AVP 97\r\nb=AS:161\r\na=rtpmap:97 MPEG4-GENERIC/48000/2\r\na=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=1190\r\na=control:streamid=1\r\n", sdp)
|
||||
|
||||
fc2, err := AllocOutputFormatContext(nil, "", "/tmp/test.mp4")
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -15,7 +15,7 @@ WORKDIR /opt/ffmpeg/src
|
||||
|
||||
RUN \
|
||||
git clone https://github.com/FFmpeg/FFmpeg /opt/ffmpeg/src && \
|
||||
git checkout n6.1.1
|
||||
git checkout n7.0
|
||||
|
||||
RUN \
|
||||
./configure --prefix=.. && \
|
||||
|
||||
@@ -127,7 +127,6 @@ const (
|
||||
PixelFormatVaapi = PixelFormat(C.AV_PIX_FMT_VAAPI)
|
||||
PixelFormatVdpau = PixelFormat(C.AV_PIX_FMT_VDPAU)
|
||||
PixelFormatVideotoolbox = PixelFormat(C.AV_PIX_FMT_VIDEOTOOLBOX)
|
||||
PixelFormatXvmc = PixelFormat(C.AV_PIX_FMT_XVMC)
|
||||
PixelFormatXyz12Be = PixelFormat(C.AV_PIX_FMT_XYZ12BE)
|
||||
PixelFormatXyz12Le = PixelFormat(C.AV_PIX_FMT_XYZ12LE)
|
||||
PixelFormatY400A = PixelFormat(C.AV_PIX_FMT_Y400A)
|
||||
|
||||
Reference in New Issue
Block a user