ffmpeg-cli-wrapper
ffmpeg-cli-wrapper copied to clipboard
[question] different input args for audio and video
Thought I'd post something new rather than continuing to post on https://github.com/bramp/ffmpeg-cli-wrapper/issues/16. I'm having trouble setting different inputs for audio and video which use different frameworks, for example the ffmpeg command:
ffmpeg -y -v info -f x11grab -draw_mouse 0 -r 30 -s 1280x720 -thread_queue_size 4096 -i :0.0+0,0 -f alsa -thread_queue_size 4096 -i hw:0,1,0 -acodec aac -strict -2 -ar 44100 -c:v libx264 -preset veryfast -maxrate 2976k -bufsize 5952k -pix_fmt yuv420p -r 30 -crf 25 -g 60 -tune zerolatency -f flv rtmp://a.rtmp.youtube.com/live2/XXX
Which would capture from the desktop for video and the sound card for audio. I tried using setInput("video=xxx:audio=xxx") like the example here, but ffmpeg didn't seem to recognize that format (maybe I screwed something up there or maybe because these input types are specific to the -f arg passed), plus, I think the corresponding -i and -f arguments (as well as other options for both audio and video) need to be in a proper order. For example, I tried this:
val ffmpegArgs = FFmpegBuilder()
.overrideOutputFiles(true)
.setVerbosity(FFmpegBuilder.Verbosity.INFO)
.addExtraArgs("-thread_queue_size", "4096")
.addExtraArgs("-f", "x11grab")
.addExtraArgs("-r", "30")
.addExtraArgs("-s", "1280x720")
.setInput(":0.0+0,0")
.addExtraArgs("-f", "alsa")
.addExtraArgs("-i", "hw:0,1,0")
.addOutput("rtmp://a.rtmp.youtube.com/live2/XXXX")
.setAudioCodec("aac")
.addExtraArgs("-strict", "-2")
.setAudioBitRate(44100)
.setVideoCodec("libx264")
.addExtraArgs("-preset", "veryfast")
.addExtraArgs("-maxrate", "2976k")
.addExtraArgs("-bufsize", "5952k")
.setVideoFrameRate(30.0)
.setVideoPixelFormat("yuv420p")
.setConstantRateFactor(25.0)
.addExtraArgs("-g", "60")
.addExtraArgs("-tune", "zerolatency")
.setFormat("flv")
.done()
.build()
Which yielded the following ffmpeg command:
ffmpeg -y -v info -thread_queue_size 4096 -f x11grab -r 30 -s 1280x720 -f alsa -i hw:0,1,0 -i :0.0+0,0 -f flv -crf 25 -vcodec libx264 -pix_fmt yuv420p -r 30/1 -acodec aac -b:a 44100 -strict -2 -preset veryfast -maxrate 2976k -bufsize 5952k -g 60 -tune zerolatency rtmp://a.rtmp.youtube.com/live2/XXX
But this doesn't work, as the -i :0.0+0,0 comes after -f alsa, when it needs to come before (in the previous 'block' of args for -f x11grab.
After reading the device docs some more, I wonder if this is really an ask for device support, which might look a little bit like the current output scheme where there's a different sub-builder for options for that output? So like:
val ffmpegArgs = FFmpegBuilder()
.overrideOutputFiles(true)
.setVerbosity(FFmpegBuilder.Verbosity.INFO)
.addExtraArgs("-thread_queue_size", "4096")
.setVideoInputDevice("x11grab")
.setInput(":0.0+0,0")
.setVideoFramerate(30)
.setVideoResoultion("1280x720")
.done()
.setAudioInputDevice("alsa")
.setInput("hw:0,1,0")
.done()
.addOutput("rtmp://a.rtmp.youtube.com/live2/XXXX")
.setAudioCodec("aac")
.addExtraArgs("-strict", "-2")
.setAudioBitRate(44100)
.setVideoCodec("libx264")
.addExtraArgs("-preset", "veryfast")
.addExtraArgs("-maxrate", "2976k")
.addExtraArgs("-bufsize", "5952k")
.setVideoFrameRate(30.0)
.setVideoPixelFormat("yuv420p")
.setConstantRateFactor(25.0)
.addExtraArgs("-g", "60")
.addExtraArgs("-tune", "zerolatency")
.setFormat("flv")
.done()
.build()