ffmpeg: how to add pixellate effect? - ffmpeg

I need to blur some uploaded videos and encoded them.
Infact by blur, it means pixellate them so "big squares" appear and blur it.
Any idea on how I can do that ? (ffmpeg would be great, by any command line windows tool should be ok)
Thanks.

FFmpeg can support the frei0r filters which includes pixeliz0r
Example:
ffmpeg -i input -vf "frei0r=filter_name=pixeliz0r:filter_params=0.02|0.02" output
The two pixeliz0r filter_params parameters are:
BlockSizeX: horizontal size of one "pixel"
BlockSizeY: vertical size of one "pixel"
Larger values will create larger blocks.
Where to get ffmpeg with frei0r support
Windows users can get the "full build" from gyan.dev.
Linux users can download or compile:
Download ffmpeg with frei0r support at johnvansickle.com.
Or compile ffmpeg by installing whatever package provides frei0r.h (such as frei0r-plugins-dev in Ubuntu or frei0r-devel in CentOS) and then add --enable-frei0r to your ffmpeg configure. See FFmpeg Wiki: Compile Guides.
macOS users can use Homebrew. You may need the --with-frei0r option.
More info
frei0r homepage
FFmpeg frei0r filter documentation

If you don't want to install the frei0r plugin for this, there's an alternative way.
dimensions=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of "csv=p=0:s=\:" input)
ffmpeg -i input -filter_complex \
"[0:v] scale='iw/15:-1', scale='$dimensions:flags=neighbor'" output
This scales down the input size (in this example, by 15) and then scales it back up to the original dimensions. The flags=neighbor tells ffmpeg to use the nearest neighbor rescaling algorithm which results in the pixelated effect. You can change the block size by changing the number 15.
The first line is needed to find out the input's original dimensions and scale back directly to it, otherwise the scaling down and scaling up might result in rounding errors that slightly alter the size of the output.

Related

imagemagick -auto-level in ffmpeg

I've been looking for a solution to perform the equivalent of magick -auto-level in ffmpeg but am unable to find anything. There are some references stating I should first manually discover the levels using other software like GIMP, however, I'm looking for an automated and simpler solution. Any ideas how to address this?
I've tried the following - the first enhanced the image which was initially prettry dark, but the second over-exposed it, causing it to become mostly white:
convert img.jpg -auto-level img2.jpg
ffmpeg -i img.jpg -vf "normalize" -y img2.jpg
Note: I apologize I cannot share the image as it is restricted by privacy policy

FFMPEG - Strange issue with video copy

