Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: detect alpha passthrough from filename #1900

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions pkg/api/deovr.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
return cuepoints[i].TS < cuepoints[j].TS
})

var hasAlpha bool = false

// Set Scene projection IF either single video or all videos have same projection type
if sceneMultiProjection {
if videoFiles[0].VideoProjection == "mkx200" ||
Expand Down Expand Up @@ -496,6 +498,8 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
stereoMode = "off"
screenType = "dome"
}

hasAlpha = videoFiles[0].HasAlpha
}

title := scene.Title
Expand All @@ -522,6 +526,8 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
fmt.Println("Error:", err)
}
chromaKey = gjson.ParseBytes(ckup)
} else if hasAlpha {
chromaKey = gjson.Parse(`{"enabled":true,"hasAlpha":true,"h":0,"opacity":0,"s":0,"threshold":0,"v":0}`)
}

// set date to EPOCH in case it is missing or 0001-01-01
Expand Down Expand Up @@ -561,7 +567,7 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
deoScene.VideoPreview = fmt.Sprintf("%v/api/dms/preview/%v", session.DeoRequestHost, scene.SceneID)
}

if gjson.Valid(scene.ChromaKey) {
if gjson.Valid(scene.ChromaKey) || hasAlpha {
deoPtScene := DeoScenePassthrough{
ID: scene.ID,
Authorized: 1,
Expand All @@ -587,8 +593,16 @@ func (i DeoVRResource) getDeoScene(req *restful.Request, resp *restful.Response)
Categories: categories,
Fleshlight: deoScriptFiles,
HSProfile: deoHSPFiles,
ChromaKey: DeoSceneChromaKey{Enabled: chromaKey.Get("enabled").String(), HasAlpha: chromaKey.Get("hasAlpha").String(), H: chromaKey.Get("h").Float(), Opacity: chromaKey.Get("opacity").Float(), S: chromaKey.Get("s").Float(), Threshold: chromaKey.Get("threshold").Float(), V: chromaKey.Get("v").Float()},
VideoPreview: deoScene.VideoPreview,
ChromaKey: DeoSceneChromaKey{
Enabled: chromaKey.Get("enabled").String(),
HasAlpha: chromaKey.Get("hasAlpha").String(),
H: chromaKey.Get("h").Float(),
Opacity: chromaKey.Get("opacity").Float(),
S: chromaKey.Get("s").Float(),
Threshold: chromaKey.Get("threshold").Float(),
V: chromaKey.Get("v").Float(),
},
VideoPreview: deoScene.VideoPreview,
}
resp.WriteHeaderAndEntity(http.StatusOK, deoPtScene)
} else {
Expand Down
5 changes: 4 additions & 1 deletion pkg/api/heresphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,10 @@ func (i HeresphereResource) getHeresphereScene(req *restful.Request, resp *restf
}

var alphaPackedSettings *HereSphereAlphaPackedSettings = nil
if gjson.Valid(scene.ChromaKey) {
if videoFiles[0].HasAlpha {
alphaPackedSettings = &HereSphereAlphaPackedSettings{DefaultSettings: true}
addFeatureTag("Is Alpha Passthrough")
} else if gjson.Valid(scene.ChromaKey) {
result := gjson.Get(scene.ChromaKey, "hasAlpha")
if result.Exists() && result.Bool() {
alphaPackedSettings = &HereSphereAlphaPackedSettings{DefaultSettings: true}
Expand Down
9 changes: 9 additions & 0 deletions pkg/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,15 @@ func Migrate() {
return tx.Exec("update sites set scrape_stash = is_enabled").Error
},
},
{
ID: "0083-file-has-alpha",
Migrate: func(tx *gorm.DB) error {
type File struct {
HasAlpha bool `json:"has_alpha" gorm:"default:false"`
}
return tx.AutoMigrate(File{}).Error
},
},

// ===============================================================================================
// Put DB Schema migrations above this line and migrations that rely on the updated schema below
Expand Down
1 change: 1 addition & 0 deletions pkg/models/model_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type File struct {
VideoCodecName string `json:"video_codec_name" xbvrbackup:"video_codec_name"`
VideoDuration float64 `json:"duration" xbvrbackup:"duration"`
VideoProjection string `json:"projection" xbvrbackup:"projection"`
HasAlpha bool `json:"has_alpha" xbvrbackup:"has_alpha"`

HasHeatmap bool `json:"has_heatmap" xbvrbackup:"-"`
IsSelectedScript bool `json:"is_selected_script" xbvrbackup:"is_selected_script"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/models/model_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,9 +878,9 @@ func queryScenes(db *gorm.DB, r RequestSceneList) (*gorm.DB, *gorm.DB) {
case "Is Favourite":
where = "scenes.favourite = 1"
case "Is Passthrough":
where = "chroma_key <> ''"
where = "(chroma_key <> '' or exists (select 1 from files where files.scene_id = scenes.id and files.`type` = 'video' and files.has_alpha = true))"
case "Is Alpha Passthrough":
where = `chroma_key <> '' and chroma_key like '%"hasAlpha":true%'`
where = `((chroma_key <> '' and chroma_key like '%"hasAlpha":true%') or ` + "exists (select 1 from files where files.scene_id = scenes.id and files.`type` = 'video' and files.has_alpha = true))"
case "In Wishlist":
where = "wishlist = 1"
case "Stashdb Linked":
Expand Down
10 changes: 10 additions & 0 deletions pkg/tasks/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ func scanLocalVolume(vol models.Volume, db *gorm.DB, tlog *logrus.Entry) {
} else if ffdata.Format.DurationSeconds > 0.0 {
fl.VideoDuration = ffdata.Format.DurationSeconds
}
fl.HasAlpha = false

if vs.Height*2 == vs.Width || vs.Width > vs.Height {
fl.VideoProjection = "180_sbs"
Expand All @@ -312,6 +313,15 @@ func scanLocalVolume(vol models.Volume, db *gorm.DB, tlog *logrus.Entry) {
break
}
}
if fl.VideoProjection == "mkx200" || fl.VideoProjection == "mkx220" || fl.VideoProjection == "rf52" || fl.VideoProjection == "fisheye190" || fl.VideoProjection == "vrca220" {
// alpha passthrough only works with fisheye projections
for _, part := range nameparts {
if part == "alpha" {
fl.HasAlpha = true
break
}
}
}
}

if vs.Height == vs.Width {
Expand Down
Loading