FFMPEG: How to add two more audio streams? - audio

This is my already working stream:
ffmpeg -f lavfi -i anullsrc -rtsp_transport tcp -i rtsp://stream1video -i rtsp://stream2audio -c:v copy -map 1:v -map 2:a -preset veryfast -pix_fmt + -c:a aac -f flv rtmp://a.rtmp.youtube.com/....
Now I would like to add two more audio files in the background in a loop.
something like this:
-i /1.aac -i /2.aac
So it should be something like:
ffmpeg -f lavfi -i anullsrc -rtsp_transport tcp -i rtsp://stream1video -i rtsp://stream2audio -stream_loop 1 -i /1.aac -stream_loop 1 -i 2.aac -c:v copy -map 1:v -map 2:a -map 3:a -map 4:a -preset veryfast -pix_fmt + -c:a aac -f flv rtmp://a.rtmp.youtube.com/....
But unfortunately, it doesn't work.
Any tips?

Assuming you want to downmix all three audio streams into one add the amix filter:
ffmpeg -rtsp_transport tcp -i rtsp://stream1video -i rtsp://stream2audio -re -stream_loop -1 -i 1.aac -re -stream_loop -1 -i 2.aac -filter_complex "[1:a][2:a][3:a]amix=inputs=3[a]" -map 0:v -map "[a]" -c:a aac -f flv rtmp://a.rtmp.youtube.com/

Related

ffmpeg: Generate empty audio and video (working for video)

I'm trying to generate a black video with FFMPEG. I have accomplished this with the following:
ffmpeg -t 5 -f lavfi -i color=c=black:s=1920x1080 -c:v libx264 -tune stillimage -pix_fmt yuv420p out.mp4
Unfortunately this video doesn't have any audio tracks. Following this, I have tried to insert -i anullsrc=channel_layout=stereo:sample_rate=44100:
ffmpeg -t 5 -i anullsrc=channel_layout=stereo:sample_rate=44100 -f lavfi -i color=c=black:s=1920x1080 -c:v libx264 -tune stillimage -pix_fmt yuv420p out.mp4
Unfortunately this gives the error:
anullsrc=channel_layout=stereo:sample_rate=44100: No such file or
directory
How can I modify my initial script to generate a video with empty audio?
anullsrc is also a source filter so it too needs -f lavfi before it.
ffmpeg -f lavfi -t 5 -i color=c=black:s=1920x1080 -f lavfi -t 5 -i anullsrc=channel_layout=stereo:sample_rate=44100 -c:v libx264 -tune stillimage -pix_fmt yuv420p out.mp4

ffmpeg output to multiple rtmp simultaneously

i have this situation:
i need stream to 3 different rtmp
1 rtmp is normal all the audio and video
2 rtmp is the video but different audio
3 rtmp is only audio of first video
this my elaboration...
ffmpeg -re -i /usr/VIDEO/my_video.mp4 -i /usr/VIDEO/x_audio.mp3 \
-map 0:v -c:v libx264 -vf format=yuv420p -b:v 2000k -bufsize 3000k -maxrate 2000k -s 1024X576 -g 60 -map 0:a -c:a aac -b:a 192k -ar 44100 -f flv rtmp://my_ip/live/pass \
-map 0:v -c:v libx264 -vf format=yuv420p -b:v 2000k -bufsize 3000k -maxrate 2000k -s 1024X576 -g 60 -map 1:a -streamloop -shortest -f flv rtmp://my_ip/noaudio/pass \
-map 0:a aac -b:a 192k -ar 44100 -f flv rtmp://my_ip/only_audio/pass
i was thinking was ok, but is not.
Where I have misstake
ok find solution
ffmpeg -re -i /usr/VIDEO/my_video.mp4 -re -i /usr/VIDEO/xaudio.mp3 \
-map 0 -c:v libx264 -vf format=yuv420p -b:v 2000k -bufsize 3000k -maxrate 2000k -s 1024X576 -g 60 -c:a aac -b:a 192k -ar 44100 -f flv rtmp://my_ip/live/pass \
-map 0:v -c:v libx264 -vf format=yuv420p -b:v 2000k -bufsize 3000k -maxrate 2000k -s 1024X576 -g 60 -map 1:a -c:a aac -b:a 192k -ar 44100 -f flv rtmp://my_ip/noaudio/pass \
-map 0:a -c:a aac -b:a 192k -ar 44100 -f flv rtmp://my_ip/onlyaudio/pass
and like that gonna work
for looping the audio add -stream_loop (--NUMBER--) before the audio where (--NUMBER--) sis the times that should repeat
once -stream_loop 1
twice 1nce -stream_loop 2
3 times 1nce -stream_loop 3
... and so on
ffmpeg -re -i /usr/VIDEO/my_video.mp4 -stream_loop (--NUMBER--) -re -i /usr/VIDEO/xaudio.mp3 \
-map 0 -c:v libx264 -vf format=yuv420p -b:v 2000k -bufsize 3000k -maxrate 2000k -s 1024X576 -g 60 -c:a aac -b:a 192k -ar 44100 -f flv rtmp://my_ip/live/pass \
-map 0:v -c:v libx264 -vf format=yuv420p -b:v 2000k -bufsize 3000k -maxrate 2000k -s 1024X576 -g 60 -map 1:a -c:a aac -b:a 192k -ar 44100 -f flv rtmp://my_ip/noaudio/pass \
-map 0:a -c:a aac -b:a 192k -ar 44100 -f flv rtmp://my_ip/onlyaudio/pass
Use the tee muxer. It's more complicated but more efficient: you can encode streams once and re-use them for multiple outputs.
ffmpeg -re -i video.mp4 -re -i audio.mp3 -map 0 -map 1:a -c:v libx264 -c:a aac -vf "scale=1024:-2,format=yuv420p" -b:v 2000k -bufsize 3000k -maxrate 2000k -g 60 -b:a 192k -ar 44100 -shortest -f tee "[select=\'v:0,a:0\':f=flv]rtmp://my_ip/normal|[select=\'v:0,a:1\':f=flv]rtmp://my_ip/altaudio|[select=\'a:0\':f=flv:onfail=ignore]rtmp://my_ip/onlyaudio"

