---+ !!Converting Files under Linux %TOC% ---++ Convert Images * Use the powerful command ==convert== <verbatim> convert file.jpg file.gif convert file.tiff file.jpg </verbatim> The command ==convert== can convert between several formats and has a lot of options, see ==man convert== * Resizing an image <verbatim> convert -resize 50% file.jpg file_small.jpg convert -resize 200x200 file.jpg file_small.jpg # ratio will be kept convert -resize 1024x768! file.jpg file_desktop.jpg # ! = force the new size </verbatim> * Rotating an image <verbatim> convert -rotate 90 file.jpg file_new.jpg </verbatim> %BR% ---++ Convert between Windows/Mac and Linux text files * Use ==dos2unix== and ==unix2dos== <verbatim> dos2unix win.txt linux.txt mac2unix mac.txt linux.txt unix2dos linux.txt win_mac.txt </verbatim> %BR% ---++ Convert text files between different character encodings * Use ==iconv== to convert a text file <verbatim> iconv --from-code=UTF-8 --to-code=ISO-8859-1 text_in_utf-8.txt > text_in_iso-8859-1.txt </verbatim> %BR% ---++ Convert PS and EPS Files There is normally more than one way to convert files. Just try out which tool produces the best results in your case. * Convert PS to PDF <verbatim> ps2pdf file.ps ps2pdf -sPAPERSIZE=a4 -dOptimize=true -dEmbedAllFonts=true file.ps pstoedit file.ps file.pdf </verbatim> * Convert EPS to PDF <verbatim> epstopdf file.eps pstoedit file.eps file.pdf </verbatim> * Convert PS to EPS <verbatim> ps2eps file.ps </verbatim> * Convert to a "better" PS <verbatim> ps2ps file.ps new.ps eps2eps file.eps new.eps ps2ps2 file.[ps|eps|pdf] new.ps # converts to PS level 2 </verbatim> * Extract text from PS <verbatim> ps2ascii file.ps file.txt </verbatim> * Convert a postscript file to png <verbatim> gs -r300 -dNOPAUSE -dUseCropBox -dBATCH -sDEVICE=pngalpha -sOutputFile=file.png file.ps # r300 = resolution of 300 dpi </verbatim> * Convert a postscript file to jpg <verbatim> gs -r300 -dNOPAUSE -dUseCropBox -dBATCH -sDEVICE=jpeg -sOutputFile=file.jpg file.ps # r300 = resolution of 300 dpi </verbatim> * Convert a transparent eps (in cmyk) to a png file <verbatim> convert -colorspace rgb file.eps file.png </verbatim> %BR% ---++ Convert GRIB into NETCDF files * Use NCL to convert. First load ncl module <verbatim> module load ncl </verbatim> * Rename your GRIB file. The name should have *.grb* as extension <verbatim> mv mygribfile mygribfile.grb </verbatim> * Convert to NETCDF <verbatim> ncl_convert2nc mygribfile.grb </verbatim> The resulting NETCDF file will be mygribfile.nc * For more information see http://www.ncl.ucar.edu/Document/Tools/ncl_convert2nc.shtml %BR% ---++ Convert PDF Files * Use ==pdftops== to convert PDF to PS <verbatim> pdftops file.pdf </verbatim> Note: ==pdf2ps== does also convert PDF to PS, but normally the result is worse. * Extract text from PDF <verbatim> pdftotext file.pdf # or use ps2ascii pdftops file.pdf ps2ascii file.ps file.txt </verbatim> * Convert a PDF file to images (one image per page) <verbatim> pdftoppm file.pdf image </verbatim> Convert page 2 (==-f 2==) to page 5 (==-l 5==) with a resoltion of 300 dpi (==-r 300==) to five PPM image files <verbatim> pdftoppm -f 2 -l 5 -r 300 file.pdf image </verbatim> * Extract images from PDF files <verbatim> pdfimages file.pdf image pdfimages -j file.pdf image # write images if possible as JPEG files </verbatim> * Open the PDF File with an application and save it in a different format. Programs that can open PDF files: <verbatim> abiword oowriter </verbatim> %BR% ---++ Manipulating PDF Files * Use ==pdfedit== to edit PDF Files <verbatim> pdfedit file.pdf </verbatim> * Joining PDF files <verbatim> pdfunite file1.pdf file2.pdf file-new.pdf pdfjoin file1.pdf file2.pdf # alternative </verbatim> * Splitting a PDF file into pages <verbatim> qpdf --split-pages file.pdf %d-out.pdf </verbatim> * Extract certain pages from a PDF. For example page 22-36 <verbatim> qpdf input.pdf --pages . 1-10 -- output.pdf pdftops input.pdf - | psselect -p22-36 | ps2pdf - output_p22-p36.pdf </verbatim> * Extract images from PDF files <verbatim> pdfimages -j file.pdf image </verbatim> * Rotating PDF file <verbatim> pdf90 file.pdf </verbatim> * Put several pages on one page: <verbatim> pdfnup --nup 2x1 file.pdf # 2 pages side by side pdfnup --nup 2x2 file.pdf # 4 pages on one page </verbatim> %BR% ---++ Convert Matlab EPS Files * Convert Matlab eps file in a pixel graphic like png, jpg: First convert the eps file into a pdf file. Afterwards convert the pdf file into a png or jpg file <verbatim> epstopdf matlab_plot.eps convert -density 100 matlab_plot.pdf matlab_plot.png </verbatim> * Choose a higher number than 100 to get a higher resolution of the image * Instead of png you can convert to matlab_plot.jpg * Convert Matlab eps file into a .emf file (Enhanced Meta File format). emf is still a vector based format and can be imported by openoffice. <verbatim> pstoedit -pta matlab_plot.eps matlab_plot.emf </verbatim> The crucial option is ==-pta==, which fixes the ugly looking font when you directly import the eps file into openofffice (==-pta== sets correct inter-letter spacing). %BR% With the above command the boundary box will be still broken (too large). If you first convert it into a pdf file it will be ok. <verbatim> epstopdf matlab_plot.eps pstoedit -pta matlab_plot.pdf matlab_plot.emf </verbatim> %BR% ---++ Convert tar files into zip files * Windows users may not be able to open tar or tar.gz files. The following commands "convert" these files to zip files <verbatim> tar xfv file.tar | zip file.zip "-@" tar xfvz file.tar.gz | zip file.zip "-@" </verbatim> %BR% ---++ Convert MS Excel and MS Word files * Convert *xls* (Excel) files to csv (comma-separated values) files: <verbatim> xls2csv -x file.xls -c file.cvs -a UTF-8 </verbatim> * Convert MS Word to plain text: <verbatim> abiword --to=txt file.doc </verbatim> * Alternatively open the file with *LibreOffice*. %BR% ---++ Create a Movie out of Images Programs * *mencoder*: Encoding from multiple input image files: http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-enc-images.html: * *convert*: create animated GIFs Create animated gif with convert * Animated gif file created from a series of png or gif files ( see also ==man convert==): <verbatim> convert -delay 30 -loop 0 *.png animated.gif convert -delay 30 -loop 0 *.gif animated.gif </verbatim> *mencoder* takes jpg or png files as imput. *Note: mencoder needs png with 8bit color depth*, use option ==-depth 8== * Convert eps to png files <verbatim> mogrify -format png -depth 8 -alpha off -density 600 -resample 150 *.eps </verbatim> * Convert jpg tp png files and keep the quality <verbatim> mogrify -format png -depth 8 -quality 100 *.jpg </verbatim> Create movies with mencoder (see also ==man mencoder==) * Create AVI movie file with MPEG4 codec (fps = frames per second): <verbatim> mencoder mf://*.jpg -mf fps=5 -ovc lavc -o output_mpeg4.avi mencoder mf://*.png -mf fps=5 -ovc lavc -o output_mpeg4.avi </verbatim> * Create AVI file with XVID codec <verbatim> mencoder mf://*.png -mf fps=5 -ovc xvid -xvidencopts fixed_quant=4 -o output_xvid.avi </verbatim> * Create AVI file with X264 codec (use 2 pass mode: pass=1 will analyze the frames, pass=2 will create the movie) <verbatim> mencoder mf://*.png -mf fps=5 -o /dev/null -ovc x264 -x264encopts pass=1:turbo:bitrate=1600:bframes=1:me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 mencoder mf://*.png -mf fps=5 -o output_x264.avi -ovc x264 -x264encopts pass=2:turbo:bitrate=1600:bframes=1:me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 </verbatim> * X264 and XVID codecs create smaller and qualitative better files than MPEG4 codec, where has X264 creates smaller files than XVID. * *Note:* For =mencoder= the file should not be too large. 1000x1000 is still fine %BR% ---++ Convert Movie/Animation Files * Convert MPEG4 movie to Quicktime (qtrle) movie <verbatim> ffmpeg -i output_mpeg4.avi -f mov -vcodec qtrle output.mov </verbatim> * Convert animated GIF into MPEG4 movie. First extract individual pictures out of the animated gif and save them as png files <verbatim> convert animation.gif animation%02d.png </verbatim> Now create out of the png files a MPEG4 movie <verbatim> mencoder mf://*.png -mf fps=5 -ovc lavc -o output_mpeg4.avi </verbatim> * Converting Flash movie <verbatim> ffmpeg -i myvideo.flv -f avi -vcodec mpeg4 myvideo_mpeg4.avi </verbatim> %BR% ---++ Convert Audio Files * Convert WAV to MP3. Set the bit rate with option ==-b== <verbatim> lame -b 320 file.wav file.mp3 </verbatim> * Convert WAV to OGG. Set quality between -1 (very low) and 10 (very high) with option ==-q==: <verbatim> oggenc -q 8 file.wav </verbatim> * Convert audio files using ==sox== <verbatim> sox file.mp3 file.ogg sox file.ogg file.mp3 </verbatim> * Convert media files using ==mplayer==. Mplayer can convert every file format, which he can play, to .wav <verbatim> mplayer -vo null -vc dummy -af resample=44100 -ao pcm:waveheader:file=output.wav input.xxx </verbatim> * Converting a bunch of files using a for loop (works in bash shell only!) <verbatim> for f in *.wav; do lame -b 320 "$f" "${f%.wav}.mp3"; done for f in *.flac; do flac -cd "$f" | lame -b 320 - "${f%.flac}.mp3"; done for f in *.ogg; do sox "$f" "${f%.ogg}.mp3"; done for f in *.ogg; do oggdec -o - "$f" | lame -b 256 - "${f%.ogg}.mp3"; done for f in *.wma ; do mplayer -vo null -vc dummy -af resample=44100 -ao pcm:waveheader "$f" && lame -b 256 audiodump.wav -o "${f%.wma}.mp3"; done; rm -f audiodump.wav </verbatim> %BR% ---++ Extract Audio from a Video File * Extract MP3 audio from MP4 video <verbatim> for f in *.mp4; do ffmpeg -i "$f" -vn -ar 44100 -ac 2 -ab 320k -f mp3 "${f%.mp4}.mp3"; done </verbatim> * Extract MP3 audio from MKV video <verbatim> for f in *.mkv; do ffmpeg -i "$f" -vn -ar 44100 -ac 2 -ab 320k -f mp3 "${f%.mkv}.mp3"; done </verbatim> <!-- * Set DENYTOPICVIEW = -->
View