Linux FFMPEG – Flip Vertical Video to Horizontal

I was recently shooting some videos on my phone to share with someone else and accidentally flipped the phone before filming a clip. I never film vertically as I know that our playback devices are not designed to playback vertical footage. But I screwed up and got a clip that was vertical. Since I would consider sharing such a clip “bad form,” I needed a quick and easy way to flip the clip. Enter FFMPEG.

This can be done very easily with a single line of code at the console or terminal in Linux, assuming you have FFMPEG installed. Here’s the line of code:

ffmpeg -i input_video.mp4 -vf "transpose=2" output_video.mp4

Here’s what the code does. First, it calls “ffmpeg.” Then you tell it what video to input “-i input_video.mp4.” (The “-i” tells FFMPEG that what follows is the input.) If you’re not in the same directory as the video, you can simply add that information (e.g., /home/user/input_video.mp4). Next, the “-vf “transpose=2″” tells FFMPEG to first “-vf” create a filtergraph (basically, apply a filter) which is “transpose.” The “2” indicates how much to rotate the video – 90 degrees in this case. Finally, pick a name for your file and a file extension. That’s it. That will rotate your video from vertical to horizontal.

Here’s an actual example of code that I used:

ffmpeg -i /home/ryan/Desktop/vertical.mp4 -vf "transpose=2" /home/ryan/Desktop/horizontal.mp4

Sources for this post. FFMPEG’s documentation (here and here) and this post.

 718 total views,  2 views today

Linux: remove all directories with same name

I ran into an issue with a piece of software that created hundreds of directories amidst my music and video collections.  However, all of the directories had the exact same name.  Rather than delete all of them individually, I figured there had to be a way to delete them all with a single command.  Turns out there is.  I found the directions here.

Step 1) Open a terminal in Linux.

Step 2) Navigate to the parent directory. In other words, find a folder that contains all of the offending folders.  For example:

$ cd /home/ryan/Desktop

Step 3) Use the “find” command combined with the remove directory command to delete all of the folders with the same name.  Here’s the command:

$ find -type d -name name_of_directories -exec rm -rf {} \;

 

Here’s what the above does.  “find” calls the “find” program, telling the computer to look for something.  “-type d” tells the find program to look for directories (d) or folders rather than files.  Next is the name of the directories or folders you want to find (replace that with the name you’re searching for).  “-exec” tells the computer to execute something when it finds a directory that has the name you’re searching for.  The computer will execute the “rm” command, which means “remove” the directory.  The “-rf” modifier tell it to remove everything below the folder as well (-r is recursive), so it will delete folders with files inside them as well.  The last part “{} \;” tells the computer to iterate this for every folder it finds.

It took me a few tries to get this to work, but when it did, it was pretty slick.  Saved me hours of having to manually delete everything.  Also, just a heads up: when the command works, it will give you a list of all the folders it deleted but will say something to the effect that it could not find the folders, which is a very awkward way of saying, “I just deleted this folder; it used to be there, but now it’s not.”

 646 total views