FFmpeg Flashcards

1
Q

What is sound and which are its basic Attributes?

A

Amplitude: loudness
Frequency: a measure of the wave’s vibrations per time unit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is sampling?

A

Sampling is used to convert the time-varying continuous signal x(t) to a discrete sequence of real numbers x(n). The interval between two successive discrete samples is the sampling period (Ts). We use the sampling frequency (fs = 1/Ts) as the attribute that describes the sampling process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is quantization?

A

Quantization is the process of replacing each real number, x(n), of the sequence of samples with an approximation from a finite set of discrete values. In other words, quantization is the process of reducing the infinite number precision of an audio sample to a finite precision as defined by a particular number of bits.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you convert video (mkv) to audio (mp3)

A

ffmpeg -i video.mkv audio.mp3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Fordownsamplingto 16KHz, converting stereo (2 channels)to mono (1 channel)and converting MP3to WAV (uncompressed audio samples), one needs to use the -ar (audio rate) -ac (audio channel) properties:

A

ffmpeg -i audio.wav -ar 16000 -ac 1 audio_16K_mono.wav

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Also, downsampling of an audio file and stereo to mono conversion can be achieved using sox in the following manner:

A

sox <source_file_ -r <new_sampling_rate> -c 1 <output_file>)</output_file></new_sampling_rate>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can you see the file’s attributes using FFmpeg?

A

ffmpeg -i audio_16K_mono.wav

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What will ffmpeg -i audio_16K_mono.wav return

A

Input #0, wav, from ‘audio_16K_mono.wav’:
Metadata:
encoder : Lavf57.71.100
Duration: 00:03:10.29, bitrate: 256 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 Hz,
mono, s16, 256 kb/s

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Totriman audio file, e.g. from the 60th to the 80th second (20 seconds new duration):

A

ffmpeg -i audio.wav -ss 60 -t 20 audio_small.wav

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is -i for?

A

In FFmpeg, the -i flag is used to specify the input file. It tells FFmpeg which file you want to process, whether you’re converting, streaming, or performing any other operation on the media file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is -ss for?

A

In FFmpeg, the -ss flag is used to specify the start time for the input or output file. This allows you to seek to a particular point in the media file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you seek in the input file?

A

If you want to start processing the input file from a specific time, use -ss before the -i flag. For example, to start from 1 minute and 30 seconds into the video:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you seek in the output file?

A

If you want to start writing the output file from a specific time without affecting the input file processing, place -ss after the -i flag:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The placement of -ss can affect the precision and performance of seeking. Using it before the -i flag performs a________ but less accurate seek, while using it after the -i flag is_________but more accurate.

A

faster, slower

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Toconcatenatetwo or more audio files one can use the “ffmpeg -f concat” command. Suppose you want to concatenate all files f1.wav, f2.wav and f3.wav to a large file called output.wav. What you need to do is create a text file of the following format (say named ‘list_of_files_to_concat’):

A

file ‘file1.wav’
file ‘file2.wav’
file ‘file3.wav’

ffmpeg -f concat -i list_of_files_to_concat -c copy output.wav

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Basic conversion:

A

ffmpeg -i in.mp4 out.avi

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

To break an audio file into successive chunks (segments) of the (same) specified duration can be done with the “ffmpeg -f segment” option. For example, the following command will break output.wav into 1-second, non-overlapping segments named out00000.wav, out00001.wav, etc.:

A

ffmpeg -i output.wav -f segment -segment_time 1 -c copy out%05d.wav

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

With regards to channel handling, apart from simple mono to stereo conversion (or stereo to mono) through the -ac property, one may want to switch stereo channels (right to left). The way to achieve this is through the ffmpeg map_channel property:

A

ffmpeg -i stereo.wav -map_channel 0.0.1 -map_channel 0.0.0 stereo_inverted.wav

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

To create astereo file from two mono files, say left.wav and right.wav:

A

ffmpeg -i left.wav -i right.wav -filter_complex “[0:a][1:a]join=inputs=2:channel_layout=stereo[a]” -map “[a]” mix_channels.wav

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

On the opposite direction, to split a stereo file into two mono (one for each channel):

A

ffmpeg -i stereo.wav -map_channel 0.0.0 left.wav -map_channel 0.0.1 right.wav

21
Q

Map_channel can also be used to mute a channel from a stereo signal, e.g. (below the left channel is muted):

A

ffmpeg -i stereo.wav -map_channel -1 -map_channel 0.0.1 muted.wav

22
Q

Volumeadaptation can also be achieved through ffmpeg, e.g.

A

ffmpeg -i data/music_44100.wav -filter:a “volume=0.5” data/music_44100_volume_50.wav
ffmpeg -i data/music_44100.wav -filter:a “volume=2.0” data/music_44100_volume_200.wav

23
Q

