Skip to content

Tag Archives: Mac

Seals at Newburgh Seal Beach – Deshaking a Video with Mac, ffmpeg and vid.stab

I had no idea that taking a video using my 300 mm zoom would be that shaky. Anyway, there is help at hand. Do you spot the difference between the left-hand side (original) and the right-hand side (stablized) in the video of the seals above–in full resolution, it is much more astounding, btw.? How did I go about it? This is how:

1) I got homebrew for my Mac. From this page I copied the command and pasted it into a terminal window I had opened before. This istalled homebrew on my computer.
2) I had homebrew install ffmpeg by just typing “brew install ffmpeg” into the terminal. ffmpeg came with the vid.stab filter enabled already.
3) I went to the folder my shaky video was in by typing “ls ” into the terminal and dragging the folder from the bread crumb trail in finder.
4) Now the filter works in two passes.
4a) First pass: command: “ffmpeg -i -vf vidstabdetect -f null -“. This writes a file named “transforms.trf” into the same folder.
4b) Second pass: command: “ffmpeg -i -vf vidstabtransform=smoothing=5:input=”transforms.trf””. This writes the stabalized clip into the folder.
5) That’s it.

Max Ogden (commands in 4 are from his text) also adds a command to creade a side-by-side comparrison here.

You might want to rescale your video. Info on that filter of ffmpeg here.

Depending on the shakiness of your video, you might want to adapt the filter options a bit. On the website of vid.stab, you will find explanations on how to do that. I have found that with this really shaky video, it seems to work fine if I put shakiness to the maximum of 10 in the first pass (default is 5) and the smoothing to 30 (default is 10) in the second (see command line summary below).

Command Line Summary:

/usr/bin/ruby -e "$(curl -fsSL"
brew install ffmpeg
ls ***folder***
ffmpeg -i ***seals***.MP4 -vf vidstabdetect=shakiness=10 -f null -
ffmpeg -i ***seals***.MP4 -vf vidstabtransform=smoothing=30:input="transforms.trf" ***seals***-stabilized.MP4
ffmpeg -i ***seals***.MP4 -i ***seals***-stabilized2.MP4 -filter_complex "[0:v:0]pad=iw*2:ih[bg]; [bg][1:v:0]overlay=w"
ffmpeg -i -vf scale=1080:-1

Replacing the Volume Changing Sound after My Update to macOS High Sierra

It really is a nuissance. You get used to the look and feel and sound (!) of a system. Basically, the OS looks very much the same after the update but the different volume changing sound is a bit unnerving. Unfortunately, you cannot just copy the old file into the place the system is using for storing the sound. Reason is the so-called “System Integrity Protection,” which takes away the rights of administrators to fiddle with the internal organs of their own system. This seems to be a good idea to protect you against malware. However, in me it creates an uneasy feeling. After all, I’ve paid for the computer. It’s mine. How dare the system hinder me from editing it? This is the workaround:

  • Disable SIP: 1) Reboot into recovery OS (you gotta press cmd + R upon start); 2) start terminal (in Utilities); 3) type in “csrutil disable” (without the quotation marks) and hit enter; 4) reboot your computer.
  • Copy the old sound file into the position of the new one. (By the way: Create a backup of the new file, if you want to keep it. You can always copy from the system folder into another folder using Finder.): 1) start terminal; 2) “cd /System/Library/LoginPlugins/BezelServices.loginPlugin/Contents/Resources”; 3) “sudo cp “***” volume.aiff” (*** is the path to the old sound file you want to copy into the system folder / you can drag and drop the address from the bottom of your finder window if you select the file in there).
  • Enable SIP: 1) see above, but this time type “csrutil enable”; 2) reboot the computer; 3) Robert is your father’s brother.

PS: Just read here that SIP can cause other issues, too…

How to Import Photos from a Camera and Move Them to a Folder Depending on the Day, Month and Year Taken

This is for Mac OS X, without any guarantee and at your own risk (Think first!).

