From d868ad9e613d2f20676d2d9f6f2c0b245aa58da2 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Thu, 2 Apr 2026 15:18:22 +0200 Subject: [PATCH] Add `channels` to audio info --- transcoder/migrations/000003_add_audio_channels.down.sql | 5 +++++ transcoder/migrations/000003_add_audio_channels.up.sql | 5 +++++ transcoder/src/codec.go | 4 ++-- transcoder/src/info.go | 5 ++++- transcoder/src/metadata.go | 5 +++-- 5 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 transcoder/migrations/000003_add_audio_channels.down.sql create mode 100644 transcoder/migrations/000003_add_audio_channels.up.sql diff --git a/transcoder/migrations/000003_add_audio_channels.down.sql b/transcoder/migrations/000003_add_audio_channels.down.sql new file mode 100644 index 00000000..2f5955f7 --- /dev/null +++ b/transcoder/migrations/000003_add_audio_channels.down.sql @@ -0,0 +1,5 @@ +begin; + +alter table gocoder.audios drop column channels; + +commit; diff --git a/transcoder/migrations/000003_add_audio_channels.up.sql b/transcoder/migrations/000003_add_audio_channels.up.sql new file mode 100644 index 00000000..b32f6c83 --- /dev/null +++ b/transcoder/migrations/000003_add_audio_channels.up.sql @@ -0,0 +1,5 @@ +begin; + +alter table gocoder.audios add column channels int not null default 2; + +commit; diff --git a/transcoder/src/codec.go b/transcoder/src/codec.go index acfe8839..9c98c110 100644 --- a/transcoder/src/codec.go +++ b/transcoder/src/codec.go @@ -100,11 +100,11 @@ func GetMimeCodec(stream *ffprobe.Stream) *string { return &ret case "ac3": - ret := "mp4a.a5" + ret := "ac-3" return &ret case "eac3": - ret := "mp4a.a6" + ret := "ec-3" return &ret case "flac": diff --git a/transcoder/src/info.go b/transcoder/src/info.go index 3860aa63..e6761b97 100644 --- a/transcoder/src/info.go +++ b/transcoder/src/info.go @@ -17,7 +17,7 @@ import ( "gopkg.in/vansante/go-ffprobe.v2" ) -const InfoVersion = 3 +const InfoVersion = 4 type Versions struct { Info int32 `json:"info" db:"ver_info"` @@ -98,6 +98,8 @@ type Audio struct { Codec string `json:"codec" db:"codec"` /// The codec of this stream (defined as the RFC 6381). MimeCodec *string `json:"mimeCodec" db:"mime_codec"` + /// The number of channels that stream has. + Channels int `json:"channels" db:"channels"` /// The average bitrate of the audio in bytes/s Bitrate uint32 `json:"bitrate" db:"bitrate"` /// Is this stream the default one of it's type? @@ -280,6 +282,7 @@ func RetriveMediaInfo(path string, sha string) (*MediaInfo, error) { Language: NullIfUnd(lang.String()), Codec: stream.CodecName, MimeCodec: GetMimeCodec(stream), + Channels: stream.Channels, Bitrate: ParseUint(cmp.Or(stream.BitRate, mi.Format.BitRate)), IsDefault: stream.Disposition.Default != 0, } diff --git a/transcoder/src/metadata.go b/transcoder/src/metadata.go index df53eee3..ced4d9b0 100644 --- a/transcoder/src/metadata.go +++ b/transcoder/src/metadata.go @@ -319,7 +319,7 @@ func (s *MetadataService) storeFreshMetadata(ctx context.Context, path string, s ctx, ` insert into gocoder.audios(sha, idx, title, language, codec, mime_codec, is_default, bitrate) - values ($1, $2, $3, $4, $5, $6, $7, $8) + values ($1, $2, $3, $4, $5, $6, $7, $8, $9) on conflict (sha, idx) do update set sha = excluded.sha, idx = excluded.idx, @@ -327,10 +327,11 @@ func (s *MetadataService) storeFreshMetadata(ctx context.Context, path string, s language = excluded.language, codec = excluded.codec, mime_codec = excluded.mime_codec, + channels = excluded.channels, is_default = excluded.is_default, bitrate = excluded.bitrate `, - ret.Sha, a.Index, a.Title, a.Language, a.Codec, a.MimeCodec, a.IsDefault, a.Bitrate, + ret.Sha, a.Index, a.Title, a.Language, a.Codec, a.MimeCodec, a.Channels, a.IsDefault, a.Bitrate, ) } for _, s := range ret.Subtitles {