Video codec specs through ffmpeg (not being achieved) - windows

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

Related

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.

I am using ffmpeg to overlay a image on top of a live stream using filter graphs, but when the input resolution changes, the overlay vanishes

I did my research and found that some filter graph options do not adapt to changing resolutions.
https://lists.ffmpeg.org/pipermail/libav-user/2012-October/002920.html
Here is the command which i am using. Whenever my input video changes from portrait to landscape, the overlay vanishes. I would really appreciate any help here.
ffmpeg -i rtmp://127.0.0.1:1935/show/$2 -i $overlayUrl -filter_complex "[1][0]scale2ref=iw:ih[ovr][base];[base][ovr] overlay=0:0, split=4[a][b]" -async 1 -vsync -1 -map 0:a -map "[a]" -c:v libx264 -c:a aac -b:v 256k -b:a 32k -s 640x360 -tune zerolatency -r 60 -preset veryfast -crf 23 -f flv rtmp://$rtmpoutput/$2_low -map 0:a -map "[b]" -c:v libx264 -c:a aac -b:v 768k -b:a 96k -s 640x480 -tune zerolatency -r 60 -preset veryfast -crf 23 -f flv rtmp://$rtmpoutput/$2_mid code here
FFmpeg reinitializes the filtergraph when input properties change. The image input is one frame long and has already been consumed.
Loop the image.
ffmpeg -i rtmp://127.0.0.1:1935/show/$2 -loop 1 -i $overlayUrl ...

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

FFmpeg keep same video dimension if video height is less than x480

The following code im using for video converting:
ffmpeg -i input.mkv -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k -movflags +faststart -s hd480 output.mp4
I want to keep same video dimension for smaller videos. For example keep 640x360 dimension if video height is less than x480.
Is ffmpeg such option?
Use
ffmpeg -i input.mkv
-vf "scale=w='if(gt(ih,480),2*trunc(oh*a/2),iw)':h='if(gt(ih,480),480,ih)'"
-c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k -movflags +faststart output.mp4

Resources