disable by default
parent
50ad3bb3db
commit
81507319dd
|
|
@ -12,8 +12,9 @@ import (
|
|||
"path"
|
||||
"show-rss/src/slow"
|
||||
"strconv"
|
||||
"golang.org/x/time/rate"
|
||||
"time"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
var EnvCksumBPS = func() int {
|
||||
|
|
@ -81,6 +82,11 @@ func One(ctx context.Context, p string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
log.Printf("asses.transcode(%s)...", shortp)
|
||||
if err := transcode(ctx, p); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ import (
|
|||
func TestOne(t *testing.T) {
|
||||
ctx := db.Test(t, context.Background())
|
||||
|
||||
os.Setenv("DO_TRANSCODE", "true")
|
||||
|
||||
d := t.TempDir()
|
||||
b, _ := os.ReadFile(path.Join("testdata", "survivor_au_S11E12.smoller.mkv"))
|
||||
p := path.Join(d, "f.mkv")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
package asses
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func EntrypointTranscode(ctx context.Context, p string) error {
|
||||
return transcode(ctx, p)
|
||||
}
|
||||
|
||||
func transcode(ctx context.Context, p string) error {
|
||||
if os.Getenv("NO_TRANSCODE") != "" || os.Getenv("DO_TRANSCODE") == "" {
|
||||
log.Printf("would transcode %s but $NO_TRANSCODE=x or $DO_TRANSCODE=", p)
|
||||
return nil
|
||||
}
|
||||
|
||||
output, err := ffprobe(ctx, "-i", p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
h264 := slices.ContainsFunc(strings.Split(output, "\n"), func(line string) bool {
|
||||
return strings.Contains(line, "tream #") && strings.Contains(line, "Video: ") && strings.Contains(line, "h264")
|
||||
})
|
||||
aac := slices.ContainsFunc(strings.Split(output, "\n"), func(line string) bool {
|
||||
return strings.Contains(line, "tream #") && strings.Contains(line, "Audio: ") && strings.Contains(line, "aac")
|
||||
})
|
||||
|
||||
if h264 && aac {
|
||||
return nil
|
||||
}
|
||||
|
||||
p2 := p + ".en" + path.Ext(p)
|
||||
if err := ffmpeg(ctx, "-y",
|
||||
"-i", p,
|
||||
"-vcodec", "libx264",
|
||||
"-acodec", "aac",
|
||||
p2,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
output2, err := ffprobe(ctx, "-i", p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
df := func(line string) bool {
|
||||
return !strings.Contains(line, "tream #")
|
||||
}
|
||||
originalStreams := slices.DeleteFunc(strings.Split(output, "\n"), df)
|
||||
newStreams := slices.DeleteFunc(strings.Split(output2, "\n"), df)
|
||||
if len(originalStreams) != len(newStreams) {
|
||||
return fmt.Errorf("stream count changed from transcode")
|
||||
}
|
||||
|
||||
return os.Rename(p2, p)
|
||||
}
|
||||
Loading…
Reference in New Issue