Using cwebp for batch processing

4,157 views
Skip to first unread message

vanessa.n...@gmail.com

unread,
Feb 9, 2014, 6:46:49 AM2/9/14
to webp-d...@webmproject.org
I don't seem to be able to find any option to use a directory with *names.jpg files and convert them all in one operation to *names.webp files - does this exit?

Paul A Norman

unread,
Feb 9, 2014, 8:53:13 PM2/9/14
to webp-d...@webmproject.org
If on Windows, have you tried seeing if this works?

   cwebp blah blah c:\mydirectory\*.jpg    c:\myOutput\*.webp

Paul


On 10 February 2014 00:46, <vanessa.n...@gmail.com> wrote:
I don't seem to be able to find any option to use a directory with *names.jpg files and convert them all in one operation to *names.webp files - does this exit?

--
You received this message because you are subscribed to the Google Groups "WebP Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webp-discuss...@webmproject.org.
To post to this group, send email to webp-d...@webmproject.org.
Visit this group at http://groups.google.com/a/webmproject.org/group/webp-discuss/.
For more options, visit https://groups.google.com/a/webmproject.org/groups/opt_out.

oX Triangle

unread,
Feb 10, 2014, 9:28:05 AM2/10/14
to webp-d...@webmproject.org
for windows u can use batchfiles
here 2 batchfiles (a simple and a complex sample)
save and edit it, produce a link of it, rename the link to a useful name,
copy the link to "sent to" directory of windows
and now u can send multiple files or one directory for a cwebp-processing
from explorer with the right-click-menu "sent to" in a easy way

########## simple batch ############

@echo off
pushd %1
for /f "delims=" %%n in ('dir /b /s /a-d-h-s') do IF NOT ".webp" == "%%~xn" (
"%~dp0cwebp.exe" -q 25 -mt -m 6 -sharpness 0 -hint graph "%%n" -o "%%n.webp")
popd
for %%i in (%1\*.*) do IF NOT ".webp" == "%%~xi" del "%%i"
Rename %1\* *. 
Rename %1\* *. 
Rename %1\* *.webp


########## complex batch ############

@echo off
title MultiWebP 2.0 by metal03326
set SETTINGS=-m 6 -pass 10 -q 80 -sns 0 -f 100
for %%i in (%1) do if exist %%~si\NUL ( goto directory ) else ( goto file )

:file
"%~dp0cwebp.exe" %SETTINGS% %1 -o %1.webp
cls
goto end

:directory
set TOPROCCESS=0
set CURRENTFILE=1
setlocal ENABLEDELAYEDEXPANSION
pushd %1
for /f "delims=" %%n in ('dir %1 /b /s /a-d-h-s') do IF NOT ".webp" == "%%~xn" (
cls
set /a TOPROCCESS+=1
echo Counting files...
echo !TOPROCCESS! files found
)
echo Found %TOPROCCESS% file(s). Starting conversion...
for /f "delims=" %%n in ('dir %1 /b /s /a-d-h-s') do IF NOT ".webp" == "%%~xn" (
cls
set /a PROCESS=!CURRENTFILE!*100/%TOPROCCESS%
echo Processing file !PROCESS!%% ^(!CURRENTFILE! of %TOPROCCESS%^)...
title MultiWebP 2.0 - !PROCESS!%% ^(!CURRENTFILE! of %TOPROCCESS%^) - by metal03326
if 33 LEQ !PROCESS! color 1F
if 67 LEQ !PROCESS! color 3F
set /a CURRENTFILE+=1
"%~dp0cwebp.exe" %SETTINGS% "%%n" -o "%%n.webp"
) ELSE (echo File already WEBP.)
endlocal
cls
echo Removing non WEBP files...
for /f "delims=" %%n in ('dir %1 /b /s /a-d-h-s') do IF NOT ".webp" == "%%~xn" del "%%n"
echo Removing double extension...
for /f "delims=" %%n in ('dir %1 /b /s /a-d-h-s') do Rename "%%n" *. 
for /f "delims=" %%n in ('dir %1 /b /s /a-d-h-s') do Rename "%%n" *. 
for /f "delims=" %%n in ('dir %1 /b /s /a-d-h-s') do Rename "%%n" *.webp
popd

:end
color 2F
echo All done!
@echo
title MultiWebP 2.0 - All done! - by metal03326
pause

James Zern

unread,
Feb 10, 2014, 3:28:45 PM2/10/14
to webp-d...@webmproject.org
Hi,

On Sunday, February 9, 2014 3:46:49 AM UTC-8, webdev wrote:
I don't seem to be able to find any option to use a directory with *names.jpg files and convert them all in one operation to *names.webp files - does this exit?

This has come a few times [1]. The link has batch and shell examples, hopefully it will help.

bach99

