MLT melt slideshow on Windows: unable to control output video length and problems with using wildcards - batch-file

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.

Related

Compressing PDF with ghostscript in .bat file - missing text

I am trying to compress PDF file and turn it grayscale with .bat script and i have big problem.
When i do the compression, the text in PDF turns red, when i added grayscale lines, after script finished its job, text is white/Gone.
Can someone help me fix it so the text can be still black? My script part:
gs -sDEVICE=pdfwrite -sProcessColorModel=DeviceGray -sColorConversionStrategy=Gray -sOutputICCProfile=sgray.icc -dPDFSETTINGS=/ebook -dCompatibilityLevel=1.7 -dCompressFonts=true -dEmbedAllFonts=true -dNOPAUSE -dQUIET -dBATCH -dAutoRotatePages=/None -sOutputFile="%TEMP%\%%~nxf" "%%~f"
Here is the image before and after compression :
You haven't said which version of Ghostscript you are using. You have not supplied the PDF file so that it can be investigated (pictures may show the problem, they are not helpful for diagnosing or fixing it).
You should not set -dProcessColorModel, especially not when you have set -sColorConversionStrategy.
You absolutely should not be setting -sOutputICCProfile.
There's really no point in setting PDFCompatibilityLevel higher than the pdfwrite device already sets it, unless you are adding content via pdfmark operators which requires a higher level (and you aren't doing that).
There's also no point in setting CompressFonts=true or EmbedAllFonts=true, as these are the default values.
When you are trying to diagnose a problem, don't set -dQUIET, you want Ghostscript to tell you about anything it thinks might be a problem.
On Windows (which I assume this is because you are talking about a .bat file) the Ghostscript executable is called gswin32, gswin32c, gswin64 or gswin64c, not gs. So I'm somewhat puzzled as to how you;re getting this to work at all.
You have set -dPDFSETTINGS=/ebook after setting -sColorConversionStrategy, if you look at the table of settings in the documentation you will see that the /ebook setting sets the colour conversion strtaegy to RGB, since that comes later on the command line than your ColorConversionStrategy, that's the one that takes precedence. The confusion between ProcessColorModel (DeviceGray, from your command line) and ColorConversionStrategy (RGB from the PDFSETTINGS value) is very possibly what is causing your problem.
When faced with this kind of problem I'd suggest you simplify the command line until you figure out what exactly is causing it. I would also suggest that you don't use PDFSETTINGS at all, as that changes many configuration controls all at once. Figure out which ones you want to use and turn them on individually.
As a final point, Ghostscript's pdfwrite device doesn't 'compress' PDF files, it produces PDF files from its input. If you choose to take action such as downsampling images or altering the colour space then it's possible that a new PDF file will be smaller than an input PDF file. It's not compressed though, it's smaller because you have discarded information.

Using ghostscript in a Windows .bat file to convert multiple pdf files to png

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.

Batch command double extension fix

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

Batch incrementation from external file

I have a script who creates new tags in a SVN, and add some files. I want to automate this task so I would like to find some way to do automatically the incrementation for the tags name, from 1.0 to X.0.
I thought about a conf file who would contains "1.0" as a first version number and who would be overwrite at each call to the script. But not sure I can get the "1.0" value from the file and then do an incrementation on it in my script.
Any help would be really appreciate.
Thanks in advance
Don't create a seed configuration file. Instead, let the batch script default to 1.0 if file does not exist.
#echo off
setlocal
set "conf=version.conf"
if not exist "%conf%" (set version=1.0) else (
for /f "usebackq delims=." %%N in ("%conf%") do set /a version=%%N+1
)
set "version=%version%.0"
(echo %version%)>"%conf%"
I'm assuming you will never run this process multiple times in parallel - it can fail if you do run in parallel. Modifications can be made to lock the conf file so you can run in parallel if need be. See the accepted answer to how to check in command line if given file or directory is locked, that it is used by a process? for more info.
Take a look at keywords in Subversion using autoprops.
First, setup subversion to honor keyword expansion
enable-auto-props = yes
[auto-props]
version.txt = svn:keywords=Revision
Then, setup a simple file, let's call it version.txt with the $revision$ keyword and some random content.
$revision$
Random content
Then, in your batch file, recreate the version.txt file with new random content
echo $revision$ >version.txt
echo %random% %date% %time% >>version.txt
and check in this new file every time your batch file is run, so it will become
$revision 32 $
4214 Mon 21/01/2013 15:53:27,62
This way, subversion will keep an accurate version number of all the runs of the batch file, even in multiple clients and simultaneosly.
You might then extract and use the revision number from version.txt with code similar to
for /f "tokens=1,2" %%a in (version.txt) do (
if %%a==$revision (
echo Revision number is %%b
echo do something with %%b, create %%b tag or whatever
)
)
Since you don't say what language you want to use only general remarks can be given:
It certainly is possible to maintain a small 'version' file holding the 'dottet version number', something like 0.2.6 maybe. That files content can be read by any process. You should implement a little collection of methods to split that content into its numerical tokens (major and minor version and the like). Those numerical values can be processed by any mathematical function you like to use. For example you can increment them. Another method would be some 'implode' function that takes the numerical tokens and creates again a 'dottet version number' (now maybe 0.2.7...) and finally you can write that information back into the file. It certainly makes sense to allow an argument that controls which part of the version should be incremented.
Such scheme is not really efficient, but often sufficient.
Note, that such approach will only work if you can guarantee that it is always only a single process to access that version file. Otherwise multiple processes might overwrite each others results which certainly is a cause of problems.
As an alternative, maybe a more elegant alternative, you might consider treating the subversion repository itself as seed storage for your version number: instead of reading a special files content (what if that file is deleted or something else happens?) make a request to the tags folder inside subversion. It should contain all previously tagged versions. So that is precisely the information you want. Take all version numbers, sort them, take the highest one and process it as above.

OCR batch processing tiff to text

I have a problem where i need to batch convert 50,000 tiff's into 50,000 txt files respectively. I am aware of abbyy finereader and some other pieces of software that may be able to do this, but a free solution would be best. I have been researching tesseract as well. Is anyone aware of any script or program that uses tesseract to do this automatically with a good quality output??
Thanks in advance
For a free solution with Tesseract, here's a straightforward command line batch file. Change the variable contents and/or create folders as necessary:
:Start
#Echo off
Set _SourcePath=C:\tifs\*.tif
Set _OutputPath=C:\txts\
Set _Tesseract="C:\Program Files (x86)\Tesseract-OCR\tesseract.exe"
:Convert
For %%A in (%_SourcePath%) Do Echo Converting %%A...&%_Tesseract% %%A %_OutputPath%%%~nA
:End
Set "_SourcePath="
Set "_OutputPath="
Set "_Tesseract="
In my opinion, I think Tesseract is going to give you the best results, whether you're looking at free solutions or not.
If you figure out how to convert one file, and then you post back the command you use, it will be easy to hack a batch script together to process multiple files.
Take a look at VietOCR, a Java/.NET frontend for Tesseract; its function seems to suit your need.

Resources