Skip to content

Instantly share code, notes, and snippets.

@isaactzab
Last active June 10, 2022 14:30
Show Gist options
  • Save isaactzab/7a259747dbc9c351777e to your computer and use it in GitHub Desktop.
Save isaactzab/7a259747dbc9c351777e to your computer and use it in GitHub Desktop.
FFmpeg on ubuntu
#!/bin/sh
# Convert all mp4 files in this folder to mp4 version 2 tv compatible.
mkdir -p converted
for file in *.mp4; do ffmpeg -i "${file%.mp4}".mp4 -c copy -map 0 -brand mp42 ./converted/"${file%.mp4}".mp4; done

FFmpeg Tricks

Repeat/loop Input Video

The -loop option is specific to the image file demuxer and gif muxer, so it can't be used for typical video files, but you can use the concat demuxer.

Concat demuxer

Make a text file. Contents of an example text file to repeat 4 times.

$ cat list.txt
file 'input.mp4'
file 'input.mp4'
file 'input.mp4'
file 'input.mp4'

Then run ffmpeg:

ffmpeg -f concat -i list.txt -c copy output.mp4 ####For Linux users This example is the same as above but you don't have to manually make list.txt:

$ for i in {1..4}; do printf "file '%s'\n" input.mp4 >> list.txt; done
$ ffmpeg -f concat -i list.txt -c copy output.mp4

With most commonly-used modern shells, you can even avoid the creation of the list.txt file entirely. For example, with bash:

ffmpeg -f concat -i <(for i in {1..4}; do printf "file '%s'\n" input.mp4; done) -c copy output.mp4 More info concat demuxer documentation How to concatenate (join, merge) media files

Merge audio to video

ffmpeg -i video.mp4 -i audio.mp3 -map 0:v -map 1:a -shortest -c copy -y output.mp4

#Install FFmpeg on Ubuntu 15.10, Using Apt-Get (PPA) Update: FFMPEG RETURNS TO THE OFFICIAL UBUNTU REPOSITORIES WITH UBUNTU 15.04 VIVID VERVET https://launchpad.net/ubuntu/+source/ffmpeg

Install FFmpeg on Ubuntu, using apt-get (PPA) on Ubuntu 15.10, Ubuntu 14.04 and Derivatives. FFmpeg is a command line tool to convert multimedia files on Ubuntu.

FFmpeg is the leading multimedia framework, able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created. It supports the most obscure ancient formats up to the cutting edge. No matter if they were designed by some standards committee, the community or a corporation. It is also highly portable: FFmpeg compiles, runs, and passes our testing infrastructure FATE across Linux, Mac OS X, Microsoft Windows, the BSDs, Solaris, etc. under a wide variety of build environments, machine architectures, and configurations.

It contains libavcodec, libavutil, libavformat, libavfilter, libavdevice, libswscale and libswresample which can be used by applications. As well as ffmpeg, ffserver, ffplay and ffprobe which can be used by end users for transcoding, streaming and playing. ###FFmpeg Tools

  • ffmpeg – A command line tool to convert multimedia files between formats.
  • ffserver – A multimedia streaming server for live broadcasts.
  • ffplay – A simple media player based on SDL and the FFmpeg libraries.
  • ffprobe – A simple multimedia stream analyzer. ##Install FFmpeg on Ubuntu FFmpeg 2.8.2 is the latest version of FFmpeg Multimedia Framework. It can be installed on Ubuntu 15.10, Ubuntu 15.04, Ubuntu 14.04, Ubuntu 14.10 and Ubuntu derivatives. Run the following commands to install FFmpeg 2.8:
$ sudo apt-add-repository ppa:samrog131/ppa
$ sudo apt-get update
$ sudo apt-get install FFmpeg-real
$ sudo ln -sf /opt/FFmpeg/bin/FFmpeg /usr/bin/FFmpeg

If the above command doesn’t work, try installing FFmpeg on Ubuntu, using the following commands:

$ sudo apt-add-repository ppa:mc3man/trusty-media
$ sudo apt-get update
$ sudo apt-get install ffmpeg

##Uninstall FFmpeg from Ubuntu Run the following commands to uninstall and remove FFmpeg 2.8 from Ubuntu Systems:

$ sudo apt-get remove FFmpeg
$ sudo rm /opt/FFmpeg/bin/FFmpeg /usr/bin/FFmpeg

##Using FFmpeg on Ubuntu Please note that FFmpeg is a command line tool. If you like to use GUI, try installing WinFF, GUI for FFmpeg (see below). If you wish to get more help, run help or info command:

##Syntax to use FFmpeg on Ubuntu

ffmpeg [[infile options][-i infile]]… {[outfile options] outfile}…

To convert a video file, simply use the following format

$ ffmpeg -i input.mp4 output.avi For example, if you want to convert mp4 file named “MTV-Gulabi” to “MTV.avi”, run the following command: $ ffmpeg -i MTV-Gulabi.mp4 MTV.avi ##Installing WinFF – GUI for FFmpeg WinFF is a GUI for FFmpeg. Run the following commands to install WinFF on Ubuntu:

$ sudo add-apt-repository ppa:paul-climbing/ppa
$ sudo apt-get update
$ sudo apt-get install winff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment