VIDEO, AUDIO and IMAGE EDITING in the command line :)

VIDEO EDITING WITH FFMPEG

FFMPEG is a free software project that produces libraries and programs for handling multimedia data. It can record, convert and stream digital audio and video in numerous formats. FFmpeg can be used to convert many multimedia formats to one another. It is a command line tool that is composed of a collection of free software / open source libraries. The name of the project comes from the MPEG video standards group, together with “FF” for “fast forward”.

1. Install FFMPEG

It’s cross platform. Please visit the official website and follow the steps to install in MacOS, Windows or Linux.

2. Basic FFMPEG commands

note: Execute commands in Terminal

Convert a video to any format

ffmpeg -i input.mp4 output.avi
ffmpeg -codecs
ffmpeg -formats  

Compress a video with a good quality

ffmpeg -i input.mp4 -c:v libx264 -crf 24 -preset slow output.mp4

Extract images frame by frame from a video file

Very useful for photogrammetry !

ffmpeg -i coding_robots.mp4 thumb%04d.jpg

Extract only one frame

ffmpeg -i coding_robots.mp4 -ss 00:01:07.000 -vframes 1 oneframe.jpg

Extract an image every X seconds

ffmpeg -i coding_robots.mp4 -vf fps=1 coding%04d.jpg

Inserting a Watermark

You can apply filters to whole audio or video streams or only to certain parts, use them to merge several streams into one in interesting ways, and do much more.

Next example show you how to use a logo to watermark a video. It’s the logo ( Future Learning Unit ):

ffmpeg -i coding_robots.mp4 -i logo_flu.png -filter_complex "overlay" -codec:a copy coding_marked.mp4

FFmpeg takes two inputs, the coding_robots.mp4 video file and the logo_flu.png file, and outputs them together – the second placed on top of the first – to coding_marked.mp4

The logo is in the upper-left corner. If you prefer in the lower right:

ffmpeg -i coding_robots.mp4 -i logo_flu.png -filter_complex "overlay=W-w-10:H-h-10" -codec:a copy coding_marked.mp4

W is the width of the first input (the bottom layer), and w is the width of the second input (the top layer). This means that W-w-10 will place the top overlay layer 10 pixels from the left-most edge of the bottom video layer. The same goes for H-h-10, but in the vertical axis.

If the logo is too big, you can scale too:

ffmpeg -i example.mp4 -i LM_logo.pngcoding_robots.mp4 -i logo_flu.png -filter_complex "[1:v] scale=150:-1 [ol], [0:v] [ol] overlay=W-w-10:H-h-10" -codec:a copy coding_marked.mp4

In the previous command you tell scale to make the stream 150 pixels wide and to scale its height proportionally.

IMAGE EDITING WITH IMAGEMAGICK

Imagemagick is a robust collection of tools and libraries offered under a usage license to read, write, and manipulate an image in many image formats (over 87 major formats) including popular formats like TIFF, JPEG, PNG, PDF, PhotoCD, and GIF. With ImageMagick you can create images dynamically, making it suitable for Web applications. You can also resize, rotate, sharpen, color reduce, or add special effects to an image or image sequence and save your completed work in the same or differing image format. Image processing operations are available from the command line, as well as through C, C++, Perl, or Java programming interfaces.

1. ImageMagick can do

2. Install ImageMagick

It’s cross platform. Please visit the official website and follow the steps to install in MacOS, Windows or Linux.

3. ImageMagick basic commands

Convert an image from one format to another

convert [ options ... ] input_file output_file

convert high1.jpg high1.png   ->1 file
convert *.jpg *.png -> a bath of images

Turn a group of images into a .GIF animation sequence

convert -resize 120 -delay 15 -loop 0 *.jpg animation.gif

Create thumbails from batch images

convert -thumbnail '500x500>' *.jpg thumb.jpg

Images file size

BATCH IMAGES
mogrify -path ../ImageMagick/ -define jpeg:extent=2MB

1 IMAGE
mogrify high2.jpg -define jpeg:extent=2MB high2.jpg

Resize image dimension and change format

convert *.jpg -resize 1024 .png

convert original_file.jpg -resize "160x160!" resized_file.jpg (ignore aspect ratio)

Rotate an image

convert high3.jpg -rotate -90 rotated_ccw.jpg