FFmpeg - Using it for your Video Production

 

FFmpeg is a command line driven program for processing videos. A major attraction for me is to be able to take the snippets of video I may produce on trips and stitch them together, remove bad stretches, trim, help the audio, convert the format for YouTube HD or other formats. FFmpeg will also work with images and audio files. My PowerShot videos automatically arrive in stereo so no need to worry about the channels command.

Installation

Good webpage describing how to install FFmpeg
and here's where to download the latest version (static is what you want) although I've already installed FFmpeg onto my laptop.
Installing on Win10 (from 2021)

General Sources

A good YouTube (12:48, from 2015) and advanced filters1

Command Lines to Accomplish Goals (general format)

* Trim first, then process with the time consuming complex filtering.
* To speed it up, use input seeking i.e. use -ss xx:xx:xx.xx before specifying input file, then doesn't waste time processing stuff to be thrown out anyway but then can only use "-t duration" and cannot use absolute time for endpoints. If all you're doing at this stage is just cutting, and not doing the complex processing like below, then it's just easier to use output seeking and specify absolute times. Then you don't have to do the math of calculating durations on your calculator first.

Get info on your video. It'll give you an error message because it's expecting an output file but ignore. The info you want is still given.
>ffmpeg -i infile

simple convert .avi to .mp4
>ffmpeg -i infile.avi -crf 18 outfile.mp4

Insuring best video quality if you don't mind bigger file size, include the switch -crf 18 for mp4 files

Trimming Your Video: First, you can play the video with your proposed trimming before actually trimming...
>ffplay -i infile -ss 00:01:05 -t 00:00:30    -crf 18                       This will start playing at 0h 01m 05s in, and duration 30sec. "-ss" means "seek start"
>ffplay -i infile -ss 00:01:05 -to 00:02:30   -crf 18                       This will start playing at 0h 01m 05s in, and play to absolute 2:30 time mark

To do the trimming for real, use this. For short clips the quality may not be compromised, but for longer clips I find I have to include -crf 18 or the quality of the video will degrade and the size of the file will be small. For example, just trimming off 30s of a 4 minute video changed the size from 900 Meg to 38 Meg, and the video quality of my asteroid event was unacceptable.
>ffmpeg -i infile -ss xx:xx:xx.xx -to yy:yy:yy.yy -crf 18 outfil       will trim off beginning and keep only until yy:yy:yy.yy absolute time mark

Concatenation of string of videos (at 16:19 in YouTube) it's tricky with mp4. Simplest is below. Try and see what happens. I tried it with a series of ~30sec videos and with video'ing myself while I talked, and I saw no failure of lip syncing as some complain about on the web.
>ffmpeg -f concat -i list.txt -crf 18 outfile

Adding a separate audio file to a video file
>ffmpeg -i sound.wav -i original_video.avi final_video.mpg

On Video Quality and other switches for MP4 files; notes from Kirk B
The -q option will change the quality for other codecs, but not for .mp4 (h.264) encoding.
For mp4, crf is used, see https://trac.ffmpeg.org/wiki/Encode/H.264
Not all options were necessary, but I want to preserve the frame rate and aspect ratio as much as possible. You may not care so much about that for occultations, but I also use ffmpeg to convert other material like home movies.  In the case of Arecibo, it was difficult to see, so I changed the brightness and contrast, but I don't usually need to do that.

The postings in the IOTA group about GUI video editors like Handbrake and VirtualDub are worth looking into, they're easier to use than ffmpeg and would probably be good enough for your needs.  I haven't tried them yet, I just use ffmpeg so I get exactly the results I want and it works on Mac. My command line:

ffmpeg  -ss 01:44 -i 20210609_4337_Arecibo_Bender.avi -vf "yadif=1,scale=1280x960,pad=1920:1080:320:60,eq=brightness=0.5:contrast=2" -preset slow -crf 18 -pix_fmt yuv420p -an -t 21  out.mp4

and what it means.....