unread,
Oct 25, 2018, 1:40:28 PM10/25/18
to WebP Discussion
I mean like according to the documentation, I should be able to get a sequential batch of PNGs in a folder and put them together into an animated webp. Is this what that method achieves? Thanks.

James Zern

unread,
Oct 25, 2018, 11:08:35 PM10/25/18
to WebP Discussion
Hi,


On Thursday, October 25, 2018 at 10:40:28 AM UTC-7, bach99 wrote:
I mean like according to the documentation, I should be able to get a sequential batch of PNGs in a folder and put them together into an animated webp. Is this what that method achieves? Thanks.

cwebp is meant for a single file, to encode multiple images this method would encode each file sequentially. Currently img2webp works on multiple files all given on the command line or via a text file containing a list of command line parameters, it doesn't read a folder itself. If the documentation isn't clear we can address that, which are you referring to?
It would be possible for img2webp to read a folder, but this would limit your ability to change settings (e.g., -lossy/-lossless) for individual frames. If this doesn't matter then something like 'ls *.png > FILES; ./img2webp FILES' or 'dir *.png > FILES & ./img2webp.exe FILES' should work.

oX Triangle

unread,
Jan 8, 2019, 11:16:31 AM1/8/19
to WebP Discussion
does img2webp use multicore/hyperthreading?

mfg from berlin 

Pascal Massimino

unread,
Jan 10, 2019, 3:53:00 AM1/10/19
to WebP Discussion
Hi,


On Tue, Jan 8, 2019 at 5:16 PM oX Triangle <oxdos...@gmail.com> wrote:
does img2webp use multicore/hyperthreading?

Right now, it doesn't.


skal/


mfg from berlin 

--
You received this message because you are subscribed to the Google Groups "WebP Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webp-discuss...@webmproject.org.
To post to this group, send email to webp-d...@webmproject.org.

feni...@gmail.com

unread,
Apr 30, 2020, 5:47:22 PM4/30/20
to WebP Discussion

"via a text file containing a list of command line parameters" - could you explain, please? Maybe the example of this file...

feni...@gmail.com

unread,
Apr 30, 2020, 6:15:42 PM4/30/20
to WebP Discussion
sorry, I found the solution. But I think the documentation is not clear to everyone. The example of command: img2webp execute.txt
execute.txt should contain the FULL command, for example:
-o path_to_output\to_webp_375.webp -min_size path_to_png_1/to_webp_380001.png path_to_png_2/to_webp_380002.png path_to_png_3/to_webp_380003.png

Pascal Massimino

unread,
May 4, 2020, 3:02:27 AM5/4/20
to WebP Discussion
Hi,

On Fri, May 1, 2020 at 12:15 AM <feni...@gmail.com> wrote:
sorry, I found the solution. But I think the documentation is not clear to everyone. The example of command: img2webp execute.txt
execute.txt should contain the FULL command, for example:
-o path_to_output\to_webp_375.webp -min_size path_to_png_1/to_webp_380001.png path_to_png_2/to_webp_380002.png path_to_png_3/to_webp_380003.png


Indeed: the parameter file 'execute.txt' should contain all the parameters you usually pass to 'img2webp' command line.
Note that they don't have to be on the same line if it helps readability. Could be:
   -o path_to_output\to_webp_375.webp 
   -min_size
  -d 80 path_to_png_1/to_webp_380001.png 
  -d 66 path_to_png_2/to_webp_380002.png 
  -d 80 path_to_png_3/to_webp_380003.png
  etc.

for instance.

glad you found a solution,
skal/
 

On Friday, May 1, 2020 at 12:47:22 AM UTC+3, Сергей Вдовин wrote:

"via a text file containing a list of command line parameters" - could you explain, please? Maybe the example of this file...

On Friday, October 26, 2018 at 6:08:35 AM UTC+3, James Zern wrote:
Hi,

On Thursday, October 25, 2018 at 10:40:28 AM UTC-7, bach99 wrote:
I mean like according to the documentation, I should be able to get a sequential batch of PNGs in a folder and put them together into an animated webp. Is this what that method achieves? Thanks.

cwebp is meant for a single file, to encode multiple images this method would encode each file sequentially. Currently img2webp works on multiple files all given on the command line or via a text file containing a list of command line parameters, it doesn't read a folder itself. If the documentation isn't clear we can address that, which are you referring to?
It would be possible for img2webp to read a folder, but this would limit your ability to change settings (e.g., -lossy/-lossless) for individual frames. If this doesn't matter then something like 'ls *.png > FILES; ./img2webp FILES' or 'dir *.png > FILES & ./img2webp.exe FILES' should work.

--
You received this message because you are subscribed to the Google Groups "WebP Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webp-discuss...@webmproject.org.
Reply all
Reply to author
Forward
0 new messages