Bash script to play .m4v video and .ul audio together

So you have a lot of .m4v video files and a lot of .ul audio files with the same names. That, for example, might be a collection of  CCTV records, where the name of the file is the date and time of when the record was made. Now you would like to play them.

Create a bash script file in ~/bin, /usr/bin or similar directory. Paste the code inside. Add execution rights. Then run the script with .m4v video  file name as the only argument. The script will figure out name of the audio file on its own and afterwards it will play it all with a bunch of various parameters.

Let’s call it playit:

#!/bin/bash
 videoFile=$1
 audioFile="${videoFile%.*}.ul"
 mplayer -fps 25 -vf denoise3d=0:0:100:0 -cache 16000 -framedrop $videoFile -audiofile $audioFile -audio-demuxer rawaudio -rawaudio format=0x0007:channels=1:rate=8000

Later you can play all video files in the current directory with their accompanying audio files by means of another script, let’s call this one playall:

#!/bin/bash
 for i in *.m4v; do
    playit $i
 done

And another improvement. A script to look into all subdirectories of the current directory and play media found there. Useful if you have your packs of audio &  video files stored in timestamped directories. Let’s call this one playdirs:

#!/bin/bash
rootDir=$(pwd)
for subDir in */; do
cd $subDir
playall
cd $rootDir
done

And then yet another one. Play only files only in a single directory. That will be playdir:

#!/bin/bash
 subDir=$1
 rootDir=$(pwd)
 cd $subDir
 playall
 cd $rootDir

Installing XBM on Ubuntu

Installing XBMC (soon to be Kodi) media center software on an Ubuntu based system (Ubuntu, Mint etc. ):

  • sudo apt-get install python-software-properties pkg-config
  • sudo apt-get install software-properties-common
  • sudo add-apt-repository ppa:team-xbmc/ppa
  • sudo apt-get update
  • sudo apt-get install xbmc

Upgrading it some time later:

  • sudo apt-get update
  • sudo apt-get install xbmc

Removing it eventually, if the need will be:

  • sudo apt-get update
  • sudo apt-get remove xbmc*
  • sudo apt-get purge xbmc*

Convert ODT to PDF

Use LibreOffice (OpenOffice.org) in command line mode to convert all of the ODT files in the directory to PDF files in subdirectory PDF:

  • libreoffice --headless --convert-to pdf --outdir PDF ./*.odt

P.S.

Use ./*.odt instead of simply *.odt, because otherwise the program will consider file names beginning with “-” to be an argument and will fail.


Monitor directory with inotify

You can use inotifywait to watch a directory (or a file for that matter) for changes and run some action when they happen.

A sample script, which watches for a new file to be created and prints only its name:

#!/bin/bash

inotifywait -m -e create --format %f /tmp/mytestdir | while read FILE
do
  echo "$FILE"
done

Send message to system log

Send a message to the Linux system log from the command line:

  • logger "Hello World!"

P.S.

You can follow the messages logged to the system log by running:

  • tail -f /var/log/syslog

Bluetooth device added successfully but failed to connect

Trying to connect to Bluetooth headphones on Linux Mint 17.
The device is detected and paired, but fails to operate.

In blueman:
Using “Setup…” for the device:
Connect to: A2DP Sink (Send Audio)

Fails with message: “device added successfully but failed to connect”

THE REASON:
A bug in the software. Pulse audio module module-bluetooth-discover is not properly loaded. The blueman utility itself is said to unload the module.

THE SOLUTION:
Run manually from the command line:

  • pactl load-module module-bluetooth-discover

(Should the blueman be runing while doing it?)

Don’t forget to switch “Output” in “Sound Preferences” to your Bluetooth headphones.

It may not always work straightforward. Be patient and experiment a bit.


Silencing DSC PC1565-2P alarm after power loss

Given: DSC Classic PC1565H-2P alarm system with PC1555RKZ PowerSeries 8-Zone LED keypad. The battery is many years old.
Power supply to the building is lost. After it is restored, the alarm begins to howl. Various key combinations you normally use do not help to silence it.
Solution: Trip the fuses off and back on again. Then run to the unit and enter your password. You might need to enter it twice.
The solution actually worked but the details are not fully clear, as it was a unique case.

If after a while it starts beeping on motion, try entering *4 followed twice by the code.


Follow

Get every new post delivered to your Inbox.