I'm new here.
I have a set of TIF frames that equal 1 minute and 25 seconds of a video.
I'm attempting to copy the frames without re-encoding using the "-c:v copy" function to avoid visible quality loss for a process I'm doing on my side. The command is as follows:
ffmpeg -r 23.977 -i %06d.tif -c:v copy out.mkv
However for some reason, the timing does not seem to be accurate and the video is slightly desynced from the original, ending at 1 minute and 22 seconds instead.
When I use the following command:
ffmpeg -r 23.977 -i %06d.tif out.mkv
It comes out with the proper timing at 1 minute and 25 seconds, however, I did not appreciate the quality loss that came with it.
Is there a workaround to this or is there something I'm missing?
I used both Command Line and Windows Terminal.
In general, it would make sense to transcode when you go from tiff to video format. (I'm surprised it actually works.) You can set encoding quality to your own liking. See [this FFmpeg Wiki article[(https://trac.ffmpeg.org/wiki/Encode/H.264).

Realtime Muxing of videos

My problem basically comes from me having 2 different streams for videoplayback and having to mux them realtime in memory. One for video, and another for audio.
My goal is to create a proxy which can mux 2 different webm streams from their URLs, while supporting range requests (requires knowing the encoded file size). Would this be possible?
This is how I mux the audio and video streams manually using ffmpeg:
ffmpeg -i video.webm -i audio.webm -c copy output.webm
But, this requires me to download the video fully to process it, which I don't want to do unfortunately.
Thanks in advance!
If you are looking for this to work in go you can look into
github.com/at-wat/ebml-go/webm
This provides a BlockWriter interface to write to webm file using buffers; You can see the test file to checkout how to use it
https://github.com/at-wat/ebml-go
Checkout ffmpeg pipes.
Also since you have tagged go - i'm assuming you will use os/exec - in which case also checkout Cmd.ExtraFiles. This lets you use additional pipes(files) beyond just the standard 0, 1 and 2.
So let's say you have a stream for video and one for audio piping to 3 and 4 respectively. The ffmpeg bit of your command becomes:
ffmpeg -i pipe:3 -i pipe:4 -c copy output.webm

DirectShow Capture Source and FFMPEG

I have an AJA Capture card. The drivers installed with the card include some DirectShow filter. If I pop the filter into GraphEdit I see this:
and if I run the ffmpeg command
ffmpeg -f dshow -list_options true -i video="AJA Capture Source"
I see
[dshow # 0034eec0] DirectShow video device options
[dshow # 0034eec0] Pin "Video"
[dshow # 0034eec0] pixel_format=yuyv422 min s=720x486 fps=27.2604 max s=1024x
486 fps=29.985
...
[dshow # 0034eec0] Pin "Audio 1-2"
[dshow # 0034eec0] Pin "Line21"
video=AJA Capture Source: Immediate exit requested
So I see the Video and Audio pins I need. But when I try to run an ffmpeg command to capture both, I can only figure out how to do the video part. How do I hook in to that audio pin? It seems all the examples and documentation point to using a separate audio device, and nothing about hooking into the pins. I'm running it out of a batch file for now like this and I use the ^ to break the line
ffmpeg.exe ^
-y ^
-rtbufsize 100M ^
-f dshow ^
-i video="AJA Capture Source" ^
-t 00:00:10 ^
-aspect 16:9 ^
-c:v libx264 ^
"C:\VCS_AUD_SAMPLE.mp4"
Again, the command above will get me some beautiful video, but I can't figure out the audio part. Is this even supported in ffmpeg or am I going to have to modify the ffmpeg dshow code?
I am the developer of this filter.
Actually the same device is used for both audio and video streams. Moreover, the data for both streams are the result of one function call. Dividing by separate audio and video filters in other cards (example - DeckLink) is artificial (they must be internally connected). Possible reason for division - an attempt to simplify the graph. However, this can lead to other problems (using streams from different devices).
Why ffmpeg can't work with pins of the same filter - not clear to me. This problem of ffmpeg developers.
About only one instance access - very old version of AJA Capture Source filter used. A more recent version of the filter allow you to create multiple instances simultaneously (but only one instance may be in "Play" state). Please, check AJA site for download latest versions of filters. If you like to check latest beta versions of AJA filters, please, write to me at support#avobjects.com
So after tracing through source code of FFmpeg it was deemed that it could not hook up to multiple pins on a dshow source, so instead of modifying the FFmpeg source, we piped the AJA source pins through two virtual capture sources to achieve the desired result.
OK support for this was (hopefully) added recently in FFmpeg dshow, you can specify ffmpeg -f dshow -i video="AJA Capture Source":audio="AJA Capture Source" now and it work.
There are even new parameters for selecting which pin you want to use, if you need them. https://www.ffmpeg.org/ffmpeg-devices.html#dshow
If it doesn't work for somebody/anybody please let me know rogerdpack#gmail.com or comment here.
From http://ffmpeg.org/trac/ffmpeg/wiki/DirectShow
Also this note that "The input string is in the format video=<video device name>:audio=<audio device name>.
So try
ffmpeg.exe -f dshow -i "video=AJA Capture Source:audio=audio source name"

FFMPEG not able to extract thumbnails of images larger than .6 MB

ffmpeg.exe -i "imageLarge.jpg" -y -f mjpeg -s 72x92 -vframes 1 -an thumbnail7292.jpg
We are using this command to generate thumbnails of image files using FFmpeg but found that it is not able to generate thumbnails of files larger than .6 MB can somebody suggest something on this.
It isn't clear what exactly the problem with ffmpeg is, but in any case I'd recommend using the convert utility from imagemagick. It's much simpler:
convert imageLarge.jpg -resize 72x92 thumbnail7292.jpg
If you give a description of the actual error, then more people will be able to help you.
EDIT
The OP's error is:
swScaler: Compile time max width is 2048
change VOF/VOFW and recompile
Cannot get resampling context
It's quite clear what the problem is. Your JPEG files are too big for your current build of ffmpeg. You will have to recompile ffmpeg or get a newer version if you want to work with larger images.
This is from src/libswscale/swscale_internal.h (version: FFmpeg SVN-r26402).
#if ARCH_X86
#define VOFW 5120
#else
#define VOFW 2048 // faster on PPC and not tested on others
#endif
That's the file you need to edit if you want to change the limits.
What version of ffmpeg are you using? This problem seems to have been addressed over a year ago.
If you don't want to rebuild ffmpeg, you could just use convert, like I originally advised.

Resources