ffmpeg "steam" cbr gop - ffmpeg

It's about live video streaming to STEAM... with ffmpeg
I have this command
ffmpeg -re -i file-from-webcam.webm -deinterlace
-c:v libx264 -pix_fmt yuv420p -preset veryfast
-tune zerolatency -c:a aac -b:a 128k -ac 2 -strict -2 -crf 18
-r 30 -g 60 -vb 1369k -minrate 1369k -maxrate 1369 -ar 44100 -x264-params "nal-hrd=cbr"
-vf "scale=1280:720" -profile:v main
-f flv "rtmp://ingest-rtmp.broadcast.steamcontent.com/app/steam_...."
but after a few seconds, the stream stops and the log of steam says
Make sure your upload key-frame interval is set to 2 seconds
and use constant bitrate (CBR).
Limit your encoders group of picture (GOP) to at most two times your framerate.
but I do have -x264-params "nal-hrd=cbr" and -r 30 -g 60 framerate 30 GOP 60...
Is there something wrong in the ffmpeg command ?
Or is it linux server related ?
**** The SAME ffmpeg command work very nicely in youtube, twitter, twitch, dlive, facebook, etc...
so what I'm I missing to get it work for steam ?

ffmpeg -re -i file.webm -deinterlace -c:v libx264 -preset veryfast -tune zerolatency -c:a aac -b:a 128k -ac 2 -r 30 -g 60 -vb 1369k -minrate 1369k -maxrate 1369k -bufsize 2730k -ar 44100 -x264-params "nal-hrd=cbr" -vf "scale=1280:720,format=yuv420p" -profile:v main -f flv "rtmp://ingest-rtmp.broadcast.steamcontent.com/app/___key___"
-crf and -b:v/-vb are mutually exclusive. It's likely your -vb was being ignored. Since you want a specific bitrate remove -crf.
-maxrate 1369 was missing the k.
Add -bufsize. See FFmpeg Wiki: Encoding for Streaming Sites.
No need for -strict -2. Users always add that without knowing why. (It was for the old AAC encoder before 2015.)
Make sure your input has audio. Some sites like YouTube require audio. If it does not have audio use the anullsrc filter to generate silent audio.

Related

Why ffmpeg ignores output fps?

I have the following ffmpeg command that streams an input to an RTMP endpoint :
ffmpeg
-re
-i -
-r 30
-vf scale=852:480
-c:v libx264
-pix_fmt yuv420p
-profile:v main
-preset veryfast
-x264opts "nal-hrd=cbr:no-scenecut"
-minrate 3000
-maxrate 3000
-g 60
-c:a aac
-b:a 160k
-ac 2
-ar 44100
-f flv
Some RTMPURL/ Some RTMPKey
This command works but the output frame rate is not respected. It drops to 6 fps.
I need it to be always 30 fps.
Does anyone know why it's not respected please ?
Thanks

I want to mix multiple crop is my command But ffmpeg error

I want to mix multiple crop is my command But ffmpeg error Filter overlay has an unconnected output.
ffmpeg -y -i "tetcrop.mp4" -i fulla.png -filter_complex "[0:v]setpts=PTS/1,scale=854:480,select='lt(mod(t,20),20)',setpts=N/FRAME_RATE/TB,setdar=16/9[vm];[vm]crop=155:176:229:150,scale=854:480,setdar=16/9[v2];[0:v]scale=854:480,setdar=16/9,setpts=PTS/1,select='lt(mod(t,20),20)',setpts=N/FRAME_RATE/TB[vc];[vc][v2]overlay=shortest=1:enable='lt(mod(t,4),2)*gte(t,2)'[v3];[0:v]setpts=PTS/1,scale=854:480,select='lt(mod(t,20),20)',setpts=N/FRAME_RATE/TB,setdar=16/9[ve];[ve]crop=155:176:229:150,scale=854:480,setdar=16/9[v4];[0:v]scale=854:480,setdar=16/9,setpts=PTS/1,select='lt(mod(t,20),20)',setpts=N/FRAME_RATE/TB[vd];[vd][v4]overlay=shortest=1:enable='lt(mod(t,4),2)*gte(t,2)'[vout];[vout]overlay =main_w-overlay_w-5:5;[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,atempo=1,aecho=0.5:0.3:2:0.5,aecho=0.5:0.3:2:0.5,aecho=0.5:0.3:2:0.5,highpass=f=10,treble=g=0,volume=10,volume=+25dB,aselect='lt(mod(t,20),20)',asetpts=N/SR/TB[a1];amovie=uottro.mp4:loop=999,volume=0.03[a2];[a1][a2]amix=duration=shortest" -vcodec libx264 -pix_fmt yuv420p -b:v 1000k -bf 2 -r 25 -g 60 -acodec libmp3lame -b:a 128k -ar 44100 -ac 2 -preset veryfast "tetcropok.mp4"
You made [vc][v2]overlay=shortest=1:enable='lt(mod(t,4),2)*gte(t,2)'[v3] but never told ffmpeg what to do with [v3]. It is orphaned, but it must be consumed.

