Compare commits
12 Commits
Author | SHA1 | Date |
---|---|---|
Cadey Ratio | 35de98b1f6 | |
Cadey Ratio | d960234c10 | |
Kagami Hiiragi | 9badc7c997 | |
Kevin Mulvey | d8fa7e3fea | |
Kagami Hiiragi | 442e948cec | |
David Warner | df3126083e | |
David Warner | 10418f2327 | |
Kagami Hiiragi | be493f43b6 | |
Ewout ter Hoeven | 0bbead89c9 | |
Kagami Hiiragi | e54663f722 | |
Kagami Hiiragi | 6487e4d17d | |
Kagami Hiiragi | a78339dcbe |
|
@ -0,0 +1 @@
|
||||||
|
custom: https://www.blockchain.com/btc/payment_request?address=3LKKbbi34MHYRQSLV3ZiDGoKgUmCjhTumT&message=Kagami+open+source+projects+support
|
|
@ -5,3 +5,5 @@
|
||||||
/*.yuv
|
/*.yuv
|
||||||
/*.xml
|
/*.xml
|
||||||
/*.png
|
/*.png
|
||||||
|
|
||||||
|
.direnv
|
||||||
|
|
|
@ -6,9 +6,10 @@ matrix:
|
||||||
- os: windows
|
- os: windows
|
||||||
if: tag IS present
|
if: tag IS present
|
||||||
- os: osx
|
- os: osx
|
||||||
|
osx_image: xcode11.2
|
||||||
if: tag IS present
|
if: tag IS present
|
||||||
- os: linux
|
- os: linux
|
||||||
dist: xenial
|
dist: bionic
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- if [[ $TRAVIS_OS_NAME != osx ]]; then set -e; fi
|
- if [[ $TRAVIS_OS_NAME != osx ]]; then set -e; fi
|
||||||
|
|
|
@ -9,10 +9,16 @@ AV1 codec.
|
||||||
|
|
||||||
Make sure libaom is installed. On typical Linux distro just run:
|
Make sure libaom is installed. On typical Linux distro just run:
|
||||||
|
|
||||||
|
#### Debian (and derivatives):
|
||||||
```bash
|
```bash
|
||||||
sudo apt-get install libaom-dev
|
sudo apt-get install libaom-dev
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### RHEL (and derivatives):
|
||||||
|
```bash
|
||||||
|
sudo dnf install libaom-devel
|
||||||
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
To use go-avif in your Go code:
|
To use go-avif in your Go code:
|
||||||
|
|
17
avif.go
17
avif.go
|
@ -17,17 +17,19 @@ import (
|
||||||
|
|
||||||
// Encoder constants.
|
// Encoder constants.
|
||||||
const (
|
const (
|
||||||
|
MinThreads = 1
|
||||||
|
MaxThreads = 64
|
||||||
MinSpeed = 0
|
MinSpeed = 0
|
||||||
MaxSpeed = 8
|
MaxSpeed = 8
|
||||||
MinQuality = 0
|
MinQuality = 0
|
||||||
MaxQuality = 63
|
MaxQuality = 63
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options are the encoding parameters. Threads ranges from 1, 0 means
|
// Options are the encoding parameters. Threads ranges from MinThreads
|
||||||
// use all available cores. Speed ranges from MinSpeed to MaxSpeed.
|
// to MaxThreads, 0 means use all available cores. Speed ranges from
|
||||||
// Quality ranges from MinQuality to MaxQuality, lower is better, 0
|
// MinSpeed to MaxSpeed. Quality ranges from MinQuality to MaxQuality,
|
||||||
// means lossless encoding. SubsampleRatio specifies subsampling of the
|
// lower is better, 0 means lossless encoding. SubsampleRatio specifies
|
||||||
// encoded image, nil means 4:2:0.
|
// subsampling of the encoded image, nil means 4:2:0.
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Threads int
|
Threads int
|
||||||
Speed int
|
Speed int
|
||||||
|
@ -113,6 +115,9 @@ func Encode(w io.Writer, m image.Image, o *Options) error {
|
||||||
}
|
}
|
||||||
if o.Threads == 0 {
|
if o.Threads == 0 {
|
||||||
o.Threads = runtime.NumCPU()
|
o.Threads = runtime.NumCPU()
|
||||||
|
if o.Threads > MaxThreads {
|
||||||
|
o.Threads = MaxThreads
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if o.SubsampleRatio == nil {
|
if o.SubsampleRatio == nil {
|
||||||
s := image.YCbCrSubsampleRatio420
|
s := image.YCbCrSubsampleRatio420
|
||||||
|
@ -121,7 +126,7 @@ func Encode(w io.Writer, m image.Image, o *Options) error {
|
||||||
// o.SubsampleRatio = &yuvImg.SubsampleRatio
|
// o.SubsampleRatio = &yuvImg.SubsampleRatio
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
if o.Threads < 1 {
|
if o.Threads < MinThreads || o.Threads > MaxThreads {
|
||||||
return OptionsError("bad threads number")
|
return OptionsError("bad threads number")
|
||||||
}
|
}
|
||||||
if o.Speed < MinSpeed || o.Speed > MaxSpeed {
|
if o.Speed < MinSpeed || o.Speed > MaxSpeed {
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/Kagami/go-avif"
|
|
||||||
"github.com/docopt/docopt-go"
|
"github.com/docopt/docopt-go"
|
||||||
|
"tulpa.dev/cadey/avif"
|
||||||
)
|
)
|
||||||
|
|
||||||
const VERSION = "0.0.0"
|
const VERSION = "0.0.0"
|
||||||
|
@ -25,6 +25,7 @@ Options:
|
||||||
-o <dst>, --output=<dst> Destination filename
|
-o <dst>, --output=<dst> Destination filename
|
||||||
-q <qp>, --quality=<qp> Compression level (0..63), [default: 25]
|
-q <qp>, --quality=<qp> Compression level (0..63), [default: 25]
|
||||||
-s <spd>, --speed=<spd> Compression speed (0..8), [default: 4]
|
-s <spd>, --speed=<spd> Compression speed (0..8), [default: 4]
|
||||||
|
-t <td>, --threads=<td> Number of threads (0..64, 0 for all available cores), [default: 0]
|
||||||
--lossless Lossless compression (alias for -q 0)
|
--lossless Lossless compression (alias for -q 0)
|
||||||
--best Slowest compression method (alias for -s 0)
|
--best Slowest compression method (alias for -s 0)
|
||||||
--fast Fastest compression method (alias for -s 8)
|
--fast Fastest compression method (alias for -s 8)
|
||||||
|
@ -35,6 +36,7 @@ type config struct {
|
||||||
Output string
|
Output string
|
||||||
Quality int
|
Quality int
|
||||||
Speed int
|
Speed int
|
||||||
|
Threads int
|
||||||
Lossless bool
|
Lossless bool
|
||||||
Best bool
|
Best bool
|
||||||
Fast bool
|
Fast bool
|
||||||
|
@ -62,6 +64,7 @@ func main() {
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
check(conf.Quality >= avif.MinQuality && conf.Quality <= avif.MaxQuality, "bad quality (0..63)")
|
check(conf.Quality >= avif.MinQuality && conf.Quality <= avif.MaxQuality, "bad quality (0..63)")
|
||||||
check(conf.Speed >= avif.MinSpeed && conf.Speed <= avif.MaxSpeed, "bad speed (0..8)")
|
check(conf.Speed >= avif.MinSpeed && conf.Speed <= avif.MaxSpeed, "bad speed (0..8)")
|
||||||
|
check(conf.Threads == 0 || (conf.Threads >= avif.MinThreads && conf.Threads <= avif.MaxThreads), "bad threads (0..64)")
|
||||||
check(!conf.Best || !conf.Fast, "can't use both --best and --fast")
|
check(!conf.Best || !conf.Fast, "can't use both --best and --fast")
|
||||||
if conf.Lossless {
|
if conf.Lossless {
|
||||||
conf.Quality = 0
|
conf.Quality = 0
|
||||||
|
@ -74,6 +77,7 @@ func main() {
|
||||||
avifOpts := avif.Options{
|
avifOpts := avif.Options{
|
||||||
Speed: conf.Speed,
|
Speed: conf.Speed,
|
||||||
Quality: conf.Quality,
|
Quality: conf.Quality,
|
||||||
|
Threads: conf.Threads,
|
||||||
}
|
}
|
||||||
|
|
||||||
var src io.Reader
|
var src io.Reader
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/Kagami/go-avif"
|
"tulpa.dev/cadey/avif"
|
||||||
)
|
)
|
||||||
|
|
||||||
const usageHelp = "Usage: %s src.jpg dst.avif"
|
const usageHelp = "Usage: %s src.jpg dst.avif"
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1663087123,
|
||||||
|
"narHash": "sha256-cNIRkF/J4mRxDtNYw+9/fBNq/NOA2nCuPOa3EdIyeDs=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "9608ace7009ce5bc3aeb940095e01553e635cbc7",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"id": "nixpkgs",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"type": "indirect"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs",
|
||||||
|
"utils": "utils"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"utils": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1659877975,
|
||||||
|
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
{
|
||||||
|
description = "/x/perimental code";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "nixpkgs/nixos-unstable";
|
||||||
|
utils.url = "github:numtide/flake-utils";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, utils }@attrs:
|
||||||
|
utils.lib.eachSystem [
|
||||||
|
"x86_64-linux"
|
||||||
|
"aarch64-linux"
|
||||||
|
"x86_64-darwin"
|
||||||
|
"aarch64-darwin"
|
||||||
|
] (system:
|
||||||
|
let
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
overlays = [
|
||||||
|
(final: prev: {
|
||||||
|
go = prev.go_1_19;
|
||||||
|
buildGoModule = prev.buildGo119Module;
|
||||||
|
})
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
in {
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
go
|
||||||
|
gopls
|
||||||
|
gotools
|
||||||
|
go-tools
|
||||||
|
|
||||||
|
pkg-config
|
||||||
|
libaom
|
||||||
|
libavif
|
||||||
|
];
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
module tulpa.dev/cadey/avif
|
||||||
|
|
||||||
|
go 1.19
|
||||||
|
|
||||||
|
require github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
|
|
@ -0,0 +1,2 @@
|
||||||
|
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh6AyO7hdCn/PkvCZXii8TGj7sbtEbQ=
|
||||||
|
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
|
4
mp4.go
4
mp4.go
|
@ -725,13 +725,13 @@ func muxFrame(w io.Writer, m image.Image, subsampling image.YCbCrSubsampleRatio,
|
||||||
|
|
||||||
fileData := boxMDAT{data: obuData}
|
fileData := boxMDAT{data: obuData}
|
||||||
fileType := boxFTYP{
|
fileType := boxFTYP{
|
||||||
majorBrand: itemTypeMIF1,
|
majorBrand: itemTypeAVIF,
|
||||||
compatibleBrands: []fourCC{itemTypeMIF1, itemTypeAVIF, itemTypeMIAF},
|
compatibleBrands: []fourCC{itemTypeMIF1, itemTypeAVIF, itemTypeMIAF},
|
||||||
}
|
}
|
||||||
metadata := boxMETA{
|
metadata := boxMETA{
|
||||||
theHandler: boxHDLR{
|
theHandler: boxHDLR{
|
||||||
handlerType: itemTypePICT,
|
handlerType: itemTypePICT,
|
||||||
name: "go-avif v0",
|
name: "tulpa.dev/cadey/avif v0",
|
||||||
},
|
},
|
||||||
primaryResource: boxPITM{itemID: 1},
|
primaryResource: boxPITM{itemID: 1},
|
||||||
itemLocations: boxILOC{
|
itemLocations: boxILOC{
|
||||||
|
|
Loading…
Reference in New Issue