UP | HOME
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 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.

3 Record audio with ffmpeg

Check this link.

First check your audio devices.

arecord -l

4 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

5 Concatenate multiple files

5.1 Create file.txt for the concatenate to work

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

5.2 While concatenating multiple videos remove audio using

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

5.3 Concatenate audio files

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

6 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

7 You can also split video.

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

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

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

9 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;