Batch rotate video files

I like to capture videos of scenery while I am driving. I do that with the help of my phone mounted on a car cell phone holder. The phone keeps recording and later I edit out the boring parts. Now, this works very well when the phone is already mounted in the horizontal position when the recording starts and as well when it ends. However, if for any reason I pick up the phone anytime during recording the video gets saved in a vertical format. So I have to rotate those videos a lot. They can also be rotated in a video editing software like Kdenlive by applying the “Rotate” effect. However, then the video gets chopped off from the sides. I find it easier to rotate the videos before importing them to the video editing software. Since a lot of videos might end up being vertical when they should be horizontal I have to rotate a lot of videos. So I wrote a batch script to rotate a bunch of videos at once. The script runs on every mp4 file in the directory. The script needs to be edited to run on other video types in the videos are in other formats. Since the script runs on all video files it is best to segregate all the videos files that need to be edited in a separate folder and copy the script to that folder. Running the script in the folder which contains all video files might have the undesirable effect of rotating the files which do not need to be rotated.

The script is very simple. It is a for loop wrapped around a ffmpeg command.

for i in `ls -1 *.mp4`; do
echo $i "====================================================="
j="rotated-"$i
ffmpeg -i $i -vf "transpose=2" $j
done

 

transpose takes the following values
0 = 90 degrees CounterClockwise and Vertical Flip (default)
1 = 90 degrees Clockwise
2 = 90 degrees CounterClockwise
3 = 90 degrees Clockwise and Vertical Flip

Setting up a virtual environment for Python

Many specialized tools are written for some version of Python like python2.7 and has dependencies on some versions of packages like pandas 0.7.3. Installing these older versions will remove newer versions and create conflicts with existing code. So a better option is to create a virtual environment with the specific package versions only. For example, QSTK does not work with Python 3 or pandas 0.21. It only works with python2.7 and pandas 0.7.3. So we have to create a virtual environment and install these versions.

virtualenv --python=/usr/bin/python2.7 ~/python2.7-virtual-env


This will create the
~/python2.7-virtual-env directory if it doesn’t exist, and also create directories inside it containing a copy of the Python interpreter, the standard library, and various supporting files. Now, we have to go to that directory and run source activate to start a new environment (just like a chroot environment).

source ~/python2.7-virtual-env/bin/activate


This will start a new environment. To test that we are really in the environment 

$ which python

~/python2.7-virtual-env/bin/python

$ python --version
Python 2.7.12


The environment is now using the local version of python which is python 2.7. 
Now we can install the older versions of the required packages.

pip install pandas==0.7.3


==0.7.3 forces install of the version 0.7.3 of pandas. It removes newer versions if already installed by default.

Setting up a virtual environment in Anaconda

Now Anaconda itself is a virtual environment with the latest version of scientific and statistical tools. However, there will be instances where certain older codes will not run with newer versions of the packages. For example, the pandas datareader library which pulls data from Yahoo and Morningstar is broken in version 0.6.0 (See my GitHub page github.com/saugatach/stockanalysis). Let us say we are trying to work around this issue and want to get back pandas-datareader v0.5.0 but also want to keep the latest pandas-datareader v0.6.0. So we create a separate virtual environment within Anaconda called “stocks”. The process is very well detailed in the conda docs conda.io/docs/user-guide/tasks/manage-environments.html.

conda create --name stocks python=3.6 pandas-datareader==0.5.0

This creates a virtenv called stocks which has python 3.6 and the older pandas-datareader. We can activate the environment by

$ source activate stocks

The CLI prompt should have the environment name as the prefix. We can check if the correct version of our package is installed.

(stocks) $ pip3 list
........
numpy (1.15.1)
pandas (0.23.4)
pandas-datareader (0.5.0)
pandocfilters (1.4.2)

parso (0.3.1)

 

Download manager for Chrome

uGet is a download manager for Chrome which uses aria2, a command line download client, to speed up downloads. uGet supports segmented downloads which can generate a massive increase in download speed. In fact, we can reach the maximum bandwidth available using uGet. It can also serve as a true test for bandwidth capacity.  The best feature of uGet is that it can be integrated into Chrome (also Firefox) using a plugin from the Chrome Web Store. However, the Chrome Web Store plugin will not be able to find uGet unless the uget-integrator is installed first. The steps to integrate uGet into Chrome as a download manager are as follows. These commands work for Debian systems. For other Linux systems, the steps remain the same, only the commands would be different.

1. Install uGet and aria2

sudo add-apt-repository ppa:plushuang-tw/uget-stable
sudo apt update
sudo apt install uget
sudo apt install aria2

 

2. Install uGet-integrator

sudo add-apt-repository ppa:uget-team/ppa
sudo apt update
sudo apt install uget-integrator

 

3. Install uGet Integration from Chrome Web Store

https://chrome.google.com/webstore/detail/uget-integration/efjgjleilhflffpbnkaofpmdnajdpepi/

A little housekeeping might be required. We need to set the default download client to aria2

Settings -> Plug-In -> aria2

Also, I would set the default download location and the total number of active downloads.

Category -> Properties -> Category Settings -> Active Downloads -> 1 

Category -> Properties -> Default for new download -> Folder: