FFMPEG tee muxer giving "Output file #0 does not contain any stream" - ffmpeg

I am trying to create two streams: one is mpegts UDP stream another - rtmp to Twitch servers.
This command works:
ffmpeg -threads:v 2 -threads:a 16 -filter_threads 2 -thread_queue_size 16 -y \
-f dshow -video_size 1920x1080 -pixel_format uyvy422 -framerate 25 -rtbufsize 500M -i video="Decklink Video Capture" \
-f dshow -rtbufsize 100M -i audio="Decklink Audio Capture" \
-preset ultrafast -c:v libx264 -tune zerolatency -b:v 900k -map 0:v:0 -f mpegts udp://127.0.0.1:5555 \
-pix_fmt yuv420p -c:v libx264 -crf 20 -tune zerolatency -f flv rtmp://live-fra05.twitch.tv/app/stream_key
But it requires double the encoding CPU power.
So, following this, I rewrote the command like this:
ffmpeg -threads:v 2 -threads:a 16 -filter_threads 2 -thread_queue_size 16 -y \
-f dshow -video_size 1920x1080 -pixel_format uyvy422 -framerate 25 -rtbufsize 500M -i video="Decklink Video Capture" \
-f dshow -rtbufsize 100M -i audio="Decklink Audio Capture" \
-preset ultrafast -c:v libx264 -tune zerolatency -b:v 900k \
-f tee "[select=\'0:v:0\':f=mpegts]udp://127.0.0.1:5555|[select=\'0:v:0,1:a:0\':f=flv]rtmp://live-fra05.twitch.tv/app/stream_key"
By writing -f tee "[select=\'0:v:0\':f=mpegts]udp://127.0.0.1:5555|[select=\'0:v:0,1:a:0\':f=flv]rtmp://live-fra05.twitch.tv/app/stream_key", I mean:
create UDP stream at udp://127.0.0.1:5555 and only include video stream from "Decklink Video Capture"
create RTMP stream where we include the same video stream as above and also the audio stream from "Decklink Audio Capture"
I get the error message:
Output file #0 does not contain any stream
How do I fix this? I assume I made a mistake in the command.

As the link shows, streams have to be mapped.
ffmpeg -thread_queue_size 16 -y \
-f dshow -video_size 1920x1080 -pixel_format uyvy422 -framerate 25 -rtbufsize 500M -i video="Decklink Video Capture" \
-f dshow -rtbufsize 100M -i audio="Decklink Audio Capture" \
-map 0:v -map 1:a \
-preset ultrafast -c:v libx264 -tune zerolatency -b:v 900k \
-f tee "[select=\'v:0\':f=mpegts]udp://127.0.0.1:5555|[select=\'v:0,a:0\':f=flv]rtmp://live-fra05.twitch.tv/app/stream_key"
See the full official docs for tee at http://ffmpeg.org/ffmpeg-formats.html#tee-1

Related

how to crop and overlay dshow?

hello I have a problem with ffmpeg I can't resize my web cam which is 1080p I would like some help pleaseffmpeg -y -rtbufsize 100M -thread_queue_size 9400 -f dshow -i video="USB Live Camera":audio="Microphone (2- Trust GXT 232 Microphone)" -thread_queue_size 9400 -f gdigrab -draw_mouse 0 -i desktop -b:v 10M -c:v libx264 -c:a aac -filter_complex "[1:v]pad=height=ih+10:color=black[b]; [b][0:v]overlay=(main_w-overlay_w):main_h-overlay_h[v] -video_size 200x200" -map "[v]" -map 0:a -c:a aac -r 20 -preset ultrafast -tune zerolatency -c:v libx264 -c:a aac -crf 30 -pix_fmt yuv420p -fflags nobuffer -f flv rtmp://localhost/hls/stream6
here is my command line
ffmpeg -y -rtbufsize 100M -thread_queue_size 9400 -video_size 320x240 -f dshow -i video="USB Live Camera":audio="Microphone (2- Trust GXT 232 Microphone)" -thread_queue_size 9400 -f gdigrab -draw_mouse 0 -i desktop -b:v 10M -c:v libx264 -c:a aac -filter_complex " [1:v]pad=height=ih+10:color=black[b]; [b][0:v]overlay=(main_w-overlay_w):main_h-overlay_h[v]" -map "[v]" -map 0:a -c:a aac -r 30 -preset ultrafast -tune zerolatency -c:v libx264 -c:a aac -crf 30 -pix_fmt yuv420p -fflags nobuffer -f flv rtmp://localhost/hls/stream6

