Mute or Edit Specified Sections of a Video or Audio File Using ffmpeg

Post Reply
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#1

Install the ffmpeg


  1. sudo snap install ffmpeg  # version 4.3.1, or
  2. sudo apt-get  install ffmpeg



ffmpeg is a Hyper fast Audio and Video encoder. Its general usage format is:

  1. ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...


For example, to mute two video sections between 5-15 seconds and 20-25 seconds we run the command:

  1. ffmpeg -i Original_video.mp4 -af "volume=enable='between(t,5, 15)':volume=0, volume=enable='between(t,20,25)':volume=0" Output_video.mp4


-af is the audio filter which works by specifying multiple volume filters that are enabled/disabled at the specified duration of time.

  1. volume=enable='between(t,5,15)':volume=0


means use a volume filter that is enabled between 5 and 15 seconds to set the volume in a specified portion to 0. In our case, the input file is the Original_video.mp4 and the output file with specified sections muted is Output_video.mp4.
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#2

Extracting part of a video with a command line using ffmpeg

Say we want to cut out part of a video starting at 00:00:20 out of the original file with 5 minutes and 25 seconds (00:05:25) length, and ending at 00:04:59 without re-encoding. The following command will do the trick:

  1. ffmpeg -ss 00:00:20 -i original_file.webm -t 00:04:59 -vcodec copy -acodec copy new_file.webm


Re-encoding requires replacing a copy with audio and video codecs. For a list of available codecs issue ffmpeg -formats -E to find out. However, you'll have to replace original_file.webm and new_file.webm with actual file names and their extensions. In our case the input file is original_file.webm and the resulting truncated file is new_file.webm.

To do the same with encoding, issue the command:

  1. ffmpeg -i original_file.webm -ss 00:00:20 -t 00:04:59 -async 1 -strict -2 new_file.mp4


Using mencoder

You can achieve similar results using mencoder by issuing the command below (as for ffmpeg, if you want to re-encode the video you have to replace copy with audio and video codecs, for a list of available audio codecs issue mencoder -oac help, for a list of available video codecs issue mencoder -ovc help).

  1. mencoder -ss 00:00:20 -endpos 00:04:59 -oac copy -ovc copy original_file.webm -o new_file.webm


Check here for more discussion.
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#3

Another useful ffmpeg usage is conversion between formats, for example converting the .webm file to .mp4:

  1. ffmpeg -i input_filename.webm output_filename.mp4

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#4

Cut a video (.MP4) from 0 seconds to 10 minutes and 30 seconds:

  1. ffmpeg -ss 00:00:00 -i original_video.mp4 -t 00:10:30 -vcodec copy -acodec copy new_video.mp4

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#5

Usually the associated packages such as vlc can be similarly installed:

  1. sudo snap install vlc
  2. sudo  apt-get install vlc

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
Post Reply

Return to “Linux and Unix Based Operating Systems”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests