Monday, April 25, 2022

another sample - short vid (24 seconds)

Note: TIME CALCULATOR, TEXT ANIMATOR (fade-in/out).

This post is how I manipulated a short vid, which is easy. But if a video is, say, 70 mins long, maybe I only want to keep the first 55 minutes of one of these...

$ ffmpeg -i foo.mp4 -t 55:00 -c copy output.mp4

Alternatively, perhaps I have a 4 hour and 20 minute video, from which I want to keep the final 20 minutes...

$ ffmpeg -ss 4:00:00 -i foo.mp4 -c copy part5.mp4

example

Got a couple minutes of funny video when slowed down to half speed. The audio needed to be gained up some, that was its only flaw.

Plan: cut it down to 30 while convert to MP4, slow audio to half speed, split audio to clean and gain. Recombine. Observe closely and cut down to 24. Add fade-in, fade out. Upload and laugh.

1. cut down to 30 and convert to MP4

Trivial to convert containers -- do it when cutting.

$ ffmpeg -i original.mkv -t 00:30 -c copy short.mp4

2. slow audio and video

Halve both the audio and video speeds, as seen in the video beneath the command.

$ ffmpeg -y -i short.mp4 -filter_complex "[0:v]setpts=2.0*PTS[v];[0:a]atempo=0.5[a]" -map "[v]" -map "[a]" halfspeed.mp4

half-speed example (3:28) The FFMPEG guy, 2021. Does audio, video, then both audio and video. Reveals filter complex mapping.

3. split audio and video

Separation was necessary in this case b/c the audio was a little dirty. I needed to work on it independently.

$ ffmpeg -i halfspeed.mp4 -vn -ar 44100 -ac 2 audio.wav
$ ffmpeg -i halfspeed.mp4 -c copy -an video.mp4

4. recombine audio and video

I force the bitrate -- ffmpeg's default is too low. I like 3M for sports, 2M for interview or person just talking.

$ ffmpeg -i video.mp4 -i audio.wav -b:v 3M combined.mp4

5. review and cut to 24 secs

Watch in slow motion to obtain a cut time, in this case 24 seconds. Then a repeat of #1 (except no container change).

$ ffmpeg -i combined.mp4 -t 00:24 -c copy short24.mp4

6. fade-in and fade-out (1 second)

There are several ways to do this. The fade filter can be used by frame, or by seconds. So if I want to use the frame number, I need to find the FPS and take that time the number of seconds to the effect. I use "st" for seconds and "s" for the frame. This one uses seconds.

$ ffmpeg -i short24.mp4 -vf fade=in:st=0:d=1,fade=out:st=23:d=1 -b:v 3M faded24.mp4

fade-in fade-out example (3:42) The FFMPEG guy, 2021. Does fade-in(frames), fade-out (seconds), and then both (frames)

7. upload to YT

I've had good luck with....

  • 30 FPS
  • MP4
  • 1920x1080 (FHD/2K) or 1280x720 (WXGA/HD)
  • 3M or 2M b:v
  • h264 high (c:v libx264)
  • aac audio

audio note: if using a WAV as an input, ffmpeg defaults the audio to AAC, 124Kb. Change the bitrate with b:a 192k, and the encoder to MP3 with c:a libmp3lame. I usually upload as with AAC as YouTube does some converting that "seems" to make MP3 uploads slightly less crisp than AAC uploads, not sure.

Basic $ ffmpeg/ffprobe -i command to get info on a media file cannot be grepped to find, say, various libs. It's annnoying but ffmpeg/ffprobe sends to stderr not stdout. Of course error can't be can't be piped. Error must be rerouted. Gotta use 2>&1. Eg, to verify libmp3lame...

$ ffmpeg -i foo.mp4 2>&1 | grep mp3

...and if there's any result from that, it's in there somewhere.

No comments: