mirror of
https://github.com/fxkt-tech/liv
synced 2025-09-26 20:11:20 +08:00
fix(conv): add metadata
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
package sugar
|
||||
|
||||
import (
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
|
||||
type Single[I, O any] func(I) O
|
||||
|
||||
func Multi[I, O any](inS []I, f Single[I, O]) []O {
|
||||
@@ -20,12 +24,20 @@ func In[T comparable](elems []T, dest T) bool {
|
||||
}
|
||||
|
||||
// 为了能将if一行写下而存在,适用于极简场景,其它情况下不要使用这个函数!
|
||||
func If[F func()](cond bool, f F) {
|
||||
func If(cond bool, f func()) {
|
||||
if cond {
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
// if表达式
|
||||
func IfExpr[T any](cond bool, y, n T) T {
|
||||
if cond {
|
||||
return y
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// 为了能将for range一行写下而存在,适用于极简场景,其它情况下不要使用这个函数!
|
||||
func Range[T any](elems []T, f func(T)) {
|
||||
for _, elem := range elems {
|
||||
@@ -44,17 +56,25 @@ func Filter[T any](slices []T, satisfied func(T) bool) []T {
|
||||
return results
|
||||
}
|
||||
|
||||
// 将一个类型的列表转换成另一个类型的列表
|
||||
func MapTo[T1, T2 any](slices []T1, deal func(T1) (T2, error)) []T2 {
|
||||
// 将一个类型的列表转换成另一个类型的列表(全转换)
|
||||
func Map[T1, T2 any](slices []T1, deal func(T1) T2) []T2 {
|
||||
var results []T2
|
||||
for _, s := range slices {
|
||||
if t, err := deal(s); err == nil {
|
||||
results = append(results, t)
|
||||
}
|
||||
results = append(results, deal(s))
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
func ToMap[K constraints.Integer | string, V any](slices []V, deal func(V) (K, V)) map[K]V {
|
||||
results := make(map[K]V)
|
||||
for _, s := range slices {
|
||||
k, v := deal(s)
|
||||
results[k] = v
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
// 带缺省值的赋值
|
||||
func Get[T comparable](value, dv T) T {
|
||||
var zero T
|
||||
if value != zero {
|
||||
|
@@ -283,6 +283,8 @@ func (tc *Transcode) ConvertContainer(ctx context.Context, params *ConvertContai
|
||||
output.MaxMuxingQueueSize(4086),
|
||||
output.File(params.OutFile),
|
||||
}
|
||||
outputOpts = append(outputOpts, metadataOptionFromKV(params.Metadata)...)
|
||||
|
||||
outputs = append(outputs, output.New(outputOpts...))
|
||||
|
||||
return ffmpeg.New(tc.ffmpegOpts...).
|
||||
|
@@ -1,9 +1,10 @@
|
||||
package liv
|
||||
|
||||
type ConvertContainerParams struct {
|
||||
InFile string
|
||||
OutFile string
|
||||
Threads int32
|
||||
InFile string
|
||||
OutFile string
|
||||
Metadata []*KV
|
||||
Threads int32
|
||||
}
|
||||
|
||||
type TranscodeParams struct {
|
||||
|
Reference in New Issue
Block a user