gpt4 book ai didi

batch-file - 如何使用 ffmpeg 将多个文件转换为 GIF

转载 作者:行者123 更新时间:2023-12-04 23:05:45 24 4
gpt4 key购买 nike

关闭。这个问题需要更多 focused .它目前不接受答案。












想改进这个问题?更新问题,使其仅关注一个问题 editing this post .


1年前关闭。







Improve this question




我在这个论坛找到了Convert-mp4-to-gif只需将文件拖放到批处理文件上,就可以将视频转换为 GIF 文件。问题是我一次只能删除一个文件,而我可能有数百个文件,我只希望我的计算机可以处理这些文件。

代码如下所示:

@echo off
::** create animated GIF w/ optimized palette
::
:: https://ffmpeg.org/ffmpeg-all.html#gif-2
:: http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
:: http://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality

if not exist "%~dpnx1" goto :EOF
cd "%~dp1"

::** generate palette
@echo on
@echo.
"c:\program files\ffmpeg\bin\ffmpeg.exe" ^
-v warning -i "%~nx1" ^
-vf "palettegen" ^
-y tmp-palette.png

::** generate GIF
@echo.
"c:\program files\ffmpeg\bin\ffmpeg.exe" ^
-v warning -i "%~nx1" ^
-i tmp-palette.png ^
-lavfi "[0][1:v] paletteuse" ^
"%~n1.gif"
@echo off

del /q tmp-palette.png

if errorlevel 1 pause
goto :eof

我完全不知道如何编写批处理文件,而这段代码只是我在网上找到的对我有用的东西。任何人都可以帮我添加所需的代码以使我能够拖放多个文件吗?

最佳答案

@echo off
setlocal
::** create animated GIF w/ optimized palette
::
:: https://ffmpeg.org/ffmpeg-all.html#gif-2
:: http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html
:: http://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality
:: https://stackoverflow.com/questions/60747767/how-to-convert-multiple-files-with-ffmpeg-to-gifs

set "ffmpeg=%ProgramFiles%\ffmpeg\bin\ffmpeg.exe"

for %%A in (%*) do (
if exist "%%~A" pushd "%%~dpA" && (

@echo:
@echo "%%~A"
@echo generate palette

"%ffmpeg%" ^
-v warning -i "%%~nxA" ^
-vf "palettegen" ^
-y tmp-palette.png

@echo generate GIF
"%ffmpeg%" ^
-v warning -i "%%~nxA" ^
-i tmp-palette.png ^
-lavfi "[0][1:v] paletteuse" ^
"%%~nA.gif"

del /q tmp-palette.png
if errorlevel 1 pause

popd
)
)

更新了一个简单的 for环形。查看 for /?获取帮助文档。

关于batch-file - 如何使用 ffmpeg 将多个文件转换为 GIF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60747767/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com