how to crop and overlay dshow? - ffmpeg

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

Related

FFmpeg filter complex audio

How do I add the aac to the filter_complex/split so the audio only is encoded once as the yadif?
ffmpeg -y -hwaccel cuvid -i test.mxf -filter_complex "[0:v]yadif=1,split=2[out1][out2]" -map "[out1]" -s 1920:1080 -c:v h264_nvenc -force_key_frames "expr:gte(t,n_forced*10)" -pix_fmt yuv420p -preset slow -rc vbr_hq -b:v 4.5M -map 0:1 -c:a aac -b:a 192k test2.mp4 -map "[out2]" -s 768:432 -c:v h264_nvenc -force_key_frames "expr:gte(t,n_forced*10)" -pix_fmt yuv420p -preset slow -rc vbr_hq -b:v 1.5M -map 0:1 -c:a aac -b:a 192k test3.mp4
Your video is being encoded twice which is unavoidable because you are outputting two different width x height. Your audio is the same for each output, so you can use the tee muxer to only encode audio once and put it in both outputs:
ffmpeg -hwaccel cuvid -i test.mxf -filter_complex "[0:v]yadif=1,format=yuv420p,split=2[vid1][vid2];[vid1]scale=-2:1080[1080];[vid2]scale=-2:432[432]" -map "[1080]" -map "[432]" -map 0:a:0 -c:v h264_nvenc -force_key_frames "expr:gte(t,n_forced*10)" -preset slow -rc vbr_hq -b:v:0 4.5M -b:v:1 1.5M -c:a aac -b:a 192k -f tee "[select=\'v:0,a\']1080.mp4|[select=\'v:1,a\']432.mp4"

I trying to stream screen to multiple sources with ffmpeg and got error

My command
ffmpeg -thread_queue_size 1024 -f x11grab -draw_mouse 0 -video_size 1920x1080 -i :99.0+0,0 -f alsa -i pulse -channels 2 -c:a aac -b:a 160k -ar 44100 -threads 8 -c:v libx264 -x264-params nal-hrd=cbr -profile:v baseline -framerate 30 -level:v 4.2 -vf format=yuv420p -b:v 1000k -maxrate 1500k -minrate 1000k -bufsize 8000k -g 60 -preset ultrafast -tune zerolatency -f tee -flags +global_header -map 0:v -map 1:a "[f=flv:onfail=ignore]rtmp://stream1|[f=flv:onfail=ignore]rtmp://stream2"
Error in console:
[NULL # 0x55aaf9a54bc0] Unable to find a suitable output format for '"[f=flv:onfail=ignore]rtmp://strea1
[tee # 0x55aaf96f3200] Slave muxer #0 failed, aborting.
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:1 --
ffmpeg -thread_queue_size 1024 -f x11grab -draw_mouse 0 -video_size 1920x1080 -i :99.0+0,0 -f alsa -i pulse -channels 2 -c:a aac -b:a 160k -ar 44100 -threads 8 -c:v libx264 -x264-params nal-hrd=cbr -profile:v baseline -framerate 30 -level:v 4.2 -vf format=yuv420p -b:v 1000k -maxrate 2500k -minrate 800k -bufsize 8000k -g 60 -preset ultrafast -tune zerolatency -map 0:v -map 1:a -f tee -flags +global_header [f=flv:onfail=ignore:flvflags=no_duration_filesize]rtmp://stream1|[f=flv:onfail=ignore:flvflags=no_duration_filesize]rtmp://stream2
problem was with quotes

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"

Burning subtitles different resolutions

I'm trying to create a live stream with three quality profiles with different resolutions (SD, HD and FullHD). The live stream has subtitles, and I have to burn them for compatibility reasons.
I know how to do it with one profile, but with many no idea.
ffmpeg -nostdin -loglevel error -hwaccel cuvid -deint 2 -drop_second_field 1 -surfaces 15 -c:v h264_cuvid -resize 1280x720 -y -i udp://xxx.xxx.xxx.xxx:xxxxx?pkt_size=1316\&buffer_size=409600\&fifo_size=1000000\&overrun_nonfatal=1 -filter_complex [i:0x2c6]hwdownload,format=nv12[base];[i:0x993]setpts=(2.5)/TB+PTS[subs];[subs]scale=1280:720[subtitle];[base][subtitle]overlay[v];[v]hwupload_cuda[v] -map [v] -c:v hevc_nvenc -preset llhq -rc vbr_hq -cq 23 -qp 23 -tier high -profile:v main10 -level 4.0 -b:v 2000k -maxrate 2400k -bufsize 1000k -map i:0x2bd -c:a libfdk_aac -ac 2 -b:a 64k -map i:0x2be -c:a libfdk_aac -ac 2 -b:a 64k -metadata:s:a:0 language=eng -metadata:s:a:1 language=spa -f mpegts -mpegts_flags resend_headers+pat_pmt_at_frames -mpegts_copyts 1 -pcr_period 40 udp://yyy.yyy.yyy.yyy:yyyy?ttl=31\?pkt_size=1316\&buffer_size=409600\&fifo_size=1000000\&overrun_nonfatal=1
Apparenlty, Iffmpeg doen't allow to use -vf filter with filter_complex.
I'm using ffmpeg 3.4, cuda 8.
Use
ffmpeg -nostdin -loglevel error -hwaccel cuvid -deint 2 -drop_second_field 1 -surfaces 15
-c:v h264_cuvid -y -i udp://xxx.xxx.xxx.xxx:xxxxx?pkt_size=1316\&buffer_size=409600\&fifo_size=1000000\&overrun_nonfatal=1
-filter_complex "[i:0x2c6]hwdownload,format=nv12,split=3[fhd][hd][sd];
[i:0x993]setpts=(2.5)/TB+PTS,split=3[subfhd][subhd][subsd];
[fhd]scale=1920:1080[fhd];
[hd]scale=1280:720[hd];
[sd]scale=960:540[sd];
[subfhd]scale=1920:1080[subfhd];
[subhd]scale=1280:720[subhd];
[subsd]scale=960:540[subsd];
[fhd][subfhd]overlay,hwupload_cuda[v-fhd];
[hd][subhd]overlay,hwupload_cuda[v-hd];
[sd][subsd]overlay,hwupload_cuda[v-sd]"
-map [v-fhd] -map [v-hd] -map [v-sd] -c:v hevc_nvenc -preset llhq -rc vbr_hq -cq 23 -qp 23 -tier high
-profile:v main10 -level 4.0 -b:v 2000k -maxrate 2400k -bufsize 1000k
-map i:0x2bd -map i:0x2be -c:a libfdk_aac -ac 2 -b:a 64k
-metadata:s:a:0 language=eng -metadata:s:a:1 language=spa
-f mpegts -mpegts_flags resend_headers+pat_pmt_at_frames -mpegts_copyts 1
-pcr_period 40 udp://yyy.yyy.yyy.yyy:yyyy?ttl=31\?pkt_size=1316\&buffer_size=409600\&fifo_size=1000000\&overrun_nonfatal=1
You'll have to adjust the video bitrates and buffer sizes as required, but this is the basic command template.

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