Media Processing Commands
Instead of accessing some privacy-questionable websites, free and open-source command-line tools are useful in working with media files, like images, audio and video.
Image processing
The convert
command that comes with ImageMagick is a powerful image processing tool that provides several useful functionalities.
convert input_image.jpg -resize 50% output_image.jpg
- To convert a JPG image into PNG format:
convert input_image.jpg output_image.png
It's possible to convert pages of a PDF file into individual PNG images using convert
as well, albeit it requires a slightly longer command. jdhao's article clearly explains how to achieve this.
- To reduce the file sizes of image files by utilising the default encoding algorithm of
ffmpeg
without compromising the quality much:
for x in *.jpg; do ffmpeg -i "$x" "reduced-$x"; done
This command processes all images in the directory where it is executed whose filenames end with the .jpg
extension and outputs their respective version with their file sizes reduced and a reduced-
prefix added to their filenames.
The jpg
part can be replaced by any other file format of image files that need to be processed, such as png
, tiff
and so on.
Video and audio processing
FFmpeg is a popular and versatile media processing tool that enables a wide range of features, from converting formats, trimming to speeding up and slowing down videos or audios, and many other functionalities.
ffmpeg -fflags +genpts -r 15 -i raw.h264 -i input.mp4 -map 0:v -c:v copy -map 1:a -af atempo=0.5 -movflags faststart output.mp4
Here, the value 15
supplied after the -r
option means the frame rate is halved (30 / 2 = 15
), whereas atempo=0.5
means the audio speed is halved.
- To convert a FLAC file into MP3 format:
ffmpeg -i input.flac output.mp3
- To trim a video with starting and ending timestamps given (with audio cut accordingly as well):
ffmpeg -i "video.mp4" -ss 1:00 -to 2:00 -c copy "cut.mp4"
The command above generates a copy of video.mp4
, named cut.mp4
, with only the portion from the 01:00
to 02:00
position.
file '/path/to/file1.wav'
file '/path/to/file2.wav'
file '/path/to/file3.wav'
ffmpeg -f concat -safe 0 -i vid_list.txt -c copy output.wav