How to save a DShow input on a file and simultaneously publish it on rtst stream?

Piping command does not work properly when your input is coming from a device (e.g. a webcam) so you cannot work with 2 output. I need to save the webcam stream on a file (.mkv) and, at the same time, publish it on a rtst server. I tried the following:
ffmpeg -y -f dshow -loglevel info -rtbufsize 2147.48M -i "video=my_camera" -vf hflip,rotate=PI ^
-c:v libx264 -preset fast -crf 25 -pix_fmt yuv420p ^
-minrate 2M -maxrate 4M -bufsize 3.5M -s 1920x1080 -f tee "[f=mkv]'C:\test.mkv'|[f=rtsp]rtsp://localhost:8554/mystream]"
Finally I did it. Use -flags +global_header, it is mandatory as the same -map 0:v option. Now is working perfectly.
ffmpeg -y -f dshow -loglevel info -rtbufsize 2147.48M -i "video=MY_CAMERA" ^
-flags +global_header -c:v libx264 -preset fast -crf 30 -pix_fmt yuv420p ^
-minrate 2M -maxrate 4M -bufsize 3.5M -s 1920x1080 -f tee -map 0:v "C:\out\test.mkv|[f=rtsp]rtsp://localhost:8554/mystream"

How to properly format FFmpeg's -vf options for both text and snapshots?

I've got this working:
ffmpeg -input_format yuyv422 -f v4l2 -s 800x448 -r 30 -i /dev/video0 -vf "[in]drawtext=fontfile=/usr/share/fonts/truetype/freefont/Roboto-Regular.ttf:text='%{localtime\:%d %b %Y}':x=8:y=8:fontcolor=white:box=1:boxcolor=black#0.75,drawtext=fontfile=/usr/share/fonts/truetype/freefont/Roboto-Regular.ttf:text='%{localtime\:%T}':x=8:y=24:fontcolor=white:box=1:boxcolor=black#0.75" -c:v h264_omx -r 30 -b:v 2M -an -f rtsp rtsp://localhost:8554/mystream
It outputs a steady video-stream, with a double-lined text overlay, from my USB-connected webcam to rtsp-simple-server on my RPi 3A+.
I've also got this working:
ffmpeg -input_format yuyv422 -f v4l2 -s 800x448 -r 30 -i /dev/video0 -c:v h264_omx -r 30 -b:v 2M -vf fps=1/20 -update 1 /dev/shm/snapshot.jpg -an -f rtsp rtsp://localhost:8554/mystream
But I can't figure out how to make FFmpeg do both at the same time - a video stream with double-lined text overlay, while saving a snapshot now and then to /dev/shm.
What would the correct syntax for this look like?
Combined command:
ffmpeg -f v4l2 -input_format yuyv422 -video_size 800x448 -framerate 30 -i /dev/video0 -filter_complex "[0]vflip,drawtext=fontfile=/usr/share/fonts/truetype/freefont/Roboto-Regular.ttf:text='%{localtime\:%d %b %Y}':x=8:y=8:fontcolor=white:box=1:boxcolor=black#0.75,drawtext=fontfile=/usr/share/fonts/truetype/freefont/Roboto-Regular.ttf:text='%{localtime\:%T}':x=8:y=24:fontcolor=white:box=1:boxcolor=black#0.75[vid];[0]fps=1/20,vflip[img]" -map "[vid]" -c:v h264_omx -b:v 2M -f rtsp rtsp://localhost:8554/mystream -map "[img]" -update 1 /dev/shm/snapshot.jpg

How to livestream a webcam to YouTube with FFmpeg?

I want to send the livestream of my webcam to YouTube. I can follow YouTube's guide up to step 8. "Stream Connection" tells me there is "No data" and the button "Go Live" remains unclickable. A screenshot of this situation can be seen at
As encoding software, I was planning on using FFmpeg because it can run from the target platform, a Raspberry Pi with Raspbian. A USB webcam supported by video4linux2 is used.
FFmpeg's wiki shows that streaming a file can be done with the following:
ffmpeg -re -i input.mkv \
-c:v libx264 -preset veryfast -maxrate 3000k \
-bufsize 6000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 160k -ac 2 \
-ar 44100 -f flv rtmp://live.twitch.tv/app/<stream key>
I modified this command in the following ways:
1. It takes the video stream from the webcam with -f v4l2 -i /dev/video0.
2. It does not broadcast any audio with -an.
3. It broadcasts to YouTube's RTMP server, rtmp://a.rtmp.youtube.com/live2/<stream key>
The final version of the command is now:
RTMP_URL="rtmp://a.rtmp.youtube.com/live2"
STREAM_KEY="secr-etse-cret-secr"
OUTPUT=$RTMP_URL/$STREAM_KEY
ffmpeg -re -f v4l2 -i /dev/video0 \
-c:v libx264 -preset veryfast -maxrate 3000k \
-bufsize 6000k -pix_fmt yuv420p -g 50 -an \
-f flv $OUTPUT
When I run this command, I would expect that "Stream connection" would change to something else than "No data" after a few seconds, but that does not happen.
I have tried recording the stream to a local file with:
ffmpeg -re -f v4l2 -i /dev/video0 \
-c:v libx264 -preset veryfast -maxrate 3000k \
-bufsize 6000k -pix_fmt yuv420p -g 50 -an \
-f flv test.flv
This worked fine. That demonstrates to me that the issue is with getting the video stream accepted by YouTube.
The code below works very well using Windows, you may adjust to fit for your need
ffmpeg -loglevel debug -threads:v 2 -threads:a 8 -filter_threads 2 -thread_queue_size 512 -f dshow -i video="HP Wide Vision HD" -f dshow -i audio="Microphone Array (Realtek Audio)" -pix_fmt yuv420p -c:v libx264 -qp:v 19 -profile:v high -rc:v cbr_ld_hq -level:v 4.2 -r:v 60 -g:v 120 -bf:v 3 -refs:v 16 -f flv rtmp://youtube_stream_url/stream_key

ffmpeg - How to filter video when record Window Application in the same time

I have a problem when record Window Application and filter (overlay, audio mixing...) with others filter video.
This code work perfectly :
ffmpeg -rtbufsize 1500M -f dshow -i audio="virtual-audio-capturer" -f gdigrab -framerate 30 -draw_mouse 0 -i title="Main" -vf crop=850:480:156:100 -pix_fmt yuv420p -profile:v baseline -y ok.mp4 (With Main is my Application)
But this code bellow doesn't:
ffmpeg -rtbufsize 1500M -f dshow -y -i audio="virtual-audio-capturer" -f gdigrab -framerate 30 -draw_mouse 0 -i title="Main" -vf crop=850:480:156:100 -pix_fmt yuv420p -profile:v baseline -stream_loop 999 -i "filter/filter.mp4" -filter_complex "[2:v]scale=385:216, setdar=dar=16/9[v1]; [2:v]scale=385:216, setdar=dar=16/9[v2]; [v1][v2]blend=shortest=1:all_opacity=1[v3]; movie=filter/nds_bg.mp4:loop=999,setpts=N/(FRAME_RATE*TB), scale=640:360[v4] ;[v4][v3]overlay=shortest=1:x=20:y=130;[2:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,asetrate=8.5/10*44100,atempo=10/8.5,lowpass=f=2500,highpass=f=400,volume
=3,bass=g=-30,equalizer=f=10.5:width_type=o:width=1:g=-30, equalizer=f=31.5:width_type=o:width=1:g=-
30,equalizer=f=63:width_type=o:width=1:g=-10, equalizer=f=125:width_type=o:width=1:g=-20,equalizer=f=250:width_type=o:width=1:g=-1.5,equalizer=f=500:width_type=o:width=1:g=-20,equalizer=f=1000:width_type=o:width=1:g=-20,equalizer=f=8000:width_type=o:width=3:g=1,equalizer=f=16000:width_type=o:width=3:g=1" -vcodec libx264 -pix_fmt yuv420p -r 26 -g 30 -b:30
800k -shortest -acodec libmp3lame -b:a 128k -preset:v ultrafast -ar 44100 -f flv -bufsize 3000k -s 640x360 out.mp4
I think this code need to output to video first
ffmpeg -rtbufsize 1500M -f dshow -y -i audio="virtual-audio-capturer" -f gdigrab -framerate 30 -draw_mouse 0 -i title="Main" -vf crop=850:480:156:100 -pix_fmt yuv420p -profile:v baseline
Please show me how to merge these code or any solution. Thank you so much!

Resources