-ss 01:44         seek 1 min 44 sec into the file

-i 20210609_4337_Arecibo_Bender.avi          my input file

-vf              video filters follow, enclosed in quotes and separated by commas.

yadif=1      This de-interlaces the interlaced video from the camcorder, producing one frame for every field, converting the 60 field/sec to 60 frames/sec. Probably not important for 2x or higher watec integrations, but it preserves the original appearance of the fractional time stamps.

scale=1280x960

YouTube only supports 60fps for vertical resolutions of 720 or greater. The source video is 480, but I want to scale by an integer multiple, so the scanlines don't get merged.  So I multiply 2*480=960.  To preserve the 4:3 aspect ratio, I do 1280x960.

pad=1920:1080:320:60                    Standard hi-def TV is 1920x1080, so I use the pad options to center the 1280x960 frame in it.

eq=brightness=0.5:contrast=2        Adjust brightness and contrast.  This makes the sky noisy, but for Arecibo, the star is easier to see

-preset slow -crf 18        Adjust quality, see link above.  Preset slow gives better compression but slow converison, -crf specifies quality. Smaller is larger files, better quality. 18 is supposedly visually lossless, but 20 or even higher is probably good enough. Even the default compression, with no quality options, is usually fine, but I wanted to minimize noise for this video.

-pix_fmt yuv420p           Specifies the color encoding.  Camcorder DV is type yuv411. VLC will play it, but other video players like Mac Quicktime won't, so I use yuv420 for better compatibility.

-an                                 Removes audio track.  I didn't like my narration in this video.

out.mp4                         Output file in mp4 format

Filtering

Adjust volume of the audio: example raises volume by 60%. Any decimal number will work. You can include this in a convert file type command as well, as above.
>ffmpeg -i inputfile -filter:a "volume=1.6" outputfile

Convert single-channel audio to both channels. Below takes left channel and mirrors it to the right channel too.
>ffmpeg -i infile -filter:a "channelmap=0-0|0-1" output file

Cropping the video images and this is good too

Scaling size of video (h= -1 says do proportionally after you specify just one of the dimensions). Scaling doesn't remove content, it just makes it all bigger or smaller.
resizing a video can be done this way too: ffmpeg -i input.avi -vf scale=320x240 output.avi

Sharpening a blurry video or vice versa. Saturation does like photoshop for colors; 1.0 is normal.
>ffmpeg -i infile -filter "unsharp" outfile                        ! will do a standard basic sharpening. But can adjust...
>ffmpeg -i infile -vf "eq=saturation=1.3, eq=unsharp=la=3"  outfile             !does the same as the basic sharpening. but making 3 higher makes sharper. "a" is amplitude, and will blur if negative

Adjusting intensity contrast and brightness and color saturation

Adjusting color balance: see beginning at 7:40 here

Converting an audio file to a different format
ffmpeg -i input_sound.avi -vn -ar 44100 -ac 2 -ab 192k -f mp3 output_sound.mp3

Adding a leading static image (image.jpg) or trailing image to your video. First, create a video of your static image... Then concat that as usual to front or back of your video. My PowerShot videos come out 1280x720 and 25 fps. For your .avi occultation videos, you should use output size 1280x960 since that 960 is 2x 480 and 480 is the natural resolution of the .avi original. You don't want to mash across natural scan lines. (more here)

ffmpeg -loop 1 -i image.jpg -pix_fmt yuv420p -t 5 -vf scale=1280x960  static.mp4 (this didn't quite work for me. The audio and video weren't well sync'd)

Another way which is more intuitive. Described in 5 min YouTube, and also here
* In Win10, bring up "VideoEditor", which is pre-packaged in Win10
* Create a new project and name for your merged video
* Add a jpg you can create in Photoshop for a title (or other jpg, or other short video title), and add your main (or series of videos) video
* Drag them down to the storyboard in the proper order
* In upper left, click "finish video" and click export, using 1080 quality (best).