LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Record multiple files in one ffmpeg command (https://www.linuxquestions.org/questions/linux-newbie-8/record-multiple-files-in-one-ffmpeg-command-4175593617/)

Sefyir 11-15-2016 10:36 PM

Record multiple files in one ffmpeg command
 
I'm trying to create a screencast with 4 inputs. I'd like to do all 4 recordings to 4 different files in one ffmepg command
  • Audio Output from Desktop (music files etc)
  • Microphone Output
  • Webcam Output
  • Desktop (X11) Output

I'd like to have 4 files when done recording, allowing me to interact with each part separately in a video editor (or mux with ffmpeg)

These 4 commands do the job - but they're not in sync, it's also difficult to stop them at the same time due to the nature of backgrounding processes.

Code:

# Record x11
ffmpeg -framerate 60 -video_size 1920x1080 -f x11grab -i :0.0 x11.mp4 &

# Record webcam
ffmpeg -framerate 30 -f v4l2 -i /dev/video0 webcam.mp4 &

# Record mic
ffmpeg -f alsa -ac 2 -ar 44100 -i pulse -acodec libfdk_aac mic.aac &

# Record Desktop Audio
ffmpeg -f pulse -ac 2 -i alsa_output.pci-0000_01_00.1.hdmi-stereo.monitor -acodec libfdk_aac desktop_audio.aac &

I attempted them combined like this:

Code:

ffmpeg -framerate 60 -video_size 1920x1080 -f x11grab -i :0.0 x11.mp4 \
 -f v4l2 -framerate 30 -i /dev/video0 webcam.mp4 \
 -f alsa -ac 2 -ar 44100 -i pulse -acodec libfdk_aac mic.aac \
 -f pulse -ac 2 -i alsa_output.pci-0000_01_00.1.hdmi-stereo.monitor -acodec libfdk_aac desktop_audio.aac

But the webcam.mp4 and x11.mp4 are identical and have audio, the desktop_audio.aac and mic.aac are both recordings of the microphone!
Is there something I'm doing wrong? I seem to be getting half of what I want

Sefyir 11-16-2016 01:20 AM

Ok, with the use of ffmpeg's map function this is possible and solved!
I tried to make it as human readable as possible, the inputs and mapping are respectfully ordered. Each file only contains their own map.
Eg, -f x11grab goes to -map 0:v:0 x11.mp4 and nothing else

Code:

  ffmpeg \
  -f x11grab -framerate 60 -video_size 1920x1080 -i :0.0 \
  -f v4l2 -framerate 30 -i /dev/video0 \
  -f alsa -ac 2 -ar 44100 -i pulse \
  -f pulse -ac 2 -i alsa_output.pci-0000_01_00.1.hdmi-stereo.monitor \
  -map 0:v:0 x11.mp4 \
  -map 1:v:0 webcam.mp4 \
  -map 2:a:0 -acodec libfdk_aac mic.aac \
  -map 3:a:0 -acodec libfdk_aac desktop_audio.aac



All times are GMT -5. The time now is 09:02 AM.