ffmpeg, conversion to flv: how to get better quality? - ffmpeg

I am using ffmpeg to convert any avi/wmv videos to flv.
My trouble is that the flv result is quite poor: it gives me big pixelitaed boxes.
I tried to use some -b parameters with no good results:
ffmpeg -i 1268459654.wmv -ar 22050 -ab 32 -f flv -s 640x480 x.flv
ffmpeg -i 1268459654.wmv -ar 22050 -ab 32 -f flv -s 640x480 -b 500k x.f4v
I also tried
ffmpeg -i 1268459654.wmv -vcodec libx264 -s 360x240 x.mp4
ans got: "Unknown encoder 'libx264'"
Any solution for that ?

libx264 does not come pre-installed (licensing issues I believe) if you've downloaded it via yum/RPM. You'll need to download the source and compile it yourself and specify libx264. Here's a command line I've used in the past with decent results, and I would consider the MP4 Container over the dated, FLV format personally.
ffmpeg -i (file) -acodec libfaac -ab 44k -vcodec libx264 -vpre normal -crf 30 -threads 0
Make note of the "-vpre normal", as you should have some presets available under:
/usr/share/ffmpeg/libx264-normal.ffpreset or similar.
More details on compiling from source.

Related

Recording Screen with FFmpeg

I recently used the FFmpeg bash commands below to capture a screen recording.
Are there any improvements that I could make to streamline this process?
Or perhaps some settings to reduce the size of the output files?
Ideally, I'd like to capture to mp4 directly. Is this possible?
Any advice generally about FFmpeg screen recording would be most appreciated.
ffmpeg -f x11grab -y -r 30 -s 1920x1080 -i :0.0 -vcodec huffyuv out.avi
# Then convert it to .mp4
ffmpeg -y -i out.avi -s 1920x1080 -f mp4 -vcodec libx264 -preset slow -crf 18 -b:v 3000k -maxrate 4000k -bufsize 512k -c:a aac -b:a 128k -strict -2 out.mp4
# and remove the .avi
rm out.avi
In general, for FFmpeg, input formats and output formats aren't tied to one another, so you can save in any format as long as the codecs are acceptable in the output format.
So, this will do,
ffmpeg -f x11grab -y -framerate 30 -s 1920x1080 -i :0.0 -c:v libx264 -preset superfast -crf 18 out.mp4
You may need to add -pix_fmt yuv420p after -i :0.0 for player compatibility.

FFmpeg adding click to beginning of audio

I've got an odd issue that's been bugging me for a while. I'm converting another format to video using FFmpeg; the conversion takes place prior and is fed into FFmpeg to be finally converted to an mp4.
Oddly, I seem to be getting a little click at the start of the resulting video; it's not present in the original audio but shows up in the final video.
Here is the sample audio. You'll notice that it has no pop at the start.
Here is the raw video input.
Here is the video my command is generating.
Here is the command I'm using to reproduce the issue (the actual conversion takes place in a Python script feeding FFmpeg the video via stdin and the audio via a temp file)
cat debug_raw_video.bin| ffmpeg -hide_banner -loglevel info -y -s 256x192 -r 30 -f rawvideo -thread_queue_size 600 -pix_fmt rgb8 -i pipe:0 -f s16le -ar 11025 -ac 1 -guess_layout_max 0 -i ./debug_audio.wav -vcodec libx264 -pix_fmt yuv420p -movflags faststart -acodec aac -strict experimental -vf scale=512:384:flags=neighbor -threads 0 -preset medium -tune animation ./out.mp4
FFmpeg version:
ffmpeg version 2.8.15 Copyright (c) 2000-2018 the FFmpeg developers
Also have the same issue with this version:
ffmpeg version 3.3.4-static http://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2017 the FFmpeg developers
Why am I getting a little click/pop at the beginning? I've been trying to figure this out for quite a while.
It appears you're specifying that the input audio is raw, but it's not:
$ file debug_audio.wav
debug_audio.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 11025 Hz
So I imagine the click you're hearing is the wav header being processed as audio. If I remove the related options, -f s16le and -ar 11025, ffmpeg correctly determines that the audio input is in wav format and produces a click-less output:
cat debug_raw_video.bin | ffmpeg -hide_banner -loglevel info -y -s 256x192 -r 30 -f rawvideo -thread_queue_size 600 -pix_fmt rgb8 -i pipe:0 -ac 1 -i ./debug_audio.wav -vcodec libx264 -pix_fmt yuv420p -movflags faststart -acodec aac -strict experimental -vf scale=512:384:flags=neighbor -threads 0 -preset medium -tune animation ./out.mp4

ffmpeg converted .mp4 videos are not playing on windows