ffmpeg multiple outputs is working only on the first rtmp

I have try stream with ffmpeg with output to differents rtmp servers like that
ffmpeg -re -i nameoffile.mp4 -vcodec libx264 -g 60 -c:a aac -b:a 160k -ar 44100 -strict -2 -f flv \
-f flv rtmp://rtmp.1.com/code \
-f flv rtmp://rtmp.2.com/code \
-f flv rtmp://rtmp.3.com/code \
-f flv rtmp://rtmp.4.com/code \
-f flv rtmp://rtmp.5.com/code \
The problem is... is working only the first one but not the others
You have to set the output options for each output: -vcodec libx264 -g 60 -c:a aac -b:a 160k -ar 44100

FFmpeg (merge two audio)

I have two long audio files. I want to merge cut some part from each video
and merge both parts in one file.
In below command the problem there is no audio in the second audio part. It contain the first part and the second is empty.
What is the problem?
ffmpeg -f lavfi -i color=c=black
-ss 157.824 -t 99.818
-i "file1.mp4"
-ss 315.764 -t 50.308
-i "file2.mp4"
-s 854x480
-aspect 1.779167
-r 25
-c:v libx264
-b:v 800k
-c:a aac
-strict experimental
-b:a 128k
-f mp4
-t 150.126 -async 1
-y "output.mp4"

ffmpeg: How to concat audio files and add background music in a single command?

Need to concat audio files and add background music in a single command.
Right now I use the following commands to do so,
To concat:
ffmpeg -i 1.mp4 -i 2.mp4 -i 3.mp4 -i 4.mp4 -i 5.mp4 -i 6.mp4 -i 7.mp4 -i 8.mp4 -i 9.mp4 -i 10.mp4 -filter_complex '[0:0][1:0]concat=n=10:v=0:a=1[out]' -map '[out]' -strict -2 -y 10_final.mp4
To add background music:
ffmpeg -i 10_final.mp4 -i music.mp4 -filter_complex "[0:a]volume=1dB[a0];[1:a]volume=0.5[a1];[a0][a1]amerge=inputs=2[a]" -map "[a]" -ac 1 -ab 32000 -ar 22050 -strict -2 -y 10_with_music.mp4
But his process is a quite time-consuming process as every time the file read/write happening to the output.
Is there a way I can merge these two above commands to a single so that the command should be optimized.
Use
ffmpeg -i 1.mp4 -i 2.mp4 -i 3.mp4 -i 4.mp4 -i 5.mp4
-i 6.mp4 -i 7.mp4 -i 8.mp4 -i 9.mp4 -i 10.mp4
-i music.mp4
-filter_complex '[0:0][1:0]...[9:0]concat=n=10:v=0:a=1,volume=1dB[a0];
[10]volume=0.5dB[a1];[a0][a1]amerge[a]'
-map '[a]' -strict -2 -y 10_with_music.mp4

Resources