Batch Convert Files Different Output Folder - bash

Goal is to convert all .wav files to .mp3 in a different location.
The following code works, but creates output files in the same directory.
All the newly created .mp3's are right alongside the .wav's.
for file in /path/to/*.wav; do lame --preset insane "$file" "${file%.wav}".mp3; done
How can I use terminal to convert a drive full of .wav's with lame and output the .mp3's to a different drive? I've tried changing lame's output, but this syntax grabs the entire filename. Looking for the most simple solution.
From the lame manual, the synopsis is very straightforward:
lame [options] <infile> <outfile>
Found the basic concept here

Assuming that the output files should be placed to /output, possible to extend loop to calculate the output file name using the 'basename'
OUT=/output
for file in /path/to/*.wav; do
# Replace .wav with .mp3
out=${file%.wav}.mp3
# Remove directory (anything up to the last '/'
out=${file##*/}
lame --preset insane "$file" $OUT/$out
done

Related

Running OpenFace tool on multiple video files via command line

I have downloaded the OpenFace tool for facial landmark extraction. Following the wiki, I am able to extract features of a single video file by running the following on a windows command line interface
./FeatureExtraction.exe -f "...\CREMA-D\VideoFlash\1001_DFA_ANG_XX.flv" -out_dir ".../openface-output" where -f represents the path of my input file.
However, I would like to extract ALL the .flv videos in the ...\CREMA-D\VideoFlash directory at once. Is there an easy way to do this?
Edit:
It is possible to add multiple -f flags e.g. ./FeatureExtraction.exe -f "...\CREMA-D\VideoFlash\1001_DFA_ANG_XX.flv" -f "...\CREMA-D\VideoFlash\1002_DFA_ANG_XX.flv" -f "...\CREMA-D\VideoFlash\1003_DFA_ANG_XX.flv" -out_dir ".../openface-output". Is there a way to perhaps loop through all the possible files and add this flag using a FOR DO loop?
Or potentially do a for loop of ./FeatureExtraction.exe -f "...\CREMA-D\VideoFlash\[file].flv" -out_dir ".../openface-output" for each file in a particular directory
My current hackish solution is to start a for loop and iterate through each file in the input location FOR %i IN ("...\CREMA-D\VideoFlash\*") DO .\FeatureExtraction.exe -f %i -out_dir "...\crema-d\openface-output"

How to batch "touch" files in subfolder with data from parent folder

I have a folder named "Video" on my Desktop and inside that folder are a bunch of .MTS video files. (00000.MTS, 00001.MTS, 00002.MTS etc...)
There is also a subfolder "H.265" (Video > H.265) which contains files (00000.mp4, 00001.mp4, 00002.mp4 etc...) which were made by converting the files from the parent folder. The problem is they don't contain the correct date created metadata.
I want to use the command
touch -r 00000.MTS 00000.mp4
touch -r 00001.MTS 00001.mp4
...
touch -r 000mn.MTS 000mn.mp4
to copy the date from the MTS to the mp4 file.
Is there a way I could write a for loop or something to do this for every single file?
I am using MacOS Mojave.
Something like this
cd ~/Desktop/Video
for v in *.mp4
do
vn=`basename $v .mp4`
touch -r "H.265/$vn.MTS" $v
done

Batch copy metadata from one file to another (EXIFTOOL)

Im currently using tags such as exiftool -FileModifyDate(<)datetimeoriginal, etc. in terminal/cmd...
Im switching from icloud and the dates in the metadata are exif (meaning finder and windows explorer just see the date they were downloaded)..
It's working but for any sloMo videos that are M4V, they dont change.. I have the originals which do have the right dates and was wondering if there is a way to match file names (123.mp4 = 123.m4v) and copy the metadata over... But I also want to do it in batches. (since every month I will be offloading my iphone every month or so) Thanks!
It will depend upon your directory structure, but your command should be something like this:
exiftool -TagsFromFile %d%f.mp4 "-FileModifyDate<datetimeoriginal" -ext m4v DIR
This assumes the m4v files are in the same directory as the mp4 files. If not, change the %d to the directory path to the mp4 files.
Breakdown:
-TagsFromFile: Instructs exiftool that it will be copying tags from one file to another.
%d%f.mp4: This is the source file for the copy. %d is a exiftool variable for the directory of the current m4v file being processed. %f is the filename of the current m4v file being processed, not including the extension. The thing to remember is that you are processing m4v files that are in DIR and this arguments tells exiftool how to find the source mp4 file for the tag copy. A common mistake is to think that exiftool is finding the source files (mp4 in this case) to copy to the target files (m4v) when exiftool is doing the reverse.
"-FileModifyDate<datetimeoriginal": The tag copy operation you want to do. Copies the DateTimeOriginal tag in the file to the system FileModifyDate.
-ext m4v: Process only m4v files.
Replace DIR with the filenames/directory paths you want to process. Add -r to recurse into sub-directories. If this command is run under Unix/Mac, reverse any double/single quotes to avoid bash interpretation.

shellscript to convert .TIF to a .PDF

I'm wanting to progress through a directory's subdirectories and either convert or place .TIF images into a pdf. I have a directory structure like this:
folder
item_one
file1.TIF
file2.TIF
...
fileN.TIF
item_two
file1.TIF
file2.TIF
...
...
I'm working on a Mac and considered using sips to change my .TIF files to .PNG files and then use pdfjoin to join all the .PNG files into a single .PDF file per folder.
I have used:
for filename in *; do sips -s format png $filename --out $filename.png; done
but this only works for the .TIF files in a single directory. How would one write a shellscript to progress through a series of directories as well?
once the .PNG files were created I'd do essentially the same thing but using:
pdfjoin --a4paper --fitpaper false --rotateoversize false *.png
Is this a valid way of doing this? Is there a better, more efficient way of performing such an action? Or am I being an idiot and should be doing this with some sort of software, like ImageMagick or something?
Try using the find command with the exec switch to call your image conversion solution. Alternatively, instead of using the exec switch, you could pipe the output of find to xargs. There is lots of information online about using find. Here's one example from StackOverflow.
As far as the image conversion, I think that really depends on your requirements for speed and efficiency. If you've verified the process you described, and this is a one-time process, and it only takes seconds or minutes to run, then you're probably fine. On the other hand, if you need to do this frequently, then it might be worth investing the time to find a one-step conversion solution that takes less time than your current, two-pass solution.
Note that, instead of two passes, you may be able to pipe the output of sips to pdfjoin; however, that would require some investigation to verify.

Find duplicate audio files via meta-tags?

I had Banshee's meta-data fixer handle all the meta-data inconsistency, now does anyone know some command line fu to search recursively through a directory and find duplicate files based on similar meta-data in regard to song title, artist name and finally, print a list of the file names of the duplicates?
I'm trying to remove many redundant audio files and I've found a program called dupeGuru to be somewhat helpful, but I'd like to simply print out a list of the duplicate filenames like:
/home/username/Music/song.mp3
/home/username/Music/oldItunes/song.wma
and then finally redirect this output to a file.
You can try exiftool.
To get comment tag of all *.{jpg,png} files in /path/to/dir/:
$ exiftool -r -ext .jpg -ext .png -comment /path/to/dir/

Resources