FFMPEG video to image batch conversion - image

#echo off
setlocal enabledelayedexpansion
set EXE_FILE=E:\ffmpeg.exe
set INPUT_PATH=C:\folder\
set OUTPUT_PATH=C:\Images\
set COUNT=0
for %%F in (*) do %EXE_FILE% -i %INPUT_PATH% %OUTPUT_PATH%/%%F.jpg
popd
I want to save 1 sec videos to jpg images with this code. This doesnt work. Any solutions?

INPUT_PATH should be a video file, rather than a directory. You need to iterate through the input videos instead of iterating through the output images. ffmpeg will output all the images by itself (without you iterating through them, ie with a single command). Look at this guide for help. Here is an example from that guide:
ffmpeg -i video.mpg -r 1 -f image2 ffmpeg_temp/%05d.png
So what you're really doing in your script is you are making the number of digits in the name of the output images more and more.
%05.png will make image file names look like "00001.png", and %03.png will look like "001.png", etc.
But what you want is to go through the input files, so iterate through for example "video1.mp4", "video2.mp4", etc.

IF EXIST %~d1%~p1%~n1.jpg GOTO exit
setlocal enabledelayedexpansion
set EXE_FILE=E:\ffmpeg.exe
set OUTPUT_PATH=E:\Glasgow\Test
set COUNT=0
for %%F in (*.avi) do %EXE_FILE% -i %~d1%~p1%~n1.avi -r 1 -vframes 1 -ss 00:00:01 -f image2 -y %~d1%~p1%~n1.jpeg
popd

Related

Need help to convert all "mp4" files to "gif" in a folder/directry with ffmpeg and .bat

I need some help.I try work automation to eliminate unnecessary time, I was looking for a way to convert video files to gif files.
So I learned how to make it using ".bat" through Googling, and want to make it a ".bat file" that automatically converts all mp4 files at one click because only one file is converted at a time.
it worked perfect for me. but I got a lot of vidoe files what i have to convert. I installed ffmpeg in my PC(#window)
this is what i find
#echo off
chcp 65001
cls
setlocal
echo 프레임 수치를 설정하세요
set /p fps=
ffmpeg.exe -i "%~1" -vf "fps=%fps%,scale=860:-1:flags=lanczos,palettegen" "%~n1.png"
ffmpeg.exe -i "%~1" -i "%~n1.png" -lavfi "fps=%fps%,scale=860:-1:flags=lanczos [x]; [x][1:v] paletteuse" "%~n1.gif"
del "%~n1.png"
goto :a
Thank for reading it.

How to set file name after merging video files (batch script, FFMPEG)

I use this bat script for converting .mp4(x264) files to .mp4(x265)
for %% in ("*.mp4") do ffmpeg -i "%%a" -c:v hevc "%dp0NewFolder\%%~na[HEVC].mp4"
So I'm trying to make another bat script for merging video files(concat).
for %%i in (*.mp4) do echo file '%%i'>> vlist.txt
ffmpeg -f concat -safe 0 -i vlist.txt -c copy %~dp0NewFolder\%%~na.mp4
Files to merge would be like
Vid_1.mp4,
Vid_2.mp4,
Vid_#.mp4
...
I want to keep the part before "_" in the new file name
What should I use instead of %%~na? To make it just Vid.mp4
Currently it creates %~na.mp4
From what I got you don't need a big scheme to create a output filename since we are talking about 1 filename only, or did I get something wrong?
for /f "delims=_" %%a in ('dir /b /a-d *.mp4') do set "NewVideoName=%%a"& goto :Next
:Next
ffmpeg -f concat -safe 0 -i vlist.txt -c copy "NewFolder\%NewVideoName%.mp4"

Batch extract first 10 seconds of multiple mp3 files using ffmpeg

I have a folder filled with songs. I would like to make ONE mp3 file containing a mashup of 10 seconds of each song.
I have found that FFMPEG is an easy software to do so.
I found how to cut a single file : ffmpeg -ss 0 -t 10 -i file.mp3 file.wav
And how to write a loop for multiple steps : for i in *.mp3; do ...
But I am not sure how to mix the two into only 1 file. If it's not possible, I guess I can also make a separate 10 sec file for each and then regroup.
In Windows
Step 1 : Go into the folder with the songs
Step 2 : Paste the following line
FOR /F "tokens=*" %G IN ('dir /b *.mp3') DO ffmpeg -ss 15 -t 10 -i "%G" -acodec mp3 "%~nG_10s.mp3"
Step 3 : Put the 10s songs into another folder (or modify the regex) and paste
copy /b *.mp3 E:\combined.mp3
You can avoid the intermediate files by using ffmpeg's concat demuxer
#1 Create the concat text file
FOR /F "tokens=*" %G IN ('dir /b *.mp3') DO (echo file '%G' >> list.txt & echo inpoint X >> list.txt & echo outpoint Y >> list.txt)
X and Y are the start and end times, in seconds.
#2 Combine the selected portions
ffmpeg -f concat -i list.txt -c copy -vn out.mp3

Using FFMPEG to Batch Convert a Series of Separate Image Sequences

I am trying to convert a large set of image sequences (each contained within its own subfolder) to video files. I can currently convert one sequence at a time by using ffmpeg and this code:
ffmpeg -r 30 -i "Image%%05d.jpg" -vf scale=1376:768 -qscale:v 2 "Display 1.m2v"
I also occasionally batch convert avi files which are contained within a single folder using:
for %%a in ("*.avi") do ffmpeg -i "%%a" -qscale:v 2 "%%~na.m2v"
I assumed I'd be able to use this batch approach with separate image sequences.
What I’m having trouble with is figuring out the syntax for a similar batch code that will convert whatever image sequence is present in a folder (or subfolder) using the anyfile%%05d naming convention. The %%a syntax in the second line of code doesn’t seem to be compatible with the way ffmpeg recognizes image sequences anyfile%%05d in the first. Any thoughts?
According to your last comment all you need is then to:
iterate the subfolders of a base dir and evtl.
cd/pushd in there run your one working line and
step out and repeat until all subfolders are processd.
This is quite basic batch stuff.
#echo off
Pushd "X:\folder\to\start"
For /D %%A in (*) do (
Pushd "%%~fA"
ffmpeg -r 30 -i "Image%%05d.jpg" -vf scale=1376:768 -qscale:v 2 "Display 1.m2v"
PopD
)
PopD

Using FFmpeg to convert all images in a folder to mp4 or avi using a .bat file [Windows]

I'm trying to get all .png files in a folder to be converted into a video format in the same directory as the images. Now I can't understand how ffmpeg works, I just want something like this;
for /l %%k in (1,1,%images%) do (
ffmpeg.exe (I need help with the parameters here)
)
This is my very first help request ever and I'm not sure if I supplied enough information for this to be an easy answer. But at least TRYING to help me would be much appreciated. Thank you for reading!
#echo off
set /p framerate=Enter framerate:
for /r %%a in (*.png) do (
echo file '%%a' >> images.txt
)
ffmpeg.exe -r %framerate% -f concat -i images.txt -c:v libx264 -pix_fmt yuv420p video.mp4
del /q images.txt
Put this batch file AND ffmpeg.exe in the directory of all images
Run the batch file and all images in that the current folder will be converted into an mp4
The batch file will automatically close after it has completed

Resources