Ravi Sagar | Home | Blog

ffmpeg tutorials

Table of Contents

1 Introduction

ffmpeg is a great piece of software. It is a cross platform utility to modify audio and video. It can do lot of wonderful things like editing videos, encoding them and live streaming as well. In this post I want to share whatever little I know and have been exploring.

Installing it is easy. Just check your package manager but on Arch linux you can do sudo pacman -S ffmpeg and it should install it.

2 Installation

2.1 CentOS 8

sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
sudo yum repolist
sudo dnf install ffmpeg
sudo yum-config-manager --enable powertools

3 Live streaming with ffmpeg

I recently made a video explain how to use ffmpeg to live stream from local computer to YouTube using nothing but shell scripts. Check the video here.

4 Record audio with ffmpeg

Check this link.

First check your audio devices.

arecord -l

5 Screen recording with ffmpeg

ffmpeg   -video_size 1368x768   -framerate 25   -f x11grab   -i :0.0+0,30   -f pulse   -i default   -ac 2   rec-01.mp4

6 Concatenate multiple files

6.1 Create file.txt for the concatenate to work

for f in *.mp3 ; do echo "file '${f}'" >> file.txt; done;

6.2 While concatenating multiple videos remove audio using

ffmpeg -safe 0 -f concat -i file.txt -vcodec copy -an output.MOV

6.3 Concatenate audio files

ffmpeg -safe 0 -f concat -i file.txt -acodec copy all.mp3

7 Merge video with audio and keeping the shortest duration (from video)

ffmpeg -i output.MOV -i ~/Documents/sounds_youtube/tmp/all.mp3 -map 0:v -map 1:a -filter:a "volume=0.2" -vcodec copy -shortest final.MOV

8 You can also split video.

ffmpeg -i output.MOV -ss 00:00:00 -t 00:09:00 -c copy final.MOV

9 You can also reduce file size drastically using this command.

ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4

10 Reduce the size of all the videos in a directory.

for f in *.MP4;do ffmpeg -i "${f}" -vcodec libx265 -crf 28 "small_${f}";done;

11 Recursively go inside directories and execute a command on them

find . -type f -exec echo "'{}' and '{}_small'" \;