Saturday, December 26, 2020

ffmpeg aac -> mp3 conversion

It seems that it isn't easy to handle aac/m4a files in sox anymore. Online help threads suggest using ffmpeg to convert it to mp3 instead:

 ffmpeg -i input.m4a -c:a libmp3lame -q:a 8 output.mp3

Reference link: https://askubuntu.com/questions/1200430/how-to-convert-m4a-audio-files-to-mp3-use-command-line

Wednesday, January 9, 2019

watch

Have you ever wanted to run some command periodically, usually to wait for some change in the result (like waiting for some ACL to be propagated, a price value to change, etc)?

Seek no more! Do you know the "watch" unix command?
watch -n 60 <command>
This will run <command> every 60 seconds! And you can inspect the output every time it does.

Its usage is quite simple. The help output is:

Usage:
 watch [options] command

Options:
  -b, --beep             beep if command has a non-zero exit
  -c, --color            interpret ANSI color and style sequences
  -d, --differences[=<permanent>]
                         highlight changes between updates
  -e, --errexit          exit if command has a non-zero exit
  -g, --chgexit          exit when output from command changes
  -n, --interval <secs>  seconds to wait between updates
  -p, --precise          attempt run command in precise intervals
  -t, --no-title         turn off header
  -x, --exec             pass command to exec instead of "sh -c"

 -h, --help     display this help and exit
 -v, --version  output version information and exit

Useful command to know!

Saturday, December 22, 2018

Noise removal (sox) and fixing video/audio merge (ffmpeg)

When you have some audio and it's noisy, remove the noise with this:

# Create background noise profile from mp3
/usr/bin/sox noise.mp3 -n noiseprof noise.prof

# Remove noise from mp3 using profile
/usr/bin/sox input.mp3 output.mp3 noisered noise.prof 0.21
Referral:
https://unix.stackexchange.com/questions/425853/how-to-clear-background-noises-with-sox

_____________________________________________________________________________
When you're merging audio and video with ffmpeg, and your video ends up silent, remember to map the video and audio streams from the two files explicitly:
ffmpeg -y -i merged.mp4 -i combined.mp3 -c:a aac -map 0:v -map 1:a output.mp4
Referral:
https://unix.stackexchange.com/questions/425853/how-to-clear-background-noises-with-sox

Tuesday, October 2, 2018

Thursday, October 5, 2017

Trim a video

...with ffmpeg!

ffmpeg -i movie.mp4 -ss 00:00:03 -t 8 -async 1 cut.mp4
Easy peasy. Trims a video from second 3 for a length of 8 seconds. The -async 1 is optional... maybe it speeds it up with parallel processing?

Source link. Thanks!

Saturday, March 5, 2016

Ghostscript JPG -> PDF

I'm not sure why I never posted this, but this is very useful when making documents from photos.

HOW TO CONVERT A JPG TO A PDF FILE:

gs \
 -sDEVICE=pdfwrite \
 -o outfile.pdf \
  /usr/local/share/ghostscript/8.71/lib/viewjpeg.ps \
 -c \(infile.jpg\) viewJPEG
Notice the \(...\) around the filename. They're important!

Also, the "/usr/local/share/ghostscript/8.71/lib/viewjpeg.ps" path varies, depending on the current installed version of ghostscript. Run the following to find your correct version:

find /usr/local/share/ghostscript -name viewjpeg.ps

Ref: http://stackoverflow.com/questions/4283245/using-ghostscript-to-convert-jpeg-to-pdf