Skip to content

Commit

Permalink
wip: add transition (I do not know)
Browse files Browse the repository at this point in the history
  • Loading branch information
DblK committed Jan 2, 2024
1 parent b96c1ff commit 2ca46af
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 3 deletions.
20 changes: 18 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const (
Stage
)

var conf *ShottowerConfig

Check failure on line 27 in config/config.go

View workflow job for this annotation

GitHub Actions / lint

conf is a global variable (gochecknoglobals)

func (s EndpointType) String() string {
switch s {
case V1:
Expand All @@ -48,11 +50,25 @@ type ShottowerConfig struct {
endpointType EndpointType
}

func NewShottowerConfig(baseURL string, endpointType EndpointType) ShottowerConfiguration {
return &ShottowerConfig{
func Init(baseURL string, endpointType EndpointType) error {

Check failure on line 53 in config/config.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary leading newline (whitespace)

// viper.SetConfigName("config")

// https://github.com/TakasBU/TakasBU/blob/main/initializers/loadEnv.go
// https://github.com/laixhe/goimg/blob/c27cdb95bdf9b09f36589c2d465c7a6ebdd44b92/config/config.go
// https://github.com/Bikram-Gyawali/LearningGoLang/blob/17f5c3a1048f4857e31652d3a139253be68ec9a9/day24_viper/utils/config.go
// https://articles.wesionary.team/environment-variable-configuration-in-your-golang-project-using-viper-4e8289ef664d

conf = &ShottowerConfig{
rootURL: baseURL,
endpointType: endpointType,
}

return nil
}

func Get() *ShottowerConfig {
return conf
}

func (s *ShottowerConfig) GetRootURL() string {
Expand Down
11 changes: 11 additions & 0 deletions go/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,12 @@ func (s *FFMPEG) toStringHandleSource(parameters []string) []string {
parameters = append(parameters, s.GenerateFiller("[email protected]"))
}

// Add transparent source for transition
parameters = append(parameters, "-f")
parameters = append(parameters, "lavfi")
parameters = append(parameters, "-i")
parameters = append(parameters, s.GenerateFiller("[email protected]"))

// Add background source
parameters = append(parameters, "-f")
parameters = append(parameters, "lavfi")
Expand Down Expand Up @@ -689,6 +695,11 @@ func (s *FFMPEG) ToString() []string {
"[" + cast.ToString(maxSource+addedSources) + "] concat=n=1:v=1,setpts=PTS-STARTPTS,format=yuva420p [overfiller" + cast.ToString(i) + "];"
}
}

// Add transition stream
addedSources = addedSources + 1
filterComplex = filterComplex + "[" + cast.ToString(maxSource+addedSources) + "] concat=n=1:v=1,setpts=PTS-STARTPTS,format=yuv420p [transition0]; [transition0] trim=start=0:end=" + cast.ToString(s.duration) + " [transition];"

// Add background stream
addedSources = addedSources + 1
filterComplex = filterComplex + "[" + cast.ToString(maxSource+addedSources) + "] concat=n=1:v=1,setpts=PTS-STARTPTS,format=yuv420p [bg0]; [bg0] trim=start=0:end=" + cast.ToString(s.duration) + " [bg];"
Expand Down
20 changes: 20 additions & 0 deletions go/ffmpeg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,24 @@ var _ = Describe("Ffmpeg", func() {
Expect(res).To(Equal("subtitles='/dev/test.mkv':stream_index=0[strack0c0]; [0:v] [strack0c0] overlay [vtrack0c0];"))
})
})
XDescribe("CloseTrack", func() {
var ff openapi.FFMPEGCommand
BeforeEach(func() {
ff = openapi.NewFFMPEGCommand()
_ = ff.AddSource("/dev/test.mkv", false)
})

It("Should merge subtitle track with video", func() {
// var sourceClip = 0
var trackNumber = 0
// var clipNumber = 0
// var index = 0
_ = ff.AddTrack(trackNumber)
_ = ff.AddClip(trackNumber, "[0] concat=n=1:v=1,setpts=PTS-STARTPTS,format=yuva420p [filler1];")
_ = ff.AddClip(trackNumber, "[1] concat=n=1:v=1,setpts=PTS-STARTPTS,format=yuva420p [filler2];")
_ = ff.CloseTrack(trackNumber)
res := ff.ToString()
Expect(res).To(BeNil())
})
})
})
8 changes: 8 additions & 0 deletions go/model_clip.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ func (s *Clip) ToFFMPEG(FFMPEGCommand FFMPEGCommand, sourceClip int, trackNumber
effects = append(effects, FFMPEGCommand.ClipResize(sourceClip, trackNumber, currentClip, 1))
}

// Apply Transition between clip and transparent reference
if s.Transition != nil {
// Use the invisible source "transition" to make the effect based on the current clip and the transparent one
// start = invisible + clip
// end = clip + invisible
fmt.Println("here")
}

_ = FFMPEGCommand.AddClip(
trackNumber,
FFMPEGCommand.ClipMerge(sourceClip, trackNumber, currentClip, effects),
Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ import (
)

func main() {
// TODO: Add test to main
// https://dev.to/techschoolguru/load-config-from-file-environment-variables-in-golang-with-viper-2j2d
log.Printf("Server started")

myConfig := config.NewShottowerConfig("http://0.0.0.0:4000", config.Stage)
// Find config file and load it!
// Use config
config.Init("http://0.0.0.0:4000", config.Stage)

Check failure on line 45 in main.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `config.Init` is not checked (errcheck)
myConfig := config.Get()

// TODO: Replace myConfig with call to config Package
EditAPIService := openapi.NewEditAPIService(myConfig)
EditAPIController := openapi.NewEditAPIController(EditAPIService)

Expand All @@ -64,4 +70,6 @@ func main() {
IdleTimeout: time.Second * 60,
}
log.Fatal(server.ListenAndServe())
// TODO: Add graceful shutdown
// https://github.com/miomiora/mio-init/blob/master/main.go
}

0 comments on commit 2ca46af

Please sign in to comment.