mp4 Video to mp3 Audio

To convert mp4 videos to mp3 audio

ffmpeg -i video.mp4 -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 audio.mp3

Channels(ac), Bit Rate(ab) and Sampling Rate(ar) can be changed as seen above.

Advertisements

Creating an Image Grid – Image Magick

A friend of mine asked for an easy way to create an image grid of a specific dimension with four images. Two in each row. The method shown here can be slightly varied to accommodate other image grid sizes or individual image sizes easily.

I had to create six image grids from four image files each. So totally i had 24 images split into different folders, each folder corresponding to images needed for a particular image grid. Since this was a repeated task, and it could be done using just the terminal with Image Magick. I love Image Magick. I created a script file with the following code.


#!/bin/bash
convert a.png -resize 246x246\! a_e.png
convert b.png -resize 246x246\! b_e.png
convert c.png -resize 246x246\! c_e.png
convert d.png -resize 246x246\! d_e.png
montage a_e.png b_e.png c_e.png d_e.png -geometry 246x246+2+2 collage.png

That is it.

  • The first line is just letting the computer know that you are using bash script.This script has to be executed from the same folder as these images, else it wouldn’t work.
  • Lines two to five convert individual images named a, ,b, c and d to their edited images of uniform size, a_e, b_e, c_e and d_e respectively. We use the convert command for this. It is part of the Image Magick package. Did i tell you how much I love image magick?.
  • The resize parameter resizes the images. 246×246 specifies that the image size should be 246 pixels wide and 246 pixels high.
  • The exclamation mark(!) ignores aspect ratio. Since all the images i had were almost square i did not have to bother about the aspect ratio.
  • It is required that all the images be the size when you create an image grid, else the results would not be favorable. But you will get results though.
  • Now it is time to make our collage from these four images. We use the montage command for this. Also from the Image Magick package.
  • In the montage command, first you specify the list of images you want to use. The geometry parameter is used to specify the size of each image and the number of rows and columns in the image grid. Then finally the name of the output file.
  • 246×246 shows the width and height of the individual images, +2+2 shows the rows and columns of the image grid respectively.

With this script, I was done creating those image grids in less than five minutes. Took five minutes to google it though. 🙂 I did not know about montage before this post. You can read about resizing and montage using their links in this post. In case you have special needs.

The final result using duplicates of a sample image as my a, b, c, d files is this.

collage