-
-
Notifications
You must be signed in to change notification settings - Fork 41
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: audio #79
base: dev
Are you sure you want to change the base?
feat: audio #79
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,19 @@ package constants | |
type FILE_TYPE int | ||
|
||
const ( | ||
Audio192K FILE_TYPE = iota | ||
ImagePng | ||
ImagePng FILE_TYPE = iota | ||
Video5M | ||
Video3M | ||
Video1M | ||
Video800K | ||
Video400K | ||
) | ||
|
||
const ( | ||
Audio192K FILE_TYPE = iota | ||
Audio128K | ||
) | ||
|
||
type FFMPEG_KWARGS int | ||
|
||
const ( | ||
|
@@ -52,6 +56,7 @@ const Scale = "scale" | |
|
||
var AudioFileTypeMap = map[FILE_TYPE]string{ | ||
Audio192K: "_audio192k.m4a", | ||
Audio128K: "_audio128k.m4a", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. m4a is supported only for dash protocol There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let discuss on this |
||
} | ||
|
||
var ImageFileTypeMap = map[FILE_TYPE]string{ | ||
|
@@ -68,6 +73,7 @@ var VideoFileTypeMap = map[FILE_TYPE]string{ | |
|
||
var AudioBitrateMap = map[FILE_TYPE]string{ | ||
Audio192K: "192k", | ||
Audio128K: "128k", | ||
} | ||
|
||
var VideoBitrateMap = map[FILE_TYPE]string{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package controllers | |
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
"net/http" | ||
"zestream-server/configs" | ||
"zestream-server/types" | ||
|
@@ -26,6 +27,36 @@ func (*Process) Video(c *gin.Context) { | |
return | ||
} | ||
|
||
log.Println("request", request) | ||
|
||
_, channel, queue, ctx, _ := configs.GetRabbitMQ() | ||
|
||
err = utils.PublishEvent(channel, queue, *ctx, jsonBytes) | ||
|
||
if err != nil { | ||
c.JSON(http.StatusExpectationFailed, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusCreated, gin.H{"status": "success"}) | ||
} | ||
|
||
func (*Process) Audio(c *gin.Context) { | ||
var request types.Audio | ||
|
||
if err := c.ShouldBindJSON(&request); err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
jsonBytes, err := json.Marshal(request) | ||
if err != nil { | ||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
log.Println("request", request) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: printing request twice |
||
|
||
_, channel, queue, ctx, _ := configs.GetRabbitMQ() | ||
|
||
err = utils.PublishEvent(channel, queue, *ctx, jsonBytes) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ import ( | |
ffmpeg "github.com/u2takey/ffmpeg-go" | ||
) | ||
|
||
func generateDash(fileName string, watermark types.WaterMark) { | ||
func generateVideoDash(fileName string, watermark types.WaterMark) { | ||
targetFile, err := utils.GetDownloadFilePathName(fileName) | ||
if err != nil { | ||
log.Println(err) | ||
|
@@ -45,6 +45,32 @@ func generateDash(fileName string, watermark types.WaterMark) { | |
utils.DeleteFile(targetFile) | ||
} | ||
|
||
func generateAudioDash(fileName string) { | ||
targetFile, err := utils.GetDownloadFilePathName(fileName) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
|
||
var fileNameStripped = utils.RemoveExtensionFromFile(fileName) | ||
|
||
outputPath, err := utils.GetOutputFilePathName(fileName, fileNameStripped) | ||
if err != nil { | ||
log.Println(err) | ||
return | ||
} | ||
|
||
var wg sync.WaitGroup | ||
|
||
wg.Add(len(constants.AudioFileTypeMap)) | ||
|
||
go generateAudioFiles(targetFile, outputPath, &wg) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets connect once to test |
||
|
||
wg.Wait() | ||
|
||
deleteVideoFiles(outputPath) | ||
utils.DeleteFile(targetFile) | ||
} | ||
|
||
func generateAudioFiles(targetFile string, outputPath string, wg *sync.WaitGroup) { | ||
for fileType, filePrefix := range constants.AudioFileTypeMap { | ||
var outputFile = outputPath + filePrefix | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets keep this const in the upper one, else iota value starts at 0, so ImagePng and Audio192K will have same value