FFMPEG GPU Image Processing - image-processing

I want to resize an image. I used ffmpeg for that. I used the following command
ffmpeg -i in.jpg -vf scale=200:200 -sws_flags lanczos out.png
Whether this command runs in CPU or GPU?? If the command is not running in GPU, how can i set it to run in GPU (NVIDIA) ??

It runs on the CPU. I don't think the PNG encoder can use the GPU, and neither does the JPEG decoder. You can try the below command and see if there's a speed or GPU utilization difference.
ffmpeg -hwaccel auto -i in.jpg -vf scale=200:200 -sws_flags lanczos out.png

Related

How to create a gif from an image sequence without dither with FFMPEG?

I'm able to create a gif from the image sequence, but I'm struggling to remove the dither from it.
This is the command I'm using to create the gif:
ffmpeg -f image2 -framerate 24 -y -i image_%d.png -loop -1 "C:\Users\agetr\Documents\_tmp\__giuf.gif"
And I've tried to use the paletteuse=dither=none filter in different ways with no luck.
P.S.: I'm very new to the ffmpeg cli
You need to use -sws_dither none (after the -i $file argument, and before the output file). I've tried this on current git/master of FFmpeg and it works as expected, but on older builds (e.g. 4.4.1) this doesn't work. I don't know why exactly, so use a recent (5.0 or any version from 2022, if possible) version/build.

OpenCV output on V4l2

I wanted to know if I can use "opencv" to write on a v4l2 device.
I would take a picture, apply small changes with the features of opencv, and then send it on a v4l2 device.
I searched on the web, but there are a lot of examples on how to read from a V4L2 device, but I found nothing about writing on v4l2.
can someone help me?
The question is 8 month old, but if you still need an answer (I suppose your OS is Linux):
Install v4l2 loopback module
1.1. Load and configure it linux: i.e. modprobe.conf: options v4l2loopback video_nr=22,23
Use such C++/OpenCV code: gist
2.1. Setup device using ioctl() call
2.2. Write raw RGB data to this device (i.e. /dev/video23)
2.3. Use it as regular v4l2 device (i.e. webcam or vlc v4l2:///dev/video23)
more: You can use ffmpeg with v4l2 loopback:
ffmpeg -f x11grab -r 12 -s 1920x1080 -i :0.0+0,0 -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 -vf 'scale=800:600' /dev/video22

Cleaning up an image for OCR with ImageMagick and 'textcleaner'

I have the following image that I'd like to prepare for an OCR with tesseract:
The objective is to clean up the image and remove all of the noise.
I'm using the textcleaner script that uses ImageMagick with the following parameters:
./textcleaner -g -e normalize -f 30 -o 12 -s 2 original.jpg output.jpg
The output is still not so clean:
I tried all kinds of variations for the parameters but with no luck.
Does anyone have an idea?
If you convert to JPEG, you will always have the type of artifacts you are seeing.
This is a typical "feature" of JPEG compression. JPEGs are never good for images showing sharp lines, contrasts with uniform colors between different areas of the image, using only very few colors. This is true for black + white texts. JPEG is only "good" for typical photos, with lots of different colors and shading...
Your problem will most likely completely get resolved if you use PNG as an output format. The following image demonstrates this. I generated it with the same parameters as your last example command used, but with PNG as the output format:
textcleaner -g -e normalize -f 30 -o 12 -s 2 \
http://i.stack.imgur.com/ficx7.jpg \
out.png
Here is a similar zoom into the output:
You can very likely improve the output even more if you play with the parameters of the textcleaner script. But that is your job... :-)

How to batch convert JPG image gallery to BPG image format

How to convert whole image gallery or family album from JPG to BPG image format?
I'm looking for some batch conversion tool, application or script on Windows platform.
Input directory must be processed recursively and image quality should be preserved.
Linux command line fragment I use for this task, with current directory being gallery of '*.JPG' files, without subdirectories.
parallel -i sh -c 'convert -quality 100 {} -scale "1280x1000>" {}.png && bpgenc -q 30 {}.png -o {}.bpg && rm -f {}.png' -- *.JPG
You may adjust (or remove) resizing and change -q 30 to lower value for more quality.
It depends on ImageMagick and bpgenc.
To run in on Windows, you probably will need Cygwin.
Look at
http://www.romeolight.com/products/bpgconv/
for nice Windows converter.
2 things to mention: Currently there is options menu in top right of window. And all BPG pictures are saved into folder on your desktop called bpg_encoded.
Martin

Slow performance cropping large JPEG2000 images with ImageMagick/Jasper

I have a 4000x3000, 3.7MB JPEG2000 file that I'm trying to process into cropped tiles. I do this with a command like:
convert 486.jp2 -crop 256x256+0+0 -format jpg 486_crop.jpg
This command takes 5 seconds to run on a current-model Mac Pro. ImageMagick is using the Jasper library, which I've read is very slow. I just want to make sure I'm not botching the command somehow before I abandon ImageMagick in this application.
ImageMagick has poor perf (pretty good results though). You can consider GraphicsMagick instead. A few interesting benchmarks (there is one for the crop option): GraphicsMagick 1.3.8 vs ImageMagick 6.5.8-10 Benchmark Report
On a year old Mac mini (2.53 C2D):
$ ls -hn test.jp2
-rw-r--r-- 1 501 20 10M Aug 12 23:40 test.jp2
$ time convert test.jp2 -crop 256x256 -format jpg test/%d.jpg
real 0m3.971s
user 0m3.383s
sys 0m0.535s
On a current-model quad-core Mac Pro it should run no slower.
I am using a stock version of ImageMagick from ports:
$ convert -version
Version: ImageMagick 6.6.3-0 2010-08-31 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: OpenMP OpenCL
Also it is same slow when tiling PNG or plain JPEG. Seems to me that JPEG2000 isn't the issue here.

Resources