Volumechange can be achieved withsoxas well in the following way:

A

sox -v 0.5 data/music_44100.wav data/music_44100_volume_50_sox.wav
sox -v 2.0 data/music_44100.wav data/music_44100_volume_200_sox.wav

24
Q

Remux an Mkv file into MP4

A

ffmpeg -i in.mkv -c:v copy -c:a copy out.mp4

25
Q

Use the crf (Constant Rate Factor) parameter to control the output quality. The lower crf, the higher the quality (range: 0-51). The default value is 23, and visually lossless compression corresponds to -crf 18. Use the preset parameter to control the speed of the compression process

A

ffmpeg -i in.mp4 -preset slower -crf 18 out.mp4

26
Q

Trimming without re-encoding:

A

ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4

27
Q

-__ specifies the start time, e.g. 00:01:23.000 or 83 (in seconds)

A

ss

28
Q

-__specifies the duration of the clip (same format).

A

t

29
Q

-__copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won’t harm the quality and make the command run within seconds.

A

c

30
Q

Trimming with re-encoding:

A

If you leave out the -c copy option, ffmpeg will automatically re-encode the output video and audio according to the format you chose.

ffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4

31
Q

Mux video and audio from another video. To copy the video from in0.mp4 and audio from in1.mp4:

A

ffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4

32
Q

With -c copy the streams will be stream copied, not ______________, so there will be no quality loss.

A

re-encoded

33
Q

The ___________ option will cause the output duration to match the duration of the shortest input stream.

A

-shortest

34
Q

Concat demuxer:

A

file ‘in1.mp4’
file ‘in2.mp4’
file ‘in3.mp4’
file ‘in4.mp4’

ffmpeg -f concat -i list.txt -c copy out.mp4

35
Q

Delay audio/video by 3.84 seconds:

A

video: ffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4
audio: ffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4

36
Q

Burn subtitles

Use the libass library (make sure your ffmpeg install has the library in the configuration –enable-libass).

A

First convert the subtitles to .ass format:

ffmpeg -i sub.srt sub.ass
Then add them using a video filter:

ffmpeg -i in.mp4 -vf ass=sub.ass out.mp4

37
Q

Extract the frames from a video
To extract all frames from between 1 and 5 seconds, and also between 11 and 15 seconds:

A

ffmpeg -i in.mp4 -vf select=’between(t,1,5)+between(t,11,15)’ -vsync 0 out%d.png

38
Q

To extract one frame per second only:

A

ffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png

39
Q

Rotate 90 clockwise:

A

ffmpeg -i in.mov -vf “transpose=1” out.mov
For the transpose parameter you can pass:

0 = 90CounterCLockwise and Vertical Flip (default)
1 = 90Clockwise
2 = 90CounterClockwise
3 = 90Clockwise and Vertical Flip
Use -vf “transpose=2,transpose=2” for 180 degrees.

40
Q

Download “Transport Stream” video streams

A
  1. Locate the playlist file, e.g. using Chrome > F12 > Network > Filter: m3u8
  2. Download and concatenate the video fragments:
    ffmpeg -i “path_to_playlist.m3u8” -c copy -bsf:a aac_adtstoasc out.mp4
    If you get a “Protocol ‘https not on whitelist ‘file,crypto’!” error, add the protocol_whitelist option:

ffmpeg -protocol_whitelist “file,http,https,tcp,tls” -i “path_to_playlist.m3u8” -c copy -bsf:a aac_adtstoasc out.mp4

41
Q

Mute some of the audio

To replace the first 90 seconds of audio with silence:

A

ffmpeg -i in.mp4 -vcodec copy -af “volume=enable=’lte(t,90)’:volume=0” out.mp4

41
Q

To replace all audio between 1’20” and 1’30” with silence:

A

ffmpeg -i in.mp4 -vcodec copy -af “volume=enable=’between(t,80,90)’:volume=0” out.mp4

42
Q

What is Deinterlace?

A

Deinterlacing is the process of converting interlaced video into a non-interlaced or progressive form

42
Q

Deinterlacing using “yet another deinterlacing filter”.

A

ffmpeg -i in.mp4 -vf yadif out.mp4

43
Q

Create a video slideshow from images

A

Parameters: -r marks the image framerate (inverse time of each image); -vf fps=25 marks the true framerate of the output.

ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4

44
Q

Extract images from a video

A

Extract all frames: ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner

Extract a frame each second: ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner

Extract only one frame: ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg

45
Q

Display the frame number on each frame

A

ffmpeg -i in.mov -vf “drawtext=fontfile=arial.ttf: text=%{n}: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000099: fontsize=72” -y out.mov

46
Q

Metadata: Change the title

A

ffmpeg -i in.mp4 -map_metadata -1 -metadata title=”My Title” -c:v copy -c:a copy out.mp4

47
Q
A