-
-
Notifications
You must be signed in to change notification settings - Fork 837
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add detection of container/codec compatibility for live file streaming
* take into account container in generate transcodes task * add container info to DB * increment appSchema to 5
- Loading branch information
Showing
13 changed files
with
251 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE `scenes` ADD COLUMN `format` varchar(255); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package ffmpeg | ||
|
||
import ( | ||
"bytes" | ||
"github.com/stashapp/stash/pkg/logger" | ||
"os" | ||
) | ||
|
||
// detect file format from magic file number | ||
// https://github.com/lex-r/filetype/blob/73c10ad714e3b8ecf5cd1564c882ed6d440d5c2d/matchers/video.go | ||
|
||
func mkv(buf []byte) bool { | ||
return len(buf) > 3 && | ||
buf[0] == 0x1A && buf[1] == 0x45 && | ||
buf[2] == 0xDF && buf[3] == 0xA3 && | ||
containsMatroskaSignature(buf, []byte{'m', 'a', 't', 'r', 'o', 's', 'k', 'a'}) | ||
} | ||
|
||
func webm(buf []byte) bool { | ||
return len(buf) > 3 && | ||
buf[0] == 0x1A && buf[1] == 0x45 && | ||
buf[2] == 0xDF && buf[3] == 0xA3 && | ||
containsMatroskaSignature(buf, []byte{'w', 'e', 'b', 'm'}) | ||
} | ||
|
||
func containsMatroskaSignature(buf, subType []byte) bool { | ||
limit := 4096 | ||
if len(buf) < limit { | ||
limit = len(buf) | ||
} | ||
|
||
index := bytes.Index(buf[:limit], subType) | ||
if index < 3 { | ||
return false | ||
} | ||
|
||
return buf[index-3] == 0x42 && buf[index-2] == 0x82 | ||
} | ||
|
||
//returns container as string ("" on error or no match) | ||
//implements only mkv or webm as ffprobe can't distinguish between them | ||
//and not all browsers support mkv | ||
func MagicContainer(file_path string) Container { | ||
file, err := os.Open(file_path) | ||
if err != nil { | ||
logger.Errorf("[magicfile] %v", err) | ||
return "" | ||
} | ||
|
||
defer file.Close() | ||
|
||
buf := make([]byte, 4096) | ||
_, err = file.Read(buf) | ||
if err != nil { | ||
logger.Errorf("[magicfile] %v", err) | ||
return "" | ||
} | ||
|
||
if webm(buf) { | ||
return Webm | ||
} | ||
if mkv(buf) { | ||
return Matroska | ||
} | ||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.