FFMPEG -re Insurance

FFMPEG -re according to the ffmpeg docs:
Read input at native frame rate. Mainly used to simulate a grab
device, or live input stream (e.g. when reading from a file). Should
not be used with actual grab devices or live input streams (where it
can cause packet loss).
My ffmpeg stream command is:
ffmpeg -re -i https://www.example.com/video.mp4 -filter_complex tpad=start_duration=10:stop_duration=15:start_mode=add:color=black:stop_mode=add -af adelay=10000|10000 -maxrate 2M -crf 24 -bufsize 6000k -c:v libx264 -preset superfast -tune zerolatency -strict -2 -c:a aac -ar 44100 -attempt_recovery 1 -max_recovery_attempts 5 -drop_pkts_on_overflow 1 -f flv rtmp://live.example.com/123453
Except this does not always work, and sometimes I have livestreams ending early because ffmpeg is playing faster than the frame rate. Is there another command that can be used to ensure ffmpeg streams the video in real time?
Remove -re and add filter-based throttling.
ffmpeg -i https://www.example.com/video.mp4 -filter_complex tpad=start_duration=10:stop_duration=15:start_mode=add:color=black:stop_mode=add,fifo,realtime -af adelay=10000|10000,afifo,arealtime -maxrate 2M -crf 24 -bufsize 6000k -c:v libx264 -preset superfast -tune zerolatency -strict -2 -c:a aac -ar 44100 -attempt_recovery 1 -max_recovery_attempts 5 -drop_pkts_on_overflow 1 -f flv rtmp://live.example.com/123453

Ffmpeg converts video of double size of original video with second part without audio

