discord / lilliput

Resize images and animated GIFs in Go
https://discord.com/blog/how-discord-resizes-150-million-images-every-day-with-go-and-c
Other
1.95k stars 123 forks source link

Report whether video content is optimized for streaming. #140

Closed skidder closed 10 months ago

skidder commented 10 months ago

It could be useful to know whether the video content supports progressive download (moov atom is before the mdat atom/box) for optimized web streaming. Though this could be loosely inferred from the AVFormatContext flags, the most accurate method is to just inspect the MP4 atoms.

Resources

Handbrake docs Understanding the MPEG-4 moov Atom Progressive Playback

Benchmarks

Memory profile is unchanged, with an insignificant increase in time.

Benchmark before adding check for streamable mp4

Running tool: /home/discord/bin/go/bin/go test -benchmem -run=^$ -coverprofile=/tmp/vscode-gof1InVD/go-code-cover -bench ^BenchmarkIsStreamableWebMp4$ github.com/discord/lilliput

goos: linux
goarch: amd64
pkg: github.com/discord/lilliput
cpu: Intel(R) Xeon(R) CPU @ 3.10GHz
BenchmarkIsStreamableWebMp4-16           765       1537259 ns/op         173 B/op          4 allocs/op
PASS
coverage: 3.5% of statements
ok      github.com/discord/lilliput 1.377s

Benchmark with check for streamable mp4

Running tool: /home/discord/bin/go/bin/go test -benchmem -run=^$ -coverprofile=/tmp/vscode-goiNHYaO/go-code-cover -bench ^BenchmarkIsStreamableWebMp4$ github.com/discord/lilliput

goos: linux
goarch: amd64
pkg: github.com/discord/lilliput
cpu: Intel(R) Xeon(R) CPU @ 3.10GHz
BenchmarkIsStreamableWebMp4-16           729       1540653 ns/op         173 B/op          4 allocs/op
PASS
coverage: 3.7% of statements
ok      github.com/discord/lilliput 1.338s