Audio Video and Photo How To

How to add custom commands to Quodlibet

Enable custom commands plugin
create ~/.quodlibet/lists/customcommands.json
Add the following

"Browse folders (Dolphin)": {
"name": "Browse folders (Dolphin)",
"pattern": "<~dirname>",
"max_args": 50,
"command": "dolphin",
"unique": true,
"parameter": ""
},
"Copy to ~/Temp flat": {
"name": "Copy to ~/Temp flat",
"pattern": "<~filename>",
"max_args": 300,
"command": "cp  -t /home/user/Temp",
"unique": false,
"parameter": ""
},
"Copy to Temp perserve paths": {
"name": "Copy to Temp perserve paths",
"pattern": "<~filename>",
"max_args": 300,
"command": "cp --parents -t /home/user/Temp",
"unique": false,
"parameter": ""
}

How to split and merge video

cut

avconv -i input.mp4 -t 00:01:02 -codec copy p-edit2.mp4
avconv -i input.avi -vcodec copy -acodec copy -ss 00:00:00 -t 00:30:00 output1.avi
avconv -i input.avi -vcodec copy -acodec copy -ss 00:30:00 -t 00:30:00 output2.avi

use -ss hh:mm:ss.msec to indicate start
Merge

sudo apt install gpac
 MP4Box -cat p-edit1.mp4 -cat p-edit2.mp4 -cat prez2.mp4 final.mp4


How to download only audio from youtube

youtube-dl -x --audio-format mp3 https://www.youtube.com/watch?v=''video_id''

You can get the whole private channel by supplying a user name and the password:
youtube-dl --username ''user@email.dom'' -x --audio-format mp3 https://www.youtube.com/playlist?list=''channel_id''

How to extract audio from an mp4

avconv -i [input file] -vn [output].mp3

How to add an audio track to an MKV Matroska video

Get mkvmerge from the mkvtoolnix package then run
mkvmerge -o "file with extra track.mkv" --default-track 0 --track-name 0:MyNewTrack audio-track.ac3 video-file.mkv
Audio preceeds the video in the argument list to ensure it's the track number 0. The detault track and the track name are the nice (optional) arguments. You could also try mkvtoolnix-gui for the GUI approach.

How to split audio files using cue sheet

Assuming you want to do it for APE files. First add a repo for the MAC codec
sudo add-apt-repository ppa:flacon/ppa #required for MAC package
sudo apt-get update 
Get the tools:
sudo apt-get install shntool cuetools mac
Split the file
cuebreakpoints *.cue | shnsplit -o flac *.ape
And copy the tags
cuetag *.cue split-track*.flac
You can then convert it to MP3 with soundconverter and use puddletag to rename files to match their tags.

How to move photos already on the Shotwell database

Run
sqliteman photo.db
Or sqlite3
Change this sql query('/old/path/' and '/new/path/'):

update phototable set filename = replace(filename, '/old/path/', '/new/path/') where filename like '/old/path/%';
update backingphototable set filepath = replace(filepath, '/old/path/', '/new/path/') where filepath like '/old/path/%';
update videotable set filename = replace(filename, '/old/path/', '/new/path/') where filename like '/old/path/%';

Verify:

SELECT filename FROM phototable WHERE filename NOT like '/new/path/%';
SELECT filepath FROM backingphototable WHERE filepath NOT like '/new/path/%';
SELECT filename FROM videotable WHERE filename NOT like '/new/path/%';

How to find corrupt JPEG

Verify EXIF

find . -iname '*jpg' -print0 | xargs -0 exiftool -warning

Verify contents

find . -iname '*jpg' -print0 | xargs -0 jpeginfo -c | grep -E "WARNING|ERROR"

How to resize an image in a script

A script I use to generate the thumbnails:

#!/bin/bash -x
INPUT="$1"
OUTPUT="$2"
TEMPFILE="/tmp/thumnailer$$"
nice -n 20 transcode -V -i "${INPUT}" -y jpg,null -o "${TEMPFILE}" -c 2000-2001
mv "${TEMPFILE}000000.jpg" "${OUTPUT}"

How to convert Videos for mobile devices

Give Handbrake a try. It's a nice gui front end to avconv. Avconv is a fork of ffmpeg.
Otherwise convert your videos using WinFF

  • Use these settings: 480x320, 15fps, XVid in AVI. (mplayer4iphone)
  • It may be crucial to keep the fps to 15, since 24fps, etc. was jerky for me.
  • Here's my preset for WinFF if you want to create one: -r 15 -vcodec libxvid -vtag XVID -s 480x320 -aspect 4:3 -maxrate 1800k -b 1500k -qmin 3 -qmax 5 -bufsize 4096 -mbd 2 -bf 2 -flags +4mv -trellis 1 -cmp 2 -subcmp 2 -g 300 -acodec libmp3lame -ar 48000 -ab 128k -ac 2

How to convert MP3 tags to UTF8

sudo apt-get install easytag

or

sudo aptitude install python-mutagen 

or

cd <dir>
find -iname '*.mp3' -print0 | xargs -0 mid3iconv -eCP1251 --remove-v1

Find all files in a folder that have a specific EXIF tag

find 2006/03 -type f -exec bash -c 'exiftool "{}" | grep -q D70 && echo {}' \;
-q is to quiet grep

Rename all photos in the current folder by their exif date

for i in *; do exiv2 -F -r '%Y-%m-%d.%H%M%S.:basename:' "$i"; done
-F appends _1, _2 on a name conflict
-r does the rename

@HowTo @AudioandVideo