Date created: 03/02/21 10:19:43. Last modified: 07/13/21 13:00:14

Music & Media Commands

Audio

sudo apt-get install ffmpeg

 

Splitting Files

Split flac file with cue file:

sudo apt-get install cuetools shntool flac
shnsplit -f file.cue -t %n-%t -o flac file.flac 

 

Converting AIFF to WAV and Renaming

ffmpeg using find with bash sub-string replacement to change the filename ending:

find . -iname "*.aiff" -execdir sh -c 'x="{}"; ffmpeg -i "$x" "${x%.aiff}.wav"' \;

 

Converting Audio to FLAC

Need to specify the sample depth and sample frequency, to match the input files (in this case 16-bit 44.1Khz APE files):

for file in *.ape; do ffmpeg -i "$file" -af aformat=s16:44100 "${file/ape/flac}"; done

 

Converting Audio to MP3

Convert from flac directly to 320Kbps MP3:

# sudo apt-get install lame ffmpeg libavcodec-extra-53
for f in *.flac; do ffmpeg -i "$f" -acodec libmp3lame -ab 320k "${f%.flac}.mp3"; done

# Alternative:
find -name "*.flac" -exec ffmpeg -i {} -acodec libmp3lame -ab 320k {}.mp3

 

Decompress from flac to wav, then encode to mp3 320k

mkdir temp
flac -d *.flac
for f in *.wav; do lame -b 320k "$f" ./temp/"${f%.wav}.mp3"; done
rm *.wav 

 

Convert m4a/wma/flac audio to mp3 audio:

$ ffmpeg -i input_file.aac -acodec libmp3lame -ab 320k output_file.mp3
$ ffmpeg -i input_file.ac3 -acodec libmp3lame -ab 320k output_file.mp3
$ ffmpeg -i input_file.flac -acodec libmp3lame -ab 320k output_file.mp3
$ ffmpeg -i input_file.m4a -acodec libmp3lame -ab 320k output_file.mp3
$ ffmpeg -i input_file.ogg -acodec libmp3lame -ab 320k output_file.mp3
$ ffmpeg -i input_file.wav -acodec libmp3lame -ab 320k output_file.mp3
$ ffmpeg -i input_file.wma -acodec libmp3lame -ab 320k output_file.mp3

 

Convert video to audio:

When converting from a video file to an audio file, if the output audio file type and encoding isn't specified, the output file may be an video file, -vn tells ffmpeg to ignore the video stream so that the output is audio only:

ffmpeg -i Input_File.flv -vn -acodec copy

 

Converting Video to Audio

Convert mp4 video to mp3 (audio only):

# -i input file
# -acodec output audio codec
# -ac audio channels
# -b:a exact bitrate
# -ar audio sampling frequency
ffmpeg -i Input-Video.mp4 -acodec libmp3lame -ac 2 -b:a 320k -ar 48000 Output-Audio.mp3

# Convert all files in the current directory, using basename to replace the filename ending with mp3:
for file in *.mp4; do ffmpeg -i "$file" -acodec libmp3lame -ac 2 -b:a 320k -ar 48000 "`basename -s ".mp4" "$file"`.mp3"; done

# Instead of basename, if using BASH, us the built-in substring replacement method:
for file in *.mp4; do ffmpeg -i "$file" -acodec libmp3lame -ac 2 -b:a 320k -ar 48000 "${file/mp4/mp3}"; done

 

Pictures

# Provides "convert"
sudo apt-get install imagemagick-6.q16
# Provides "exiftool"
sudo apt-get install libimage-exiftool-perl

 

Resizing Pictures

Resize by percentage:

convert infile.jpg -resize 50x50% outfile.jpg

 

Reduce quality to a certain percentage of original:

convert infile.jpg -quality 40 outfile.jpg

 

EXIF Data

Removing EXIF data:

exiftool -all= image.jpg

 

Video

Joining Files

Rename video segments to remove trailer then join them together:

$ ls -1
segment100_2296000_av.ts?null=0
segment101_2296000_av.ts?null=0
segment102_2296000_av.ts?null=0
segment10_2296000_av.ts?null=0

$ rename 's/\?null=0//' *

$ ls -1
segment100_2296000_av.ts
segment101_2296000_av.ts
segment102_2296000_av.ts
segment10_2296000_av.ts

$ ffmpeg -i "concat:segment1_2296000_av.ts|segment2_2296000_av.ts|segment3_2296000_av.ts" -c copy -bsf:a aac_adtstoasc output.mp4

 


Previous page: 'mdadm' - Notes
Next page: 'perf' - Notes