ffmpeg resulting in no audio and unplayble video - ffmpeg

I am trying to get ffmpeg to work as expected however I am having all kinds of trouble getting it to work.
I need to output a webm and h264 for web play. However, the command I am using, while it used to work a few years ago, does not work at all now.
Both my webm and h264 do not have audio, and neither will play in any browser.
My command for webm is:
ffmpeg -y -i "$KMVAR_File" -c:v libvpx -crf 24 -b:v 1000k -vf scale=720:-2 -c:a libvorbis "$KMVAR_webmPath"
and my command for mp4 is:
ffmpeg -y -i "$KMVAR_File" -c:v libx264 -pix_fmt yuv420p -profile:v baseline -level 3.0 -crf 32 -b:v 1M -minrate 1M -maxrate 1M -bufsize 2M -vf scale=720:-2 -c:a aac -strict experimental -movflags +faststart "$KMVAR_mp4Path"

When playing with multiple audio, downmixing or extracting, there's no "one size fit all" solution with ffmpeg.
Look at https://trac.ffmpeg.org/wiki/AudioChannelManipulation as it provides multiple possible solution to your problem.
(I usually go with the pan filter : not the easiest to use, but more powerful than the map_channel approach)

Related

Tweaking FFMPEG Stream For Games For Open Source Projech

Right now I am using FFMPEG to record and broadcast video games on a open source projected call Glitch: https://www.glitch.fun/
The problem is the streams are a little but choppy and pixelated. Here is an example video recording:
https://www.glitch.fun/streams/7e5b7557-d028-4d39-bc59-af3836f7e30d/watchrecording/c147ffda-d26d-4c5f-8be1-a8832ba03dfa
The FFMPEG command I am currently for getting the stream from a source and sending it to a recording file and to destinations is as follows:
ffmpeg [some_input_source] -vf scale=1920x1080 -pix_fmt yuv420p -r 60 -b:v 4000k -maxrate 4000k -bufsize 4500k -vcodec libx264 -preset veryfast -keyint_min 24 -level 3.0 -s 1920:h=1080 -g 40 -x264opts no-scenecut -strict experimental -f [output_location]
What can I tweak in here to improve the quality of streaming for games?

FFmpeg - Streaming from a rtsp server to a rtmp server - loosing packages

I'm trying to stream a video from a rtsp server to a rtmp one using FFmpeg.
Tried multiple arguments for my command :
ffmpeg.exe -re -i "rtsp://10.65.28.251:11442/video/live" -pix_fmt yuv420p -codec:v libx264 -tune animation -preset fast -crf 23 -maxrate 4M -bufsize 8M -f flv "rtmp://10.65.58.21:1935/rec/XB"
ffmpeg.exe -re -i "rtsp://10.65.28.251:11442/video/live" -preset ultrafast -vcodec libx264 -tune zerolatency -b 900k -f flv "rtmp://10.65.52.131:1935/rec/XB
I'm loosing a lot of packages as seen in the picture. I'm pretty new to FFmpeg so I'm pretty sure I'm messing up the parameters somehow.
My goal is to get a video on rtmp with min 30fps and as least lost packages as possible. If needed a downsize of the video quality would be fine.
Any idea what I'm doing wrong?
Thanks!
As kesh pointed above removing -re made a big difference. I ended up with this command which holds pretty good quality at 30fps.
ffmpeg.exe -i "rtsp://serversource:11442" -filter:v fps=fps=30 -crf 40 -preset ultrafast -vcodec libx264 -f flv "rtmp://servertarget:1935"

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, capturing video is laggy, how to eliminate that?

Lets say I dont have a very good computer and my recordings are laggy. Two version I tried:
ffmpeg -f dshow -framerate 30 -i video="screen-capture-recorder":audio="virtual-audio-capturer" -vcodec libx264 -crf 0 -preset ultrafast -acodec pcm_s16le output.mkv
ffmpeg -f gdigrab -framerate 30 -i desktop -vcodec libx264 -crf 0 -preset ultrafast -acodec pcm_s16le output.mkv
I tried to avoid all compressing stuff, still lagging. Although Im recording 1920x1080 video... I dont care how big the result is. Isnt there an option like "store all frames, and encoding a bit later, I dont care the realtime capturing" ?

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