Skip to content

Commit

Permalink
Add using wav format for ffmpeg transcoding to PCMA/PCMU
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed May 21, 2024
1 parent 54c8ca0 commit c41bddb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/ffmpeg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

```yaml
streams:
tts: ffmpeg:#input=-re -f lavfi -i "flite=text='1 2 3 4 5 6 7 8 9 0'"#audio=pcma
tts: ffmpeg:#input=-readrate 1 -readrate_initial_burst 0.001 -f lavfi -i "flite=text='1 2 3 4 5 6 7 8 9 0'"#audio=pcma
```
## Useful links
Expand Down
23 changes: 18 additions & 5 deletions internal/ffmpeg/ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var defaults = map[string]string{
// output
"output": "-user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}",
"output/mjpeg": "-f mjpeg -",
"output/wav": "-f wav -",

// `-preset superfast` - we can't use ultrafast because it doesn't support `-profile main -level 4.1`
// `-tune zerolatency` - for minimal latency
Expand Down Expand Up @@ -315,11 +316,23 @@ func parseArgs(s string) *ffmpeg.Args {
args.AddCodec("-an")
}

// transcoding to only mjpeg
if (args.Video == 1 && args.Audio == 0 && query.Get("video") == "mjpeg") ||
// no transcoding from mjpeg input
(args.Video == 0 && args.Audio == 0 && strings.Contains(args.Input, " mjpeg ")) {
args.Output = defaults["output/mjpeg"]
// change otput from RTSP to some other pipe format
switch {
case args.Video == 0 && args.Audio == 0:
// no transcoding from mjpeg input (ffmpeg device with support output as raw MJPEG)
if strings.Contains(args.Input, " mjpeg ") {
args.Output = defaults["output/mjpeg"]
}
case args.Video == 1 && args.Audio == 0:
if query.Get("video") == "mjpeg" {
args.Output = defaults["output/mjpeg"]
}
case args.Video == 0 && args.Audio == 1:
codec, _, _ := strings.Cut(query.Get("audio"), "/")
switch codec {
case "pcma", "pcmu", "pcml":
args.Output = defaults["output/wav"]
}
}

return args
Expand Down

0 comments on commit c41bddb

Please sign in to comment.