FFMPEG -re Insurance - ffmpeg

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

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

ffmpeg "steam" cbr gop

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.

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...

FFMPEG image not updating

THE INPUT FILES
An overlay image that has is being updated every 5 seconds by a Python script
A small MP4 file that will be looped by a concat input
An MP3 file as audio source
THE COMMAND (UPDATED)
This is the command I'm currently using to combine and stream the inputs.
ffmpeg -re -i music.mp3 -f concat -i videoincludes.txt
-r 1 -loop 1 -f image2 -i overlay.png
-c:v libx264 -c:a aac -shortest -crf 23 -pix_fmt yuv420p
-maxrate 2500k -bufsize 2500k -preset ultrafast -r 30 -g 60 -b:v 2000k -b:a 192k -ar 44100
-filter_complex "[1:v][2:v] overlay=0:0" -map 0:a -strict -2
-f flv rtmp://a.rtmp.youtube.com/live2/{key}
Als tried using -framerate 1 instead of -r 1
THE ISSUE
So the issue is that the image doesn't always update. Sometimes it does update every couple seconds at the start but it stops updating after 10-20 seconds without any difference in log output and sometimes it just doesn't update.
I can however confirm that the image is being updated by the Python script but FFmpeg is just not picking this up.
I read setting the input format of the image to image2 should allow it to update so I am not sure what is wrong or what I can do to improve it.
I'm working on the same task, and finally, I think, I found the answer.
Because streams different from each other we must reset their timestamps with setpts=PTS-STARTPTS to have them begin in the same zero timestamp . And, also, try to use image2pipe instead of image2.
This is your code with timestamp reset:
ffmpeg -re -i music.mp3 -f concat -i videoincludes.txt
-r 1 -loop 1 -f image2pipe -i overlay.png
-c:v libx264 -c:a aac -shortest -crf 23 -pix_fmt yuv420p
-maxrate 2500k -bufsize 2500k -preset ultrafast -r 30 -g 60 -b:v 2000k -b:a 192k -ar 44100
-filter_complex "[1:v]setpts=PTS-STARTPTS[out_main]; [2:v]setpts=PTS-STARTPTS[out_overlay]; [out_main][out_overlay]overlay=0:0" -map 0:a -strict -2
-f flv rtmp://a.rtmp.youtube.com/live2/{key}
p.s and I think, there is no need in -r or -framerate anymore

live streamming using ffmpeg for more than stream on the same time

I'm using this command to stream video in ffmpeg but when I stream more than 3 or 4 streams at the same time interruption happen although the process in my device doesn't exceed 50%
I tried to use ffmpeg lib for each stream but interruption still happened
this is my command :
ffmpeg -re -i test.mp4 -i logo.png -vcodec libx264 -pix_fmt yuv420p -vb 2000000 -g 60
-vprofile main -acodec aac -ab 128000 -ar 48000 -ac 2 -vbsf h264_mp4toannexb
-strict experimental -filter_complex "[0][1]overlay=0:0"
-pass 1 -f mpegts udp://127.0.0.1:1234?pkt_size=1316

Resources