This question already has answers here:
How do you convert an entire directory with ffmpeg?
(34 answers)
Closed 3 years ago.
I've been trying to convert entire folders of files using ffmpeg for a long time now. I've searched the web, found various answers, but none that helped me. Currently I'm using multiple instances of ffmpeg to convert more than one file at a time. But it's very time consuming and annoying to type in everything all the time, even with copy/paste.
To simplify my current code it would look something like this. I specify the input file and the output format (+ various settings):
ffmpeg -i "EXAMPLE.avi" newEXAMPLE.mp4
But what I would like is a single instance of ffmpeg to convert all files in a specific folder to a new format and for the files to keep their original name.
example1.avi > example1.mp4
example2.avi > example2.mp4
example3.avi > example3.mp4
and so on...
PS. I'm a bit new to these kind of things, so I'd much appreciate an explanation with your answer, so I can understand and learn. Thank you!
for /f "tokens=1 delims=." %a in ('dir /B *.avi') do ffmpeg -i "%a.avi" "%a.mp4"
This is for cmd window usage, if you want to use it in the batch script, than double all percent signs. You have run it in directory where your videos reside.
In order to make ffmpeg batch encoding easier for Windows users, I developed this free open-source application using .NET/C#. I would like to include it here as an addtional choice to make things easier for some Windows users who may not be so familiar with command-line operation.
https://sourceforge.net/projects/ffmpeg-batch
If you have multiple periods in your file names, you can use this method instead:
for /r C:\path\ %a in (*.avi) do ffmpeg -i "%a" "%~pa%~na.mp4"
Just edit "C:\path\" as necessary.
Related
I've been trying to convert multiple videos into image stacks using ffmpeg. I would like to convert multiple videos at once, and export all the images from one video into a new folder, named after the video.
I've found the following code from a previous question, but I can't get it to work on my computer (I'm using a mac).
#echo off for %%i in (*.mp4) do (if not exist "%%~ni\" MD "%%~ni" ffmpeg -i "%%i" -vf fps=1/1800 "%%~ni\%%~ni_%%d.jpeg")
I keep getting the error
parse error near %%i`
I think this is probably a syntax error, but I'm relatively new to using ffmpeg and working in the terminal.
I tried searching everywhere for a possible solution but I really can't find it. Hope someone can help me out here.
I have written a batch file to use FFMPEG to compress and sharpen JPGs in a folder.
FOR %%a in (*.jpg) DO (ffmpeg -i "%%a" -q:v 8 -vf unsharp=5:5:1.0:5:5:0.0 "2022 01 22 %%~na".jpg)
PAUSE
The new file comes out smaller in size, but is missing all the EXIF information that the original photo has.
I tried to add in the command "-metadata" but apparently it works for MP4 only. I have an existing solution with imageMagick but I'm hoping to solve this via FFMPEG. or is there a way to integrate exiftool into the batch file?
Thank you and I really appreciate any help here.
I've tried using soffice -writer and swriter to convert pdf files to jpg:
The documentation is pretty rare and I can't seem to make it work.
I'm sure something is happening because the OpenOficce icon shows up briefly but I don't know what because there is no trace of a new file...
I hope someone can help me...
This worked for me using LibreOffice 5:
for %F in (*.pdf) do "%ProgramFiles%\LibreOffice 5\program\soffice" -convert-to jpg "%F" -outdir conv
Explanation of the command:
To convert more than one file, the For command specifies each name separately.
\conv goes to C:\conv. To put the folder on the desktop instead, just use conv.
Use one dash rather than two on Windows.
No need for the headless argument.
It did not work in Apache OpenOffice, apparently for several reasons:
It had trouble reading the PDF.
It expected the conv folder to already exist.
Something seemed wrong with automatic conversion in general. It opened the file but nothing happened.
From time to time I receive several mkv's from a server I have. These mkv's are all part of the same recording, but they come in 1 minute chunks, and I don't want to have to take the time to stitch them together manually each time. Can this be done via an automated process in Windows?
EDIT: See my answer below for the solution that worked for me. The post by Endoro also looks promising.
I can give you an example:
#echo off &setlocal enabledelayedexpansion
cd /d "%sourcefolder%"
set "line="
for %%a in (*.mkv) do set line=!line! +"%%~a"
mkvmerge -o "output.mkv" %line:~2%
As I continued researching, I discovered a download page that also contained a review of mkvtoolnix (http://www.fosshub.com/MKVToolNix.html) that referred to some cmd commands he tested along with the standard GUI test. using the "mkvmerge --help" command, I was able to determine the appropriate command to stitch mkv files together. It looked something like this:
C:\Program Files (x86)\MKVToolNix>mkvmerge file1.mkv + file2.mkv --output C:\Users\User1\mkvfolder\combined.mkv
This stitched two mkv files together (that were located in the MKVToolNix folder), and puts the combined.mkv file in a different directory. It seemed to me that changing the source directories for either of the original mkv's (file1.mkv, file2.mkv) should be possible as well, so I next tried this:
C:\Program Files (x86)\MKVToolNix>mkvmerge file1.mkv + C:\Users\User1\Documents\file2.mkv --output C:\Users\User1\mkvfolder\combined.mkv
The above code merged file1.mkv (which I had placed in the mkvtoolnix directory) with file2.mkv (which I had located in a different directory), and placed the merged file (combined.mkv) in a third directory. The merged file ran cleanly in vlc, with no hiccups at the stitchpoint.
TL DR: go to http://www.fosshub.com/MKVToolNix.html, download MKVToolNix, and use the command line to merge mkv's.
You could try using AVIDemux with the --append arg. On this link there is also a batch file example script.
I'm trying to merge all *.pdf in directory :
gswin64c -q -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=Total_Files.pdf -dBATCH *.pdf
This is perfectly work for me on Linux, but when I run it on Windows
I'm getting **Error: /undefinedfilename in *.pdf.**.
Please could some one help me with this.
(My problem was practically exactly the same). My solution (with the help of previous answers) answers the original question slightly better (an actual MS-DOS example is below)
del filename.lst
for %%s in (C:\somefolder\some?wildcards*.pdf) do ECHO %%s >> filename.lst
gswin64c.... #filename.lst
To explain;
'>>' means append in MS-DOS - so firstly we delete file filename.lst
I read (just now in some other place) that %%s in MS-DOS batch files works (instead of %s). Obviously - one day the filenames may contain spaces (as mine did already) so better be safe and quote the filenames. So the better batch file is;
del filename.lst
for %%s in (C:\somefolder\some?wildcards*.pdf) do ECHO "%%s" >> filename.lst
gswin64c.... #filename.lst
Right now I just used this for inputting many EPS files - but many PDF files work fine too; as in the above example - I actually tested it with both - my result is a PDF with many EPS files in it - and many pages from multiple PDF files in one PDF (as per the question).
There was a previous question on this topic, the answer is the same, Ghostscript does not allow wildcards in the input filename, you must specify each file you want to have as input.
Why does it work on Linux ? Because the shell you are using expands '*.ps' to a full list of files before passing the command line to Ghostscript.
To do this in Windows you will need to execute a shell script, pipe the filenames to a file, then supply the file as an argument to GS.
EG, something like
for %s in (*.ps) do ECHO %s >> filename.lst
gswin64c.... #filename.lst
As alternative to the for loop
dir /b /o:n *.ps > filename.lst
gets the job done (/b to get the files only, /o:n to sort by name).
To solve the sorting problem completely, you could rename the first 9 files to 01->09, or open the output file in notepad and handle these few cases manually. But if you will have more than 100 files, this could be bothersome.
Sorry to stir up this one year old thread, which helped me with my problem, but I thought using 'dir' is easier, more flexible and doesn't need you to delete the file list before starting.