[feature] support processing of (many) more media types (#3090)

* initial work replacing our media decoding / encoding pipeline with ffprobe + ffmpeg

* specify the video codec to use when generating static image from emoji

* update go-storage library (fixes incompatibility after updating go-iotools)

* maintain image aspect ratio when generating a thumbnail for it

* update readme to show go-ffmpreg

* fix a bunch of media tests, move filesize checking to callers of media manager for more flexibility

* remove extra debug from error message

* fix up incorrect function signatures

* update PutFile to just use regular file copy, as changes are file is on separate partition

* fix remaining tests, remove some unneeded tests now we're working with ffmpeg/ffprobe

* update more tests, add more code comments

* add utilities to generate processed emoji / media outputs

* fix remaining tests

* add test for opus media file, add license header to utility cmds

* limit the number of concurrently available ffmpeg / ffprobe instances

* reduce number of instances

* further reduce number of instances

* fix envparsing test with configuration variables

* update docs and configuration with new media-{local,remote}-max-size variables
This commit is contained in:
kim
2024-07-12 09:39:47 +00:00
committed by GitHub
parent 5bc567196b
commit cde2fb6244
376 changed files with 8026 additions and 54091 deletions

View File

@@ -1,101 +0,0 @@
/*
exif-terminator
Copyright (C) 2022 SuperSeriousBusiness admin@gotosocial.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package terminator
import (
"encoding/binary"
"errors"
"io"
)
const (
riffHeaderSize = 4 * 3
)
var (
riffHeader = [4]byte{'R', 'I', 'F', 'F'}
webpHeader = [4]byte{'W', 'E', 'B', 'P'}
exifFourcc = [4]byte{'E', 'X', 'I', 'F'}
xmpFourcc = [4]byte{'X', 'M', 'P', ' '}
errNoRiffHeader = errors.New("no RIFF header")
errNoWebpHeader = errors.New("not a WEBP file")
)
type webpVisitor struct {
writer io.Writer
doneHeader bool
}
func fourCC(b []byte) [4]byte {
return [4]byte{b[0], b[1], b[2], b[3]}
}
func (v *webpVisitor) split(data []byte, atEOF bool) (advance int, token []byte, err error) {
// parse/write the header first
if !v.doneHeader {
if len(data) < riffHeaderSize {
// need the full header
return
}
if fourCC(data) != riffHeader {
err = errNoRiffHeader
return
}
if fourCC(data[8:]) != webpHeader {
err = errNoWebpHeader
return
}
if _, err = v.writer.Write(data[:riffHeaderSize]); err != nil {
return
}
advance += riffHeaderSize
data = data[riffHeaderSize:]
v.doneHeader = true
}
// need enough for fourcc and size
if len(data) < 8 {
return
}
size := int64(binary.LittleEndian.Uint32(data[4:]))
if (size & 1) != 0 {
// odd chunk size - extra padding byte
size++
}
// wait until there is enough
if int64(len(data)-8) < size {
return
}
fourcc := fourCC(data)
rawChunkData := data[8 : 8+size]
if fourcc == exifFourcc || fourcc == xmpFourcc {
// replace exif/xmp with blank
rawChunkData = make([]byte, size)
}
if _, err = v.writer.Write(data[:8]); err == nil {
if _, err = v.writer.Write(rawChunkData); err == nil {
advance += 8 + int(size)
}
}
return
}