Friday, September 29, 2023

View information about audio or video files in command line

One of the command to accomplish this, is called mediainfo. It is not installed by default, so we have to install it first.

To install mediainfo in ubuntu, simply run
$ sudo apt update && sudo apt install mediainfo -y

Once installed, we can check the information of any audio / video file using the command
$ mediainfo myfile.mp4

Some of the information that we can get from a video file



















Some of the information that we can get from an audio file


Thursday, September 21, 2023

Extracting audio from video using ffmpeg

To extract audio from a video, here is the command
$ ffmpeg -i video.mp4 -q:a 0 -map a audio.mp4

whereby we supply the name of our video to using -i and put the name of the audio file at the end of the command.

If we want to extract only some part of the audio from the video, we can use below command
$ ffmpeg -i video.mp4 -ss 00:03:00 -t 00:00:45.0 -q:a 0 -map a audio.mp4

where -ss is the start time of the video, that we want to extract, and -t is the duration of how much time we want to extract from the -ss time. In the above example, the output will be an audio extract from a video called video.mp4, starting from the third minute, until 45 seconds after the third minute.  

Monday, September 18, 2023

Converting rpm into deb, tgz and vice versa using alien

To convert rpm to deb, or vice versa, we can use a tool called alien. To install alien in an ubuntu machine:
$ sudo apt install alien -y

To install alien in redhat based distro:
$ sudo dnf install alien -y

Once installed, we can easily convert any rpm into deb:
$ sudo alien --to-deb myapp.rpm

A file called myapp.deb will be created once alien finished doing its magic.

We can also use alien to convert deb to rpm:
$ sudo alien --to-rpm myapp.deb

A file called myapp.rpm will be created.

We can also convert to tgz package:
$ sudo alien --to-tgz myapp.deb

To generate multiple packages format:
$ sudo alien --to-rpm --to-deb myapp.tgz

Sunday, September 10, 2023

Determine if your system is using systemd

Systemd is a suite of basic building blocks for a Linux system that provides a system and service manager that runs as PID 1 and starts the rest of the system. It works as a replacement for sysvinit.
Almost all popular distros are using systemd, but if you need to use old version of the popular distros, or simply some non popular distros, here is how you can determine whether the linux your are having is using systemd, or not.

First, check which process is running PID 1.
$ ps 1

The output, most of the time will be /sbin/init. 






Now we need to determine if /sbin/init is a symlink to something else. There are 2 commands we can use to achieve that:
1. use stat
$ stat /sbin/init
2. use readlink
$ readlink /sbin/init

In a systemd based system, you will be getting output showing that /sbin/init is actually a symlink to /lib/systemd/systemd, where as in other system, you will not get that output.




Monday, September 4, 2023

Remove background from picture using command line

Removing a picture's background is sometimes a necessity, especially if you need the picture to integrate into other document or other picture. Here I will show how we can achieve that in linux using a python application called rembg.

First, make sure we have python installed. Most linux will have it installed by default, but just check to make sure
$ python -V






In order avoid installing python libraries globally, we will create a virtual environment to keep the rembg application files. You can read more about virtual environment, by clicking here. So we will create a virtual environment called rembg
$ python3 -m venv rembg

Activate the virtual environment
$ cd rembg
$ source bin/activate

Update pip
(rembg) $ pip install --upgrade pip

Install rembg[cli] package
(rembg) $ pip install rembg[cli]

Once installed, we can use "--help" to see what are the options available for rembg
$ rembg --help

Now we can use rembg to remove background. Let's say we have a picture called mypicture.jpg, and we want to remove its background, and save the new picture as mypicture-nobg.jpg:
(rembg) $ rembg i mypicture.jpg mypicture-nobg.jpg

Verify that the background has been removed in the new picture.

rembg also comes with http-server, for those who wanted a web interface to remove background from picture. Just run rembg with "s" flag to launch the rembg http server
$ rembg s

A web app will be launched on http://localhost:5000, where you can upload the file to be background removed, and click submit to get the output.

























Simply press "ctrl + c" to cancel rembg's http server, when you are done.