Friday, November 24, 2017

Basic Commandline Video Processing In Linux

video edit icon
Prerequisite: Install packages for MP4Box and ffpmpeg commands:
sudo apt install gpac ffmpeg

 

Three Methods to Trim Video:

  1. MP4Box -splitx ss:ss input.mp4 -out output.mp4 , where ss:ss are numerical values for start-seconds and stop-seconds. (Fastest, does not transcode)
  2. ffmpeg -i input.mp4 -ss hh:mm:ss -t hh:mm:ss -async 1 output.mp4, where hh:mm:ss are numerical values for hours, minutes, seconds.
  3. ffmpeg -i input.mp4 -vf trim=ss:ss output.mp4, where ss is a numerical value for seconds.
Annoyed with converting hours, minutes, seconds into total seconds? Use this bash function:
function to_sec() { echo "$1" | awk -F':' '{if (NF == 2) {print $1 * 60 + $2} else {print $1 * 60 * 60 + $2 * 60 + $3}}'; }
Usage examples: to_sec 2:47 or to_sec 1:2:47 or $(to_sec 2:47) or MP4Box -splitx $(to_sec 2:47):$(to_sec 7:33) input.mp4 -out output.mp4


 

Overlay a Logo onto Video:

    1. Static graphic logo:
ffmpeg -i input.mp4 \
-i logo.png \
-filter_complex "X:Y" \  # set logo position
-codec:a copy \  # just copy audio
output.mp4
where X:Y is the horizontal and vertical pixel positioning.
    2. Animated graphic logo:
ffmpeg -i input.mp4 \
-ignore_loop 0 -i animated-logo.gif \  # do not ignore looping
-filter_complex "X:Y:shortest=1" \  # limit to input video length
-codec:a copy \
output.mp4
where :shortest=1 is required, and where X:Y is the horizontal and vertical pixel positioning. Without shortest, the video transcoding will not end.
X and Y may be static numerical values, or ffmpeg built-in variables and equations. Examples:
  • Top right with 10 pixel margin : main_w-overlay_w-10:10
  • Top left with 10 pixel margin : 10:10
  • Bottom left with 10 pixel margin : 10:main_h-overlay_h-10
  • Bottom right with 10 pixel margin : main_w-overlay_w-10:main_h-overlay_h-10

 

 

Trim First x Seconds off Audio File:

ffmpeg -ss x -i input.mp3 -codec:a copy output.mp3 , where x is a numerical value for seconds.

 

Add Audio to Video and Trim to Shortest Source:

ffmpeg -i input.mp4 -i audio.mp3 -codec copy -shortest output.mp4

 

Overlay Logo and Add Audio with One Command:

ffmpeg -i input.mov \
 -i logo.png \
 -filter_complex "overlay=main_w-overlay_w-10:10" \
 -i music.mp3 -codec:a copy \
 -shortest output.mov
As always, good luck!
~~~
Written with StackEdit.

Firefox 57 Open Bookmarks in New Tab

icon

about:config –> browser.tabs.loadBookmarksInTabs = true




~~~

Saturday, November 18, 2017

dpkg: error processing package docker.io (--purge)

docker icon
Uninstall (remove, purge) failed in Ubuntu 16.04 :
$ sudo aptitude purge docker docker.io
The following packages will be REMOVED:
  docker.io{p}
0 packages upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
Need to get 0 B of archives. After unpacking 0 B will be used.
Do you want to continue? [Y/n/?]
(Reading database ... 386398 files and directories currently installed.)
Removing docker.io (1.13.1-0ubuntu1~17.04.1) ...
Purging configuration files for docker.io (1.13.1-0ubuntu1~17.04.1) ...

Nuking /var/lib/docker ...
  (if this is wrong, press Ctrl+C NOW!)

+ sleep 10

/var/lib/docker/nuke-graph-directory.sh: 64: /var/lib/docker/nuke-graph-directory.sh: shopt: not found
dpkg: error processing package docker.io (--purge):
 subprocess installed post-removal script returned error exit status 127
Errors were encountered while processing:
 docker.io
E: Sub-process /usr/bin/dpkg returned an error code (1)
It gives a hint: /var/lib/docker, so:
$ # This will erase all your container images
$ sudo rm -rf /var/lib/docker
$ sudo aptitude purge docker.io
The following packages will be REMOVED:
  docker.io{p}
0 packages upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
Need to get 0 B of archives. After unpacking 0 B will be used.
Do you want to continue? [Y/n/?]
(Reading database ... 386398 files and directories currently installed.)
Removing docker.io (1.13.1-0ubuntu1~17.04.1) ...
Purging configuration files for docker.io (1.13.1-0ubuntu1~17.04.1) ...
dpkg: warning: while removing docker.io, directory '/etc/docker' not empty so not removed
It gave another hint: '/etc/docker' not empty so not removed , so:
$ # This will erase all docker configs
$ sudo rm -rf /etc/docker/
$ sudo aptitude purge docker.io
Package docker.io is not installed, so it will not be purged
Package docker.io is not installed, so it will not be purged
No packages will be installed, upgraded, or removed.
0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B of archives. After unpacking 0 B will be used.

Now if you need official and latest docker-ce (community edition) and docker-compose, see here:
https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/
https://docs.docker.com/compose/install/

~~~
Written with StackEdit.

Wednesday, November 15, 2017

Emergency Downgrade to Firefox 56

rewind firefox

Firefox 57 is out!!! Oh sh*t, half my plugins are gone and i can’t work!
I had previously automated daily firefox upgrades on my Debian 9 with a root cronjob:

@daily cd /home/USERNAME/Downloads && /usr/bin/curl -L -o firefox-latest-linux64.tar.bz2 "https://download.mozilla.org/?product=firefox-latest&os=linux64&lang=en-US" && tar xvf firefox-latest-linux64.tar.bz2 -C /opt/ && rm firefox-latest-linux64.tar.bz2 && ln -sf /opt/firefox/firefox /usr/bin/firefox

Today When i opened my favorite browser, “Hooray, FF 57!” … “CRAP, I can’t get my work done” because half my plugins are not compatible.
Here is the emergency downgrade to 56.0.2:

cd ~/Downloads
curl -L -o firefox-56.0.2.tar.bz2 "https://download.mozilla.org/?product=firefox-56.0.2-ssl&os=linux64&lang=en-US"
sudo tar xvf firefox-56.0.2.tar.bz2 -C /opt/ && sudo ln -sf /opt/firefox/firefox /usr/bin/firefox



~~~
Written with StackEdit.