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"
Related
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
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
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/
I have this ffmpeg script I'm running to automatically convert videos to instagram's accepted coded
The script looks like this:
ffmpeg -analyzeduration 20M -probesize 20M -y -re -f lavfi -i "movie=filename='file.mp4':loop=5, setpts=N/(FRAME_RATE*TB)" -vcodec libx264 -b:v 3500k -vsync 2 -t 59 -acodec aac -b:a 128k -pix_fmt yuv420p -vf "scale=1080:1080:force_original_aspect_ratio=decrease,pad=1080:1080:(ow-iw)/2:(oh-ih)/2:white" -crf 24 new_file.mp4
However that seems to cut out the audio, and I can't seem to find out how to prevent that? I didn't use any -an or anything, and when messing around the audio keeps being cut out? Any idea why?
The movie filter, by default, only reads one video stream from the input.
For looping, stream_loop is available without having to use filters.
ffmpeg -analyseduration 20M -probesize 20M -y -re -stream_loop 5 -i "file.mp4" -vcodec libx264 -b:v 3500k -vsync cfr -t 59 -acodec aac -b:a 128k -pix_fmt yuv420p -vf "scale=1080:1080:force_original_aspect_ratio=decrease,pad=1080:1080:(ow-iw)/2:(oh-ih)/2:white" -crf 24 new_file.mp4
I'm having a slight issue trying to sync my audio and video up with an acceptable margin of error. Here is my command:
ffmpeg -y -thread_queue_size 9999 -indexmem 9999 -guess_layout_max 0 -f dshow -video_size 3440x1440 -rtbufsize 2147.48M ^
-framerate 100 -pixel_format nv12 -i video="Video (00 Pro Capture HDMI 4K+)":audio="SPDIF/ADAT (1+2) (RME Fireface UC)" ^
-map 0:0,0:1 -map 0:1 -flags +cgop -force_key_frames expr:gte(t,n_forced*2) -c:v h264_nvenc -preset: llhp -pix_fmt nv12 ^
-b:v 250M -minrate 250M -maxrate 250M -bufsize 250M -c:a aac -ar 44100 -b:a 384k -ac 2 -r 100 -af "aresample=async=250" ^
-vsync 1 -max_muxing_queue_size 9999 -f segment -segment_time 600 -segment_wrap 9 -reset_timestamps 1 ^
C:\Users\djcim\Videos\PC\PC\PC%02d.ts
My problem is the video comes in slightly ahead of the audio, I can use -itsoffset but then I have to call the video and audio as separate inputs as -itsoffset offsets both audio and video. While this may seem the obvious solution it causes inconsistent audio synchronization if the audio isn't called with the video. Basically if both audio and video aren't called at the same time the video can now be ahead or behind with a 2-3 frame margin. When I call them at the same time the video consistently comes in 2 frames ahead of the audio, every time. I just need a way to delay only the video stream without delaying the audio while keeping both audio and video linked from the beginning. I've tried this with no luck:
ffmpeg -y -thread_queue_size 9999 -indexmem 9999 -guess_layout_max 0 -f dshow -video_size 3440x1440 -rtbufsize 2147.48M ^
-framerate 200 -pixel_format nv12 -i video="Video (00 Pro Capture HDMI 4K+)":audio="SPDIF/ADAT (1+2) (RME Fireface UC)" ^
-flags +cgop -force_key_frames expr:gte(t,n_forced*2) -c:v h264_nvenc -preset: llhp -pix_fmt nv12 -b:v 250M ^
-minrate 250M -maxrate 250M -bufsize 250M -c:a aac -ar 44100 -b:a 384k -ac 2 -r 100 ^
-filter_complex "[0:v] setpts=PTS-STARTPTS+.032/TB [v]; [0:a] asetpts=PTS-STARTPTS, aresample=async=250 [a]" -map [v] ^
-map [a] -vsync 1 -max_muxing_queue_size 9999 -f segment -segment_time 600 -segment_wrap 9 -reset_timestamps 1 ^
C:\Users\djcim\Videos\PC\PC\PC%02d.ts
Just like -itsoffset both video and audio are being delayed. You can delay solely audio with adelay, but there doesn't seem to be a video delaying equivalent.
Any help or advice would be greatly appreciated.
As stated by Gyan in the comments, atrim worked. While it isn't delaying the video it is still lining everything up by ditching part of the audio stream.
ffmpeg - y -thread_queue_size 9999 -indexmem 9999 -guess_layout_max 0 -f dshow -video_size 3440x1440 -rtbufsize 2147.48M ^
-framerate 200 -pixel_format nv12 -i video="Video (00 Pro Capture HDMI 4K+)":audio="SPDIF/ADAT (1+2) (RME Fireface UC)" ^
-map 0:0,0:1 -map 0:1 -flags +cgop -force_key_frames expr:gte(t,n_forced*2) -c:v h264_nvenc -preset: llhp -pix_fmt nv12 ^
-b:v 250M -minrate 250M -maxrate 250M -bufsize 250M -c:a aac -ar 44100 -b:a 384k -ac 2 -r 100 ^
-af "atrim=0.038, asetpts=PTS-STARTPTS, aresample=async=250" -vsync 1 -ss 00:00:01.096 -max_muxing_queue_size 9999 ^
-f segment -segment_time 600 -segment_wrap 9 -reset_timestamps 1 C:\Users\djcim\Videos\PC\PC\PC%02d.ts