Compare commits

...

12 Commits

Author SHA1 Message Date
Cadey Ratio 35de98b1f6 test
Signed-off-by: Xe <me@christine.website>
2022-09-15 16:05:37 +00:00
Cadey Ratio d960234c10 make this use avif instead of heif
Signed-off-by: Xe <me@christine.website>
2022-09-15 15:55:41 +00:00
Kagami Hiiragi 9badc7c997
Merge pull request #15 from kmulvey/patch-1
give rhel some love
2022-06-23 07:47:12 +03:00
Kevin Mulvey d8fa7e3fea
give rhel some love
not everyone uses debian
2022-06-22 18:09:38 -06:00
Kagami Hiiragi 442e948cec
Merge pull request #11 from Quppa/master
avif CLI: Expose thread count config as command-line option
2021-01-18 11:07:12 +03:00
David Warner df3126083e Tweak usage string 2021-01-18 18:54:02 +11:00
David Warner 10418f2327 Expose thread count config as command-line option 2021-01-18 18:52:26 +11:00
Kagami Hiiragi be493f43b6
Merge pull request #8 from EwoutH/patch-1
Travis CI: Update Linux and macOS build environments
2019-10-14 20:28:13 +03:00
Ewout ter Hoeven 0bbead89c9
Travis CI: Update Linux and macOS build environments
- Update linux build environment from Ubuntu 16.04 Xenial to Ubuntu 18.04 Bionic
 - Update macOS build environment from macOS 10.13 with Xcode 9.4 to macOS 10.14 with Xcode 11.2
2019-10-14 11:13:00 +02:00
Kagami Hiiragi e54663f722 Limit max number of threads as per libaom req
Fix #7
2019-08-29 10:43:17 +03:00
Kagami Hiiragi 6487e4d17d
Update FUNDING.yml 2019-07-21 19:44:26 +03:00
Kagami Hiiragi a78339dcbe
Create FUNDING.yml 2019-07-21 18:51:15 +03:00
13 changed files with 121 additions and 11 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use flake

1
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1 @@
custom: https://www.blockchain.com/btc/payment_request?address=3LKKbbi34MHYRQSLV3ZiDGoKgUmCjhTumT&message=Kagami+open+source+projects+support

2
.gitignore vendored
View File

@ -5,3 +5,5 @@
/*.yuv
/*.xml
/*.png
.direnv

View File

@ -6,9 +6,10 @@ matrix:
- os: windows
if: tag IS present
- os: osx
osx_image: xcode11.2
if: tag IS present
- os: linux
dist: xenial
dist: bionic
install:
- if [[ $TRAVIS_OS_NAME != osx ]]; then set -e; fi

View File

@ -9,10 +9,16 @@ AV1 codec.
Make sure libaom is installed. On typical Linux distro just run:
#### Debian (and derivatives):
```bash
sudo apt-get install libaom-dev
```
#### RHEL (and derivatives):
```bash
sudo dnf install libaom-devel
```
## Usage
To use go-avif in your Go code:

17
avif.go
View File

@ -17,17 +17,19 @@ import (
// Encoder constants.
const (
MinThreads = 1
MaxThreads = 64
MinSpeed = 0
MaxSpeed = 8
MinQuality = 0
MaxQuality = 63
)
// Options are the encoding parameters. Threads ranges from 1, 0 means
// use all available cores. Speed ranges from MinSpeed to MaxSpeed.
// Quality ranges from MinQuality to MaxQuality, lower is better, 0
// means lossless encoding. SubsampleRatio specifies subsampling of the
// encoded image, nil means 4:2:0.
// Options are the encoding parameters. Threads ranges from MinThreads
// to MaxThreads, 0 means use all available cores. Speed ranges from
// MinSpeed to MaxSpeed. Quality ranges from MinQuality to MaxQuality,
// lower is better, 0 means lossless encoding. SubsampleRatio specifies
// subsampling of the encoded image, nil means 4:2:0.
type Options struct {
Threads int
Speed int
@ -113,6 +115,9 @@ func Encode(w io.Writer, m image.Image, o *Options) error {
}
if o.Threads == 0 {
o.Threads = runtime.NumCPU()
if o.Threads > MaxThreads {
o.Threads = MaxThreads
}
}
if o.SubsampleRatio == nil {
s := image.YCbCrSubsampleRatio420
@ -121,7 +126,7 @@ func Encode(w io.Writer, m image.Image, o *Options) error {
// o.SubsampleRatio = &yuvImg.SubsampleRatio
// }
}
if o.Threads < 1 {
if o.Threads < MinThreads || o.Threads > MaxThreads {
return OptionsError("bad threads number")
}
if o.Speed < MinSpeed || o.Speed > MaxSpeed {

View File

@ -8,8 +8,8 @@ import (
"io"
"os"
"github.com/Kagami/go-avif"
"github.com/docopt/docopt-go"
"tulpa.dev/cadey/avif"
)
const VERSION = "0.0.0"
@ -25,6 +25,7 @@ Options:
-o <dst>, --output=<dst> Destination filename
-q <qp>, --quality=<qp> Compression level (0..63), [default: 25]
-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)
--best Slowest compression method (alias for -s 0)
--fast Fastest compression method (alias for -s 8)
@ -35,6 +36,7 @@ type config struct {
Output string
Quality int
Speed int
Threads int
Lossless bool
Best bool
Fast bool
@ -62,6 +64,7 @@ func main() {
checkErr(err)
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.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")
if conf.Lossless {
conf.Quality = 0
@ -74,6 +77,7 @@ func main() {
avifOpts := avif.Options{
Speed: conf.Speed,
Quality: conf.Quality,
Threads: conf.Threads,
}
var src io.Reader

View File

@ -6,7 +6,7 @@ import (
"log"
"os"
"github.com/Kagami/go-avif"
"tulpa.dev/cadey/avif"
)
const usageHelp = "Usage: %s src.jpg dst.avif"

42
flake.lock Normal file
View File

@ -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
}

41
flake.nix Normal file
View File

@ -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
];
};
});
}

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module tulpa.dev/cadey/avif
go 1.19
require github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815

2
go.sum Normal file
View File

@ -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
View File

@ -725,13 +725,13 @@ func muxFrame(w io.Writer, m image.Image, subsampling image.YCbCrSubsampleRatio,
fileData := boxMDAT{data: obuData}
fileType := boxFTYP{
majorBrand: itemTypeMIF1,
majorBrand: itemTypeAVIF,
compatibleBrands: []fourCC{itemTypeMIF1, itemTypeAVIF, itemTypeMIAF},
}
metadata := boxMETA{
theHandler: boxHDLR{
handlerType: itemTypePICT,
name: "go-avif v0",
name: "tulpa.dev/cadey/avif v0",
},
primaryResource: boxPITM{itemID: 1},
itemLocations: boxILOC{