In the olden days, I used to have a tool called Camera Window to import photos from my Canon camera into the archive on my computer. On a windows machine, this worked by connecting the camera via USB cable with the computer, and it worked like a charm. On the Mac, I had to pull the SD card out of the camera and put it into the computer. Same thing: The photos were copies from the card to the computer, but not only to some random place. They were sorted and copied into folders according to the date they were taken. My folder scheme looked like this:


Now Camera Window doesn’t seem to want to import photos and videos from my Android devices. What a shame. I had to figure out another way. This is how it works for me. The solution uses Image Capture, AutoImport, an Folder Action Script and the freeware tool DIM. (Surely, one could have coded a nice script, but I couldn’t be bothered. There’s also some nice commercial software around, but it seemed too expensive (Hazel).)

1 Recognize that a card has been inserted or an Android device attached

Once you insert an SD card or connect an Android device, OS X recognizes the new device and acts the way you told it to act in the settings of an app called “Image Capture” (“Digitale Bilder”). If you cannot find the app in Spotlight, you can find it in the applications folder of your system.

Bildschirmfoto 2015-12-29 um 14.28.48

Select the device from the list on the left-hand side of the window and select the AutoImporter app (if you cannot see the selection option, press the little arrow icon).

2 Copy the files automatically into one location on the computer and delete files from card/device

Now you need to tell AutoImporter what precisely to do once it has been started by Image Capture. First you will have to locate the app. You can find it here: Mac > System > Library > Image Capture > Support > Application. Start it, go to the preferences, select your import folder (mine is called MotoGImport), and select to have the app delete the files from the camera once they have been copied (again: at your own risk and only if you want this).

Bildschirmfoto 2015-12-29 um 14.39.07

Now, once you insert your card/attach your device, “Image Capture” will recognise this, invoke AutoImporter, which will copy the files to your import folder on your computer and delete the files on your camera/SD card. If you are happy with the choices to create and sort into folders in AutoImport, you can have AutoImport do everything and you are done here. I wasn’t happy with the choices. This is why there is step 3.

3 Sort and copy the files into the proper location in the archive

Mac OS X can automatically observe folders and act upon “folder action”, e.g. if there are new files in a folder. Topher Kessler explains how this works over at MacIssues. Please read.

You can then create an apple script. I have used the “add – new item alert” and changed it in the script editor (you’ll probably have to save your script elsewhere and then move it to where the other scripts are: Library > Scripts > Folder Action Scripts). My script looks like this:

on adding folder items to this_folder after receiving added_items
	delay 30
		tell application "Terminal"
			do script "/Applications/dim -p; exit;"
		end tell
	end try
end adding folder items to

As you can see, the script basically invokes an app called DIM.

DIM is an app by Alan Light. You can get it here. There is a manual that will explain everything in detail. Please donate some money to Alan if you like the tool.

Now once I connect my Android phone or plug in an SD card, Image Capture will see this and start AutoImport, which will import the photos to the import folder. Folder Actions will see the new files in the folder and start DIM. DIM will move the files to their target destination. Done.

This is a solution without any clicking and it works with all devices. If your camera appears as a folder, you only need DIM and nothing else.

I imagine there are easier ways to get the job done, if you know any, please comment.

Random File Names for Shuffle

My DVD player doesn’t have a shuffle mode, and I wanted to create an mp3 DVD on which the order of files is randomized. This can be done by adding a random number to the beginning of the file name. There are all kinds of tools for Windows machines. On OS X, you don’t need them (you don’t need them on Windows either if you write a little batch file). I used the following line of code to be executed in the respective directory in Terminal. Worked like a charm. It can be optimized, I know. Prerequisite is that your folder only contains the files you want to rename. Make sure, that this is only a copy and not your originals as there is no undo function.

for i in *; do mv "$i" "$((RANDOM%10000+32767))_$i"; echo "Renaming $i as $((RANDOM%10000+32767))_$i"; done