These are some scripts or FFmpeg commands that I use a lot
FFmpeg command to make an audio sample
This is the FFmpeg command that I have been using to make short audio samples. I keep it in a .bat file, and edit it every time… or did, until I got around to making the PowerShell script in the next section.
(a) Just copy the following into a .bat file. Replace input file and output file with the appropriate filenames.
ffmpeg -hide_banner -y -accurate_seek -ss 00:00.00 -i “input file.flac” -b:a 192k -t 01:23.00 “output file.mp3″
(b) With the .bat file, FFmpeg and the input audio file all in the same directory.
(c) Run the .bat file.
PowerShell command to make an audio sample
Here’s a little Windows PowerShell script to automate the FFmpeg command above, to make a (roughly) 75-second 192kbs MP3 sample of an audio file. You should be able to drag & drop an audio file into a shortcut & have an MP3 sample automatically created in the same folder as the original file.
(a) Put this script into a PowerShell file(.PS1) in the same folder as a copy of FFmpeg. Change the path in the last line.
param ( [string] $Paths, [string] $ExampleParameter ) $PathOnly = [System.IO.Path]::GetDirectoryName($Paths) $PathOnly = $PathOnly + "\" $NameExts = [System.IO.Path]::GetFileName($Paths) $Names = [System.IO.Path]::GetFileNameWithoutExtension($Paths) $NewNameExts = $Names + ".mp3" $RunFFmpeg = " -y -accurate_seek -ss 00:00.00 -i `"" + $PathOnly + $NameExts + "`" -b:a 192k -t 01:23.00 `"" + $PathOnly + $NewNameExts + "`"" Start-Process -FilePath "C:\Path\To\YourFFmpeg\ffmpeg.exe" $RunFFmpeg
(b) Make a shortcut to the .PS1 file. Edit the shortcut, changing the target to this (again, change the path!). If you remove the -noexit parameter, the PowerShell window won’t stay open. (The next line or two, in orange, is actually one line, ignore the word-wrapping.) C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -noprofile -file “C:\Path\To\YourFFmpeg\75secondsMP3.ps1”
(c) Drag-and-drop an audio file into the shortcut. It should pass the audio file’s full path/filename.ext to the PS1 script.
(d) The script should create a roughly 75 second 192kbs MP3 in the same location as the file that you dropped.
Update Folder Dates
So, I had moved to a new USB hard drive and all the folders on the new drive had the date that I copied them, not the original created date… which I wanted. The script reads the folder names and dates from a CSV file (that I create easily from my concerts database), and updates the folder dates (created, accessed, and modified).
(a) Copy the PowerShell script file into the parent folder of the folders to be re-dated. Change the extension to .PS1
(b) Edit the script file parameters. It’s explained in comments in the .PS1 file. In short, you need to update for the path/filename of the CSV file; yes/no for updating the dates created, modified and accessed; and you can have the routine pause every so-many lines to review what’s happening (or 0 for no pauses)
# ———- Edit these user parameters —————
$CSVfilename = “.\csvlist20190928.csv”
$Create4 = “yes”
$Modify5 = “yes”
$Access6 = “yes”
$ReviewOutput = 0
# ———–End user parameters ———————-
(c) Create your CSV file & put it in the location indicated (I normally have it in the same folder, hence the .\ in my example above). There are a few sample rows in the .PS1 file also. Three fields: folder name, the date to put on the file (format YYYY-MM-DD) and another field that I didn’t get around to using yet (but which is necessary as I was too lazy to change that). The first row must identify the field names, as in this example:
FolderName,Dldate,Dbcat Miles Davis - 1958 Spotlight Lounge,2004-10-31,Jazz MilesDavis5-PlayboyJF-Chicago-1959-08-07.flac,2004-10-31,Jazz "Reuben Wilson - 1996-02-01 & 1996-03-26 SOBs, New York City",2004-10-31,Jazz
(d) Run the PowerShell script.