Showing posts with label convert. Show all posts
Showing posts with label convert. Show all posts

Friday, 1 November 2013

Converting images (Jpeg, png, etc) to PDF on linux

Pop up a terminal.
$ sudo apt-get install imagemagick
$ convert img1 [img2...] output.pdf

If your files are already in alphabetical order, bash can automatically expand:

$ convert *.jpg output.pdf
If you want to limit the target file size, play around with -quality VALUE:
$ convert -quality 30 *.jpg output.pdf
VoilĂ !

Sunday, 29 January 2012

Converting Flac to Mp3 (or other formats)

Sometimes you need to have .mp3 files for compatibility reasons (mp3 player?). Here's an easy way to convert Flac (or any other formats readable by ffmpeg, m4a, wav, whatever else) to Mp3 on Linux (or windows using Cygwin or ffmpeg for windows... which is hard to find). First, install lame codecs and ffmpeg
ubuntu: sudo apt-get install lame ffmpeg libavcodec-extra-53 
Then cd to the directory with flac files and use find (or change ffmpeg for avconv):
find -name "*.flac" -exec ffmpeg -i {} -acodec libmp3lame -ab 128k {}.mp3 \;
Done! You now have the exact same filenames with .mp3 encoding (also adds .mp3 at the end but keeps the .flac as well).
Enjoy.
Notes:
  1. Obviously, change *.flac to whatever extension your input files are in
  2. You can also change the output codec by replacing libmp3lame to whatever codec you'd like
  3. Heck, just use man find ;)
  4. If you don't like the .flac.mp3 thing, you can rename easily (I like it since it tells me it came from a lossless source, which is likely sitting somewhere on my hard drive):
    rename 's/\.flac//' *.mp3

Alternative without ffmpeg

If you don't have ffmpeg and prefer using lame and flac directly, first install the codecs if you dont have them already.
Ubuntu: sudo apt-get install flac lame 
Arch: sudo pacman -Syu flac lame
Then, convert away!
find . -name '*.flac' -exec sh -c 'flac -cd "{}" | lame - "{}".mp3' \;
You can also do this in the current folder only with a for-loop:
for f in *.flac; do flac -cd "${f}" | lame - "${f}.mp3"; done;
Set the target bitrate depending on the quality/size you prefer with the -b option of lame:
lame -b 320 - "${f}.mp3"