diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 94469ec..b3e5f99 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: check-latest: true - run: go vet ./... - run: go test -coverprofile=coverage.txt -covermode=atomic ./... - - run: go install ./mp4tool + - run: go install ./cmd/mp4tool - name: Upload Coverage Report if: ${{ github.event_name == 'push' && matrix.os == 'ubuntu-latest' && matrix.go-version == '1.19' }} env: diff --git a/README.md b/README.md index 2c6acfd..61f5152 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ If you should reduce Read function calls, you can wrap the io.ReadSeeker by [buf Install mp4tool as follows: ```sh -go install github.com/abema/go-mp4/mp4tool@latest +go install github.com/abema/go-mp4/cmd/mp4tool@latest mp4tool -help ``` diff --git a/box.go b/box.go index 72a1379..c69e892 100644 --- a/box.go +++ b/box.go @@ -5,7 +5,7 @@ import ( "io" "math" - "github.com/abema/go-mp4/bitio" + "github.com/abema/go-mp4/internal/bitio" ) const LengthUnlimited = math.MaxUint32 diff --git a/box_types_iso14496_12.go b/box_types_iso14496_12.go index b3e46fd..f87fb46 100644 --- a/box_types_iso14496_12.go +++ b/box_types_iso14496_12.go @@ -5,8 +5,8 @@ import ( "fmt" "io" - "github.com/abema/go-mp4/bitio" - "github.com/abema/go-mp4/util" + "github.com/abema/go-mp4/internal/bitio" + "github.com/abema/go-mp4/internal/util" ) /*************************** btrt ****************************/ diff --git a/box_types_metadata.go b/box_types_metadata.go index a56145e..de21469 100644 --- a/box_types_metadata.go +++ b/box_types_metadata.go @@ -3,7 +3,7 @@ package mp4 import ( "fmt" - "github.com/abema/go-mp4/util" + "github.com/abema/go-mp4/internal/util" ) /*************************** ilst ****************************/ diff --git a/mp4tool/divide/divide.go b/cmd/mp4tool/internal/divide/divide.go similarity index 100% rename from mp4tool/divide/divide.go rename to cmd/mp4tool/internal/divide/divide.go diff --git a/mp4tool/dump/dump.go b/cmd/mp4tool/internal/dump/dump.go similarity index 98% rename from mp4tool/dump/dump.go rename to cmd/mp4tool/internal/dump/dump.go index 3ecf80c..42280b1 100644 --- a/mp4tool/dump/dump.go +++ b/cmd/mp4tool/internal/dump/dump.go @@ -9,7 +9,7 @@ import ( "strings" "github.com/abema/go-mp4" - "github.com/abema/go-mp4/mp4tool/util" + "github.com/abema/go-mp4/cmd/mp4tool/internal/util" "github.com/sunfish-shogi/bufseekio" "golang.org/x/term" ) diff --git a/mp4tool/dump/dump_test.go b/cmd/mp4tool/internal/dump/dump_test.go similarity index 99% rename from mp4tool/dump/dump_test.go rename to cmd/mp4tool/internal/dump/dump_test.go index 62e2f4d..8f1e592 100644 --- a/mp4tool/dump/dump_test.go +++ b/cmd/mp4tool/internal/dump/dump_test.go @@ -18,24 +18,24 @@ func TestDump(t *testing.T) { }{ { name: "sample.mp4 no-options", - file: "../../_examples/sample.mp4", + file: "../../../../testdata/sample.mp4", wants: sampleMP4Output, }, { name: "sample.mp4 with -full mvhd,loci option", - file: "../../_examples/sample.mp4", + file: "../../../../testdata/sample.mp4", options: []string{"-full", "mvhd,loci"}, wants: sampleMP4OutputFullMvhdLoci, }, { name: "sample.mp4 with -offset option", - file: "../../_examples/sample.mp4", + file: "../../../../testdata/sample.mp4", options: []string{"-offset"}, wants: sampleMP4OutputOffset, }, { name: "sample.mp4 with -hex option", - file: "../../_examples/sample.mp4", + file: "../../../../testdata/sample.mp4", options: []string{"-hex"}, wants: sampleMP4OutputHex, }, diff --git a/mp4tool/edit/edit.go b/cmd/mp4tool/internal/edit/edit.go similarity index 100% rename from mp4tool/edit/edit.go rename to cmd/mp4tool/internal/edit/edit.go diff --git a/mp4tool/extract/extract.go b/cmd/mp4tool/internal/extract/extract.go similarity index 96% rename from mp4tool/extract/extract.go rename to cmd/mp4tool/internal/extract/extract.go index 0d5235b..51f93e2 100644 --- a/mp4tool/extract/extract.go +++ b/cmd/mp4tool/internal/extract/extract.go @@ -7,7 +7,7 @@ import ( "os" "github.com/abema/go-mp4" - "github.com/abema/go-mp4/mp4tool/util" + "github.com/abema/go-mp4/cmd/mp4tool/internal/util" "github.com/sunfish-shogi/bufseekio" ) diff --git a/mp4tool/extract/extract_test.go b/cmd/mp4tool/internal/extract/extract_test.go similarity index 79% rename from mp4tool/extract/extract_test.go rename to cmd/mp4tool/internal/extract/extract_test.go index 60282e3..15a7f71 100644 --- a/mp4tool/extract/extract_test.go +++ b/cmd/mp4tool/internal/extract/extract_test.go @@ -18,19 +18,19 @@ func TestExtract(t *testing.T) { }{ { name: "sample.mp4/ftyp", - file: "../../_examples/sample.mp4", + file: "../../../../testdata/sample.mp4", boxType: "ftyp", expectedSize: 32, }, { name: "sample.mp4/mdhd", - file: "../../_examples/sample.mp4", + file: "../../../../testdata/sample.mp4", boxType: "mdhd", expectedSize: 64, // = 32 (1st trak) + 32 (2nd trak) }, { name: "sample_fragmented.mp4/trun", - file: "../../_examples/sample_fragmented.mp4", + file: "../../../../testdata/sample_fragmented.mp4", boxType: "trun", expectedSize: 452, }, @@ -56,11 +56,11 @@ func TestExtract(t *testing.T) { func TestValidation(t *testing.T) { // valid - require.Zero(t, Main([]string{"xxxx", "../../_examples/sample.mp4"})) + require.Zero(t, Main([]string{"xxxx", "../../../../testdata/sample.mp4"})) // invalid require.NotZero(t, Main([]string{})) require.NotZero(t, Main([]string{"xxxx"})) - require.NotZero(t, Main([]string{"xxxxx", "../../_examples/sample.mp4"})) + require.NotZero(t, Main([]string{"xxxxx", "../../../../testdata/sample.mp4"})) require.NotZero(t, Main([]string{"xxxx", "not_found.mp4"})) } diff --git a/mp4tool/probe/probe.go b/cmd/mp4tool/internal/probe/probe.go similarity index 100% rename from mp4tool/probe/probe.go rename to cmd/mp4tool/internal/probe/probe.go diff --git a/mp4tool/probe/probe_test.go b/cmd/mp4tool/internal/probe/probe_test.go similarity index 95% rename from mp4tool/probe/probe_test.go rename to cmd/mp4tool/internal/probe/probe_test.go index 1c65182..f98fc61 100644 --- a/mp4tool/probe/probe_test.go +++ b/cmd/mp4tool/internal/probe/probe_test.go @@ -18,18 +18,18 @@ func TestProbe(t *testing.T) { }{ { name: "sample.mp4 no-options", - file: "../../_examples/sample.mp4", + file: "../../../../testdata/sample.mp4", wants: sampleMP4JSONOutput, }, { name: "sample.mp4 format-json", - file: "../../_examples/sample.mp4", + file: "../../../../testdata/sample.mp4", options: []string{"-format", "json"}, wants: sampleMP4JSONOutput, }, { name: "sample.mp4 format-json", - file: "../../_examples/sample.mp4", + file: "../../../../testdata/sample.mp4", options: []string{"-format", "yaml"}, wants: sampleMP4YamlOutput, }, diff --git a/mp4tool/psshdump/psshdump.go b/cmd/mp4tool/internal/psshdump/psshdump.go similarity index 100% rename from mp4tool/psshdump/psshdump.go rename to cmd/mp4tool/internal/psshdump/psshdump.go diff --git a/mp4tool/psshdump/psshdump_test.go b/cmd/mp4tool/internal/psshdump/psshdump_test.go similarity index 92% rename from mp4tool/psshdump/psshdump_test.go rename to cmd/mp4tool/internal/psshdump/psshdump_test.go index 0fca5bf..e350135 100644 --- a/mp4tool/psshdump/psshdump_test.go +++ b/cmd/mp4tool/internal/psshdump/psshdump_test.go @@ -18,7 +18,7 @@ func TestPsshdump(t *testing.T) { }{ { name: "sample_init.encv.mp4", - file: "../../_examples/sample_init.encv.mp4", + file: "../../../../testdata/sample_init.encv.mp4", wants: "0:\n" + " offset: 1307\n" + " size: 52\n" + @@ -31,7 +31,7 @@ func TestPsshdump(t *testing.T) { }, { name: "sample_init.encv.mp4", - file: "../../_examples/sample_init.enca.mp4", + file: "../../../../testdata/sample_init.enca.mp4", wants: "0:\n" + " offset: 1307\n" + " size: 52\n" + diff --git a/mp4tool/util/util.go b/cmd/mp4tool/internal/util/util.go similarity index 100% rename from mp4tool/util/util.go rename to cmd/mp4tool/internal/util/util.go diff --git a/mp4tool/main.go b/cmd/mp4tool/main.go similarity index 79% rename from mp4tool/main.go rename to cmd/mp4tool/main.go index 1c159a1..5b368b9 100644 --- a/mp4tool/main.go +++ b/cmd/mp4tool/main.go @@ -4,12 +4,12 @@ import ( "fmt" "os" - "github.com/abema/go-mp4/mp4tool/divide" - "github.com/abema/go-mp4/mp4tool/dump" - "github.com/abema/go-mp4/mp4tool/edit" - "github.com/abema/go-mp4/mp4tool/extract" - "github.com/abema/go-mp4/mp4tool/probe" - "github.com/abema/go-mp4/mp4tool/psshdump" + "github.com/abema/go-mp4/cmd/mp4tool/internal/divide" + "github.com/abema/go-mp4/cmd/mp4tool/internal/dump" + "github.com/abema/go-mp4/cmd/mp4tool/internal/edit" + "github.com/abema/go-mp4/cmd/mp4tool/internal/extract" + "github.com/abema/go-mp4/cmd/mp4tool/internal/probe" + "github.com/abema/go-mp4/cmd/mp4tool/internal/psshdump" ) func main() { diff --git a/extract_test.go b/extract_test.go index ddb0812..3baef00 100644 --- a/extract_test.go +++ b/extract_test.go @@ -103,7 +103,7 @@ func TestExtractBoxWithPayload(t *testing.T) { for _, c := range testCases { t.Run(c.name, func(t *testing.T) { - f, err := os.Open("./_examples/sample.mp4") + f, err := os.Open("./testdata/sample.mp4") require.NoError(t, err) defer f.Close() @@ -166,7 +166,7 @@ func TestExtractBox(t *testing.T) { for _, c := range testCases { t.Run(c.name, func(t *testing.T) { - f, err := os.Open("./_examples/sample.mp4") + f, err := os.Open("./testdata/sample.mp4") require.NoError(t, err) defer f.Close() @@ -234,7 +234,7 @@ func TestExtractBoxes(t *testing.T) { for _, c := range testCases { t.Run(c.name, func(t *testing.T) { - f, err := os.Open("./_examples/sample.mp4") + f, err := os.Open("./testdata/sample.mp4") require.NoError(t, err) defer f.Close() @@ -251,7 +251,7 @@ func TestExtractBoxes(t *testing.T) { } func TestExtractDescendantBox(t *testing.T) { - f, err := os.Open("./_examples/sample.mp4") + f, err := os.Open("./testdata/sample.mp4") require.NoError(t, err) defer f.Close() diff --git a/bitio/bitio.go b/internal/bitio/bitio.go similarity index 100% rename from bitio/bitio.go rename to internal/bitio/bitio.go diff --git a/bitio/read.go b/internal/bitio/read.go similarity index 100% rename from bitio/read.go rename to internal/bitio/read.go diff --git a/bitio/read_test.go b/internal/bitio/read_test.go similarity index 100% rename from bitio/read_test.go rename to internal/bitio/read_test.go diff --git a/bitio/write.go b/internal/bitio/write.go similarity index 100% rename from bitio/write.go rename to internal/bitio/write.go diff --git a/bitio/write_test.go b/internal/bitio/write_test.go similarity index 100% rename from bitio/write_test.go rename to internal/bitio/write_test.go diff --git a/util/io.go b/internal/util/io.go similarity index 100% rename from util/io.go rename to internal/util/io.go diff --git a/util/io_test.go b/internal/util/io_test.go similarity index 100% rename from util/io_test.go rename to internal/util/io_test.go diff --git a/util/string.go b/internal/util/string.go similarity index 100% rename from util/string.go rename to internal/util/string.go diff --git a/util/string_test.go b/internal/util/string_test.go similarity index 100% rename from util/string_test.go rename to internal/util/string_test.go diff --git a/marshaller.go b/marshaller.go index b5c6686..18ff79a 100644 --- a/marshaller.go +++ b/marshaller.go @@ -8,7 +8,7 @@ import ( "math" "reflect" - "github.com/abema/go-mp4/bitio" + "github.com/abema/go-mp4/internal/bitio" ) const ( diff --git a/marshaller_test.go b/marshaller_test.go index fb4e317..ca99eb0 100644 --- a/marshaller_test.go +++ b/marshaller_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "github.com/abema/go-mp4/bitio" + "github.com/abema/go-mp4/internal/bitio" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/probe.go b/probe.go index e407b95..2ffaf7a 100644 --- a/probe.go +++ b/probe.go @@ -5,7 +5,7 @@ import ( "errors" "io" - "github.com/abema/go-mp4/bitio" + "github.com/abema/go-mp4/internal/bitio" ) type ProbeInfo struct { diff --git a/probe_test.go b/probe_test.go index 0c3dacf..6e62417 100644 --- a/probe_test.go +++ b/probe_test.go @@ -9,7 +9,7 @@ import ( ) func TestProbe(t *testing.T) { - f, err := os.Open("./_examples/sample.mp4") + f, err := os.Open("./testdata/sample.mp4") require.NoError(t, err) defer f.Close() @@ -75,7 +75,7 @@ func TestProbe(t *testing.T) { } func TestProbeEncryptedVideo(t *testing.T) { - f, err := os.Open("./_examples/sample_init.encv.mp4") + f, err := os.Open("./testdata/sample_init.encv.mp4") require.NoError(t, err) defer f.Close() @@ -94,7 +94,7 @@ func TestProbeEncryptedVideo(t *testing.T) { } func TestProbeEncryptedAudio(t *testing.T) { - f, err := os.Open("./_examples/sample_init.enca.mp4") + f, err := os.Open("./testdata/sample_init.enca.mp4") require.NoError(t, err) defer f.Close() @@ -111,7 +111,7 @@ func TestProbeEncryptedAudio(t *testing.T) { } func TestProbeWithFMP4(t *testing.T) { - f, err := os.Open("./_examples/sample_fragmented.mp4") + f, err := os.Open("./testdata/sample_fragmented.mp4") require.NoError(t, err) defer f.Close() @@ -165,7 +165,7 @@ func TestProbeWithFMP4(t *testing.T) { } func TestProbeFra(t *testing.T) { - f, err := os.Open("./_examples/sample_fragmented.mp4") + f, err := os.Open("./testdata/sample_fragmented.mp4") require.NoError(t, err) defer f.Close() diff --git a/read_test.go b/read_test.go index b4dd9f3..57f3793 100644 --- a/read_test.go +++ b/read_test.go @@ -10,7 +10,7 @@ import ( ) func TestReadBoxStructure(t *testing.T) { - f, err := os.Open("./_examples/sample.mp4") + f, err := os.Open("./testdata/sample.mp4") require.NoError(t, err) defer f.Close() @@ -74,7 +74,7 @@ func TestReadBoxStructure(t *testing.T) { assert.Equal(t, 57, n) } -// > mp4tool dump _examples/sample.mp4 | cat -n +// > mp4tool dump testdata/sample.mp4 | cat -n // 1 [ftyp] Size=32 MajorBrand="isom" MinorVersion=512 CompatibleBrands=[{CompatibleBrand="isom"}, {CompatibleBrand="iso2"}, {CompatibleBrand="avc1"}, {CompatibleBrand="mp41"}] // 2 [free] Size=8 Data=[...] (use "-full free" to show all) // 3 [mdat] Size=6402 Data=[...] (use "-full mdat" to show all) @@ -134,7 +134,7 @@ func TestReadBoxStructure(t *testing.T) { // 57 [loci] (unsupported box type) Size=35 Data=[...] (use "-full loci" to show all) func TestReadBoxStructureQT(t *testing.T) { - f, err := os.Open("./_examples/sample_qt.mp4") + f, err := os.Open("./testdata/sample_qt.mp4") require.NoError(t, err) defer f.Close() diff --git a/string.go b/string.go index 56afff1..4bc368e 100644 --- a/string.go +++ b/string.go @@ -7,7 +7,7 @@ import ( "reflect" "strconv" - "github.com/abema/go-mp4/util" + "github.com/abema/go-mp4/internal/util" ) type stringifier struct { diff --git a/_examples/sample.mp4 b/testdata/sample.mp4 similarity index 100% rename from _examples/sample.mp4 rename to testdata/sample.mp4 diff --git a/_examples/sample_fragmented.mp4 b/testdata/sample_fragmented.mp4 similarity index 100% rename from _examples/sample_fragmented.mp4 rename to testdata/sample_fragmented.mp4 diff --git a/_examples/sample_init.enca.mp4 b/testdata/sample_init.enca.mp4 similarity index 100% rename from _examples/sample_init.enca.mp4 rename to testdata/sample_init.enca.mp4 diff --git a/_examples/sample_init.encv.mp4 b/testdata/sample_init.encv.mp4 similarity index 100% rename from _examples/sample_init.encv.mp4 rename to testdata/sample_init.encv.mp4 diff --git a/_examples/sample_qt.mp4 b/testdata/sample_qt.mp4 similarity index 100% rename from _examples/sample_qt.mp4 rename to testdata/sample_qt.mp4