I need help with FFmpeg/batch. I have a couple of large batches of images (+14000 files each batch, +5 MB each image, .TIFF all of them) and I'm stringing them together into a .mp4 video using FFmpeg.
The date in the metadata is broken because of the way they're stored upon creation, so the time and date (T/D) are on the file_name. I need each frame to have its respective T/D (so its File_Name) burnt onto them for accurate measurements (scientific purpose).
With the help of google and reddit, I've managed to semi-automate it like so:
Master.bat:
forfiles /p "D:\InputPath" /m "*.TIFF" /S /C "cmd /c C:\SlavePath\slave.bat #file #fname"
Slave.bat:
ffmpeg -i "%~1" -vf "drawtext=text=%~2: fontcolor=white: fontsize=30: fontfile='C\:\\FontPath\\OpenSans-Regular.ttf'" "D:\OutputPath\mod_%~1"
Running Master.bat will output each individual image with the text burnt onto them and change the File_Name to mod_'File_name'.TIFF
Real example: 2018-06-05--16-00-01.0034.TIFF turns into mod_2018-06-05--16-00-01.0034.TIFF
The problem is that FFmpeg doesn't like it when my files have "--" in them ("date--time.miliseconds.TIFF") and doesn't like the miliseconds either, so I have to change the name of all files "manually" using Bulk Rename Utility (BRU). So, using BRU I rename all files to 00001.TIFF, 00002.TIFF, etc. and FFmpeg likes me again. It works great, but it means I can't be AFK.
After that, I have to go back to cmd and manually start the image to video conversion.
Also, FFmpeg doesn't seem to be using all cores.
I need help finding a way to:
Change master.bat's output to 00001.TIFF etc. automatically in order of processing (i.e. first to be processed is 1.TIFF, 2nd is 2.TIFF)
Add ffmpeg's img-to-vid function to the automating system
Get my CPU to use all the cores effectively if possible. 2014/15 posts found on google make it seem as though FFmpeg doesn't support multi-core or hyperthreading.
64bit Windows, i7 7700hq, gtx 1050 4Gb, C: SSD, D: HDD
Try this:
ffmpeg -i "2018-06-05--16-00-01.%4d.TIFF" -threads 4 out.mp4
https://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/image_sequence
Related
I have a batch file that runs a simple "burst" (a.k.a. split) multi-page PDF into single pages scripts, then moves them to a mapped network drive (Z:\). This batch file is triggered by the user and has been working without a hitch for at least two years. Last week, there was a flurry of Windows 10 (x64) updates and it stopped working. Now, instead of looping over every PDF in the source dir, the batch file will generate single pages for the first PDF in the iteration, then stops (although not showing any errors in output). I have tried a multitude of fixes, including using a full timestamp in the target file names to prevent overwriting, though I don't think that's the problem. It seems too coincidental that it just stopped working shortly after the updates (per my User). I'm not very experienced with batch files, and just drew this up based on a PDFTK example I saw. Here it is (not sure why line 2 is being split in the markup, but in the batch file lines 2 & 3 here represent a single line; PS the last line is also being weird, should read: del "C:\Users\My User\Desktop\PHYS_SRCDIR'BACKSLASH''STAR''DOT''STAR'" /F /Q):
cd C:\Users\My User\Desktop\PHYS_SRCDIR
for /r %%i in (*.pdf) do (pdftk "%%i" burst output "Z:\PHYSICALS_IN\%date:~10,4%%date:~4,2%%date:~7,2%_%%~ni_%%03d.pdf")
del Z:\PHYSICALS_IN\doc_data.txt /F /Q
del "C:\Users\My User\Desktop\PHYS_SRCDIR\*.*" /F /Q
I haven't seen any new responses lately, and have to divert my attention elsewhere, so my solution was simply to move the batch file to the server w/ "Z:" on it (allowing a limited login to the User), reverse it so it copies from User's PC mapped drive to the Server, and move on to the bigger fish I have to fry. I know, it's not really a solution but that is my circumstance. I'll check in from time to time to see if there are any other suggestions. Since the batch file works perfectly from a WS2012R2 box my only thoughts are that something in Windows 10 "broke" either PDFTK Server or batch files/command-line in general. Since it works singly and only breaks when trying to loop over several multi-page PDFs, I'm leaning toward batch files/CLI. Thanks for the suggestions, keep 'em coming!
I am using the following command within a batch script to, hopefully, eventually programmatically create simple video slideshows with transitions:
melt 131.jpg 132.jpg 133.jpg ttl=75 -attach crop center=1 -filter luma cycle=75 duration=25 -transition mix -consumer avformat:out.mp4 frame_rate_num=30 frame_rate_den=1
Most of this command is an adaptation for Windows of this command on the MLT website blog (with the exception of the part that scales and transforms the image). For some reason when I run this, however, the output video file is 25 minutes long!
I have two main questions:
a. How do I properly control the duration of each image in the video? I have experimented quite a bit with changing the parameters and I have a semi-decent understanding of what they all mean (I am a newbie to MLT but I figured that there's no way to do something like this easily in FFMPEG alone). The only way I have found to decrease the duration with any amount of control is to increase the output framerate to absurd numbers (which, of course, is not ideal as it's a massive waste of time and energy and still doesn't really solve the issue).
b. How do I use a wildcard to input all the .jpg files in a folder on Windows? I tried adding *.jpg but that didn't work and I don't know how else to do it within a batch script (I tried using the following code to get the file names as a variable, but I wasn't able to get string concatenation working correctly because it only outputs the final file name)
set files=
for /r %%i in (*.jpg) do (
echo %%i
set files=%files% "%%i"
)
echo %files%
Thank you for any suggestions!
When you specify a .jpg file, melt automatically chooses a producer internally. Depending on your environment and version, that producer will either be the qimage or pixbuf producer.
Both producers offer a "ttl" parameter to specify the duration of the image (in frames) for image sequences
https://mltframework.org/plugins/ProducerQimage/#ttl
https://mltframework.org/plugins/ProducerPixbuf/#ttl
In the example you linked, an image sequence is created by using the special syntax: photos/.all.jpg ttl=75
In your example, you specify a specific file name. So an image sequence is not created. Instead, a new producer is created for each file. The default length for a producer is 15000 frames.
https://github.com/mltframework/mlt/blob/master/src/framework/mlt_producer.c#L102
The length can be specified in the command line.
melt 131.jpg length=100 132.jpg length=100 133.jpg length=100
Change
set files=%files% "%%i"
to
CALL set "files=%%files%% "%%i""
This uses a subsidiary process to concatenate your filenames.
I have no idea about the solution to your other question.
I have many many pdf files in a directory that I need to convert from pdf to png. Currently, I am using the ImageMagick command:
magick mogrify -format png *.pdf
Because, there are so many files, I would like to use ghostscript directly because there are several sources that suggest that I could achieve a 75% reduction in processing time by doing this.
However, I am having trouble finding a clean dos command example to accomplish the same thing as the ImageMagick command above. I believe I need to execute the gswin64c.exe module but I am unsure how to do this to accomplish what I need to get done. Can someone provide me with a clean example of the ghostscript that accomplishes what I'm doing in ImageMagick?
After much digging, what I discovered was that ghostscript does not really have a wildcard that would allow reference to all files of a certain pattern (like ImageMagick does). To convert all files in a directory that are pdf's to png's, a dos script like the following could be used:
for %%x in (*) do gswin64c.exe -sDEVICE=png16m -dBATCH -dNOPAUSE -dQUIET -
SOutputFile="%%~nx.png" %%~nx.pdf
This can also be run from the command line by simply using single percentage signs (%) instead of the double percentage signs in the script above.
The terms are as follows:
gswin64c.exe: This is the dos command version of GhostScript. It should be used as opposed to gswin64.exe which will open a GhostScript window.
-sDEVICE=png16m This indicates the form of the output file. Is this case png.
-dBATCH -dNOPAUSE. These are GhostScript options and when employed will allow for continuous operation of the script (without them, the program will pause after each file converted).
-dQUIET - This suppresses notifications that display on stdout after each processed file.
SOutputFile="%%~nx.png" %%~nx.pdf This indicates the pattern for the input files and the output files. x is the loop variable. The % sign is used as a wild card. ~nx is a Dos convention which truncates the extension of an echoed file name.
Hi everybody i would like to ask how i can remove a mistakenly added second file extension using a batch script.
E.g. "test.aac.m4a" -> "test.m4a"
So the last extension is the right one which i want to have.
But this is ONLY the case for
.aac.m4a
-> .m4a
and
.m4a.aac
-> .aac
I know some batch scripting but
ren *.aac.m4a *.m4a
Won't work :(
Another thing worth mentioning would be that these double extensions come from my music software MusicBee.
I use mp4box on m4a files to extract the raw aac stream from the m4a container so i can edit it in other software.
Currently the syntax is:
mp4box.exe -raw 1 "<URL>" -out "<URL>".aac
The "<URL>" is the variable MusicBee will replace with the file url.
But this will add the .aac extension after the .m4a and i have no idea how to replace it instead. (and again when i repack the files ".aac -> .aac.m4a")
As far as i know MusicBee just replaces the variables and launches the batch code when activated so i think other batch code will work too.
Is it possible to prevent this double extension from even developing?
As always ANY help is apreciated!!
Thanks, Daniel
In preventing the double extension from developing I'm guessing you're not appending the file extension accordingly in the right way, I am however not familiar at all with Music Bee.
As for creating the right batch files that do what you want, I've used Advanced File Renamer in the past for all sorts of renaming patterns such as your case. It's freeware too! The program has a fairly advanced feature that allows users to write custom scripts in JavaScript user guide here. And can even generate batch scripts that do special renaming (as you've noted in the comments) for your specific use case.
For the other less advanced users the program has a GUI that makes it easy to do batch renames.
Best of all, if you're like me that avoids third party software installs just to do one thing as much as possible, the program has a portable mode that won't hook itself into your system, which is always good.
Read the manuals and guides there for more information. My answer might sound a little too much like advertising for it, but that's only because it's helped me so much in renaming my music a long time ago.
Here's a screenshot by the OP, RapidFireArts that shows how OP used the software to remove the second file extension.
It ought to be possible, but I have no idea how to work with your software to prevent the double extensions from occurring in the first place. But it is fairly easy to strip off the unwanted middle "extension".
If you know for a fact that none of your .m4a or .aac files are supposed to have multiple dots, then you could simply do the following:
ren *.m4a ???????????????????????????????????????????.m4a
ren *.aac ???????????????????????????????????????????.aac
Just make sure you have enough ? wildcards to match the longest name in your folder. See How does the Windows RENAME command interpret wildcards? for an explanation of why this solution works.
But sometimes file names legitimately have additional dots prior to the actual extension. If this is your case, then the following batch script will remove only the unwanted .m4a and .aac middle "extensions"
#echo off
for /f "eol=: delims=" %%A in ('dir /b /a-d *.m4a.aac *.aac.m4a') do (
for %%B in ("%%A") do ren "%%A" "%%~nB%%~xA"
)
Another option is to use my JREN.BAT regular expression file renaming utility. JREN.BAT is a hybrid JScript/batch script that runs natively on any Windows machine from XP onward. Ideally, the script should be placed within a folder that is included within your PATH. I like to use c:\utils for all of my non-standard utilities.
Once you have JREN.BAT, then all you would need would be
call jren "\.(m4a|aac)(?=\.(m4a|aac)$)" ""
Provided you understand regular expressions, and you take the time to read the built-in JREN help, then there are many wondrous things you can do with the utility. The help is accessed by issuing jren /? from the command line. You might want to use jren /?|more if you have not configured your console window to have a large buffer that enables scrolling to see prior output.
I use File Renamer Basic.
http://download.cnet.com/File-Renamer-Basic/3000-2248_4-10306538.html
It's Free
Is there a way to move files in a directory (we have 1.7 million) to folders based upon a date?
WOuld like to move all files created between 1-1-2010 and 2-1-2010 to a specific folder
You can use the Robocopy feature. It comes as default in Windows Vista and Windows 7 and you can download it in Windows XP in the microsoft website.
If your Windows is 64 bit it even move files that have a path longer than 256 characters, unlike the CTRL+C, CTRL+V on Windows Explorer (I can't understand why). To see the program help you can write the following in the DOS Prompt (example, usually you can't write to the root):
robocopy /? > c:\robocopyhelp.txt
Use the switches "/MINAGE" for setting the minimum age of the file to be copied/moved and "/MAXAGE" for setting the maximum age.
I've never moved files before and never tried to filter them by age, but I think the syntax should be (from drive F to G, for example, and only 2011 files):
robocopy F:\ G:\ /MOVE /MAXAGE:20110101 /MINAGE:20111231
Plus other parameters described on the "robocopy /?". Usually I add "/R:0 /W:0", for it not try to access systems files (can help if you run the batch file with administrator privileges) 1 million times with a wait time of 2 seconds for each system file it can't copy/move (2 million seconds or 23 days for just pagefile.sys and hiberfil.sys). And the "/A-:H" switch to un-hide the hidden files.
Keep in mind also the existence of NTFS Junctions (infinite loop in the C:\users directory) and encrypted directories and use the according switches.
This won't be very nice, but you could use forfiles twice. Once to move all files with a date greater than 2010-01-01 to the folder and a second time to move all files with a date greater than 2010-??-?? (can't parse your date format reliably) back to the original folder.
Not pretty, definitely.