I am converting some videos with below command in ffmpeg
ffmpeg -y -i source.mp4 -c:a libfdk_aac -ac 2 -ab 128k -c:v libx264 -x264opts keyint=24:min-keyint=24:no-scenecut -crf 18 -b:v 4000k -maxrate 4000k -bufsize 4000k -vf "scale=-1:1080" destination_1080.mp4
But in some cases the output video is exactly double size of the original and the second part is without audio. Please help.
First thing, there's a flaw in your command. You can't use: -crf 18 -b:v 4000k together, use one or the other.
I don't know what version of FFMPEG you are using, but with the inclusion of: libfdk_aac it's either an old version or one you have self compiled. If I remember correctly that audio codec was taken out of the common builds once the standard aac encoder matured. (I may be wrong about that)
First thing I'd try is to narrow things down a little. From your command line I'm guessing you have a Windows PC, download the latest FFMPEG from HERE
Here are some examples to try: (change audio codec if needed)
BITRATE
ffmpeg -y -i source.mp4 -c:v libx264 -x264opts keyint=24:min-keyint=24:no-scenecut -b:v 4000k -maxrate 4000k -bufsize 4000k -vf "scale=-1:1080" -c:a aac -ac 2 -ab 128k destination_1080_bit.mp4
CRF
ffmpeg -y -i source.mp4 -c:v libx264 -x264opts keyint=24:min-keyint=24:no-scenecut -crf 18 -maxrate 4000k -bufsize 4000k -vf "scale=-1:1080" -c:a aac -ac 2 -ab 128k destination_1080_crf18.mp4
It's interesting you mention the video is twice the size and the audio finishing in the second part.
Your output size will be greater if the bitrate used is higher than the original. Higher the crf value, or lower the bitrate, and have a few tests.
There may also be some FPS issue where the video and audio are mismatched, maybe one thinks the other is at double frame rate. (that's a complete guess)
I would give the above a try first and see how you get on before digging deeper.
Let us know how you get on.
I'll post a new answer, rather than edit other answer, as my first answer is already rather long.
First, I would try to get to the bottom of the problem by starting simple and working my way up on the problematic file/s.
Just copy source to destination:
ffmpeg -i source.mp4 -c copy destination_1.mp4
Is the ouptut as expected? Any errors? What did FFMPEG display?
Copy video - encode audio:
ffmpeg -i source.mp4 -c:v copy -c:a libfdk_aac -ac 2 -ab 128k destination_2.mp4
Is the ouptut as expected? Any errors? What did FFMPEG display?
Encode video (simple) - encode audio:
ffmpeg -i source.mp4 -c:v libx264 -b:v 4000k -maxrate 4000k -bufsize 4000k -c:a libfdk_aac -ac 2 -ab 128k destination_3.mp4
Is the ouptut as expected? Any errors? What did FFMPEG display?
Encode video (+opts) - encode audio:
ffmpeg -i source.mp4 -c:v libx264 -x264opts keyint=24:min-keyint=24:no-scenecut -b:v 4000k -maxrate 4000k -bufsize 4000k -c:a libfdk_aac -ac 2 -ab 128k destination_4.mp4
Is the ouptut as expected? Any errors? What did FFMPEG display?
Encode video (+filter) - encode audio:
ffmpeg -i source.mp4 -c:v libx264 -x264opts keyint=24:min-keyint=24:no-scenecut -b:v 4000k -maxrate 4000k -bufsize 4000k -filter:v "scale=1920:-2" -c:a libfdk_aac -ac 2 -ab 128k destination_5.mp4
Is the ouptut as expected? Any errors? What did FFMPEG display?
If you still get problems it's going to be difficult to fix or make further suggestions without us seeing the output from FFMPEG.
Remember, don't use -crf 18 -b:v 4000k in the same command, one or the other, cfr OR bitrate, not both.
Best of luck...

Video codec specs through ffmpeg (not being achieved)

The specs for the video format are the following:
Aspect Ratio: 1:1
H.264 video compression, high profile, square pixels, fixed frame rate, progressive scan
.mp4 container with leading mov atom, no edit lists
Audio: Stereo AAC audio compression, 128kbps +
Reading through posts and ffmpeg documentation I came up with the following (yeah, I run it on a Windows PC):
ffmpeg.exe -r 30 -i input.webm -vf scale=iw*sar:ih -c:v libx264 -preset slow -profile:v high -c:a aac -strict experimental -ar 44100 -aspect 1:1 output.mp4
But when the video is played within the app that asks for this specification, it only displays black moving pixels, all broken, but you an hear the audio.
I don't really know what else to change on the command, and I have no idea in regards to the ...with leading mov atom specification.
Thanks.
EDIT:
I've tried #Mulvya's answer:
ffmpeg.exe -i input.webm -vf scale=iw*sar:ih,setsar=1 -c:v libx264 -preset slow -profile:v high -pix_fmt yuv420p -r 30 -c:a aac -strict experimental -ar 44100 -ac 2 -b:a 128k -movflags +faststart output.mp4
But the effect is the same once given to the app:
This is the information that ffmpeg spews about the input.webm file:
Use
ffmpeg.exe -i input.webm -vf scale=iw*sar:ih,setsar=1 -c:v libx264 -preset slow -profile:v high -pix_fmt yuv420p -r 30 -c:a aac -strict experimental -ar 44100 -ac 2 -b:a 128k -movflags +faststart output.mp4
Depending on how strict the app is, you may need to check the precise framerate. Use -r 30000/1001 for 29.97. The -movflags +faststart moves the moov atom to the front of the file.
Based on info I found elsewhere, this seems to be what Instagram requires:
ffmpeg.exe -i input.webm -vf scale=640:640,setsar=1 -c:v libx264 -preset slow -profile:v main -level 3.1 -pix_fmt yuv420p -r 30000/1001 -c:a aac -strict experimental -ar 44100 -ac 1 -b:a 64k -t 15 -movflags +faststart output.mp4

Resources