ffmpeg: use one command to stream video/audio
This commit is contained in:
@@ -23,6 +23,12 @@ arecord -D hw:0,0 -f cd -r 44100 -c 2 | /app/ffmpeg -re -init_hw_device rkmpp=hw
|
||||
|
||||
|
||||
arecord -D hw:0,0 -f cd -r 44100 -c 2 | /app/ffmpeg -re -f wav -i pipe:0 -c:a aac -b:a 128k -ar 44100 -ac 2 -f rtp rtp://127.0.0.1:5006?pkt_size=1200
|
||||
|
||||
arecord -D hw:0,0 -f dat -r 48000 -c 2 --buffer-size=60 | /app/ffmpeg -re -init_hw_device rkmpp=hw -filter_hw_device hw \
|
||||
-f wav -i pipe:0 -map 0:a -c:a libopus -b:a 48000 -sample_fmt s16 -ssrc 1 -payload_type 111 -f rtp -max_delay 0 -application lowdelay \
|
||||
-f rtp rtp://127.0.0.1:5006?pkt_size=1200 \
|
||||
-i /dev/video0 -map 1:v -vf hwupload,scale_rkrga=h=720:force_original_aspect_ratio=1 -c:v h264_rkmpp -flags +low_delay -b:v 6000000 -framerate 60 -g 10 \
|
||||
-f rtp rtp://127.0.0.1:5004?pkt_size=1200
|
||||
*/
|
||||
|
||||
// https://jsfiddle.net/z7ms3u5r/
|
||||
@@ -30,50 +36,57 @@ arecord -D hw:0,0 -f cd -r 44100 -c 2 | /app/ffmpeg -re -f wav -i pipe:0 -c:a aa
|
||||
var ffmpeg *FFmpeg
|
||||
|
||||
type FFmpeg struct {
|
||||
*ExtProcess
|
||||
*PipedCmd
|
||||
config.FFmpeg
|
||||
}
|
||||
|
||||
func (f *FFmpeg) getCmd() string {
|
||||
return f.Commands[config.StreamInputVideoAudio]
|
||||
}
|
||||
|
||||
func (f *FFmpeg) SetBitrate(b int) {
|
||||
f.Bitrate = b
|
||||
if f.Bitrate < 0 {
|
||||
f.Bitrate = 6000
|
||||
}
|
||||
|
||||
f.ChangeArgs(f.FormatArgs())
|
||||
}
|
||||
|
||||
func (f *FFmpeg) SetFPS(fps int) {
|
||||
f.FPS = fps
|
||||
if f.FPS < 0 {
|
||||
f.FPS = 30
|
||||
} else if f.FPS > 60 {
|
||||
f.FPS = 60
|
||||
}
|
||||
|
||||
f.ChangeArgs(f.FormatArgs())
|
||||
}
|
||||
|
||||
func (f *FFmpeg) SetResolution(height int) {
|
||||
f.Height = height
|
||||
if f.Height <= 0 {
|
||||
f.Height = 1080
|
||||
} else if f.Height > 2060 {
|
||||
f.Height = 2060
|
||||
}
|
||||
|
||||
f.ChangeArgs(f.FormatArgs())
|
||||
}
|
||||
|
||||
func (f *FFmpeg) SetGOP(gop int) {
|
||||
f.GOP = gop
|
||||
if f.GOP < 0 {
|
||||
f.GOP = 0
|
||||
f.GOP = 2
|
||||
}
|
||||
|
||||
f.ChangeArgs(f.FormatArgs())
|
||||
}
|
||||
|
||||
func InitFFmpeg(path string, args []string) *FFmpeg {
|
||||
func (f *FFmpeg) ApplyOptions() {
|
||||
f.ChangeCmd(f.FormatCmd(f.getCmd()))
|
||||
}
|
||||
|
||||
func InitFFmpeg() *FFmpeg {
|
||||
cfg := config.Get().Video
|
||||
cmd := cfg.Commands[config.StreamInputVideoAudio]
|
||||
|
||||
ffmpeg = &FFmpeg{
|
||||
ExtProcess: Init(path, args),
|
||||
FFmpeg: config.Get().Video,
|
||||
PipedCmd: InitPipedCmd(cfg.FormatCmd(cmd)),
|
||||
FFmpeg: cfg,
|
||||
}
|
||||
return ffmpeg
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user