I am converting videos with extension "flv","avi","mp4","mkv", "mpg", "wmv", "asf", "webm","mov","3gp","3gpp" into "mp4" for a better quality.
Command I am using:
ffmpeg -i <server_path>/g9zyy2qg54qp1l5spo2-mergedFile.webm -strict -2 -vcodec libx264 -preset slow -vb 500k -maxrate 500k -bufsize 1000k -vf 'scale=-1:480 ' -threads 0 -ab 64k -s 640x480 -movflags faststart -metadata:s:v:0 rotate=0 <server_path>/g9zyy2qg54qp1l5spo2-mergedFile7.mp4
Videos are working fine everywhere except on Windows. No Video is working on window platform. I tried playing them on firefox, opera, even downloaded them and played on media player software but didn't work at all.
Can you please tell me codecs I should use that make the videos play on windows as well?
My video gets played in Windows 10 after adding parameters about pix_fmt and resolution (width and height should be even number):
ffmpeg -i temp-%d.png -c:v libx264 -strict -2 -preset slow -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -f mp4 output.mp4
Use
"ffmpeg -i {$audioFile} -i {$videoFile} -map 1:0 -map 0:0 -strict -2 -vcodec libx264 -preset slow -vb 500k -maxrate 500k -bufsize 1000k -vf 'scale=-1:480 ' -threads 0 -ab 64k -s 640x480 -movflags +faststart -metadata:s:v:0 rotate=0 -fflags +genpts <server_path>/g9zyy2qg54qp1l5spo2-mergedFile7.mp4
(this uses the original command in your question)
Found a fix here convert webm to mp4. Now after getting merged webm file I am converting it to mp4 using command "ffmpeg -fflags +genpts -i 1.webm -r 24 1.mp4". This mp4 file is playing in window browsers.
For the above process I have to use 2 ffmpeg commands.
1.To make merge audio/video file into 1 webm file and
"ffmpeg -i {$audioFile} -i {$videoFile} -map 0:0 -map 1:0 -strict -2 {$mergedFileName}"
To make mp4 file.
"ffmpeg -fflags +genpts -i {$mergedFile} -strict -2 -r 24 {$mp4File}"
Can I club above 2 commands which input audio & video files to give me single mp4 file?
Edit:
I have clubbed the above 2 commands
"ffmpeg -fflags +genpts -i {$videoFile} -i {$audioFile} -strict -2 -r 24 {$mp4File}"
Its working well for me. The result mp4 video is playing in window 7 (chrome, firefox, opera) browsers. Also working in Linux (firefox, Opera ) browsers.

converted mp4 file using ffmpegvis not playing JW player

Just i converted mov video file to mp4 file using ffmpeg. But the converted file is not playing JW player. Actual mp4 file videos working fine in all browsers. Thanks for help.
ffmpeg -i movie.mov -vcodec libx264 -acodec acc -strict experimental -profile:v baseline -f mp4 -y mp4video.mp4
My ffmpeg conversion comment is correct. But ffmpeg installation is the reason for the issue. I used the following command to convert:
ffmpeg -i /uploads/sample.move -acodec libfaac -ab 96k -vcodec libx264 -vpre slower -vpre main -level 21 -refs 2 -b 345k -bt 345k -threads 0 /uploads/sample.mp4

How to get better quality converting MP4 to WMV with ffmpeg?

I am converting MP4 files to WMV with these two rescaling commands:
ffmpeg -i test.mp4 -y -vf scale=-1:360 test1.wmv
ffmpeg -i test.mp4 -y -vf scale=-1:720 test2.wmv
I've also tried:
ffmpeg -g 1 -b 16000k -i test1.mp4 test1.wmv
However, the .wmv files that are produced are "blocky and grainy" as you can see here in a small section of a video screenshot:
These are the sizes:
test.mp4 - 106 MB
test1.wmv - 6 MB
test2.wmv - 16 MB
How can I increase the quality/size of the resulting .wmv files (the size of the .wmv files is of no concern)?
Consider the following command instead (some outdated commands in the final answer section):
ffmpeg -i test.mp4 -c:v wmv2 -b:v 1024k -c:a wmav2 -b:a 192k test1.wmv
REFERENCES
https://askubuntu.com/questions/352920/fastest-way-to-convert-videos-batch-or-single
You can simply use the -sameq parameter ("use same quantizer as source") which produces a much larger sized video file (227 MB) but with excellent quality.
ffmpeg -sameq -i test.mp4 -y -vf scale=-1:360 test1.wmv
In newer versions of ffmpeg flag '-sameq' has been removed. To achieve similar results one should use 'qscale' flag with 0 value:
ffmpeg -sameq -i test.mp4 -qscale 0 -vf scale=-1:360 test1.wmv
Working answer in 2020, producing an output video without blockiness:
ffmpeg -i input.mp4 -q:v 1 -q:a 1 output.wmv
One thing I discovered after many frustrating attempts of enhancing the final quality was that if you don't specify a bitrate, it'll use a quite low average. Try -b 1000k for a starting point, and experiment increasing or decreasing it until you reach the desired result. Your file will be quite bigger or smaller, accordingly.
I used this and it turned out quite well
ffmpeg -i "file1.mp4" -q:v 0 -c:v wmv2 -b:v 1024k -c:a wmav2 -b:a 192k test2.wmv

Resources