FFmpeg Flashcards
What is sound and which are its basic Attributes?
Amplitude: loudness
Frequency: a measure of the wave’s vibrations per time unit
What is sampling?
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.
What is quantization?
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 do you convert video (mkv) to audio (mp3)
ffmpeg -i video.mkv audio.mp3
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:
ffmpeg -i audio.wav -ar 16000 -ac 1 audio_16K_mono.wav
Also, downsampling of an audio file and stereo to mono conversion can be achieved using sox in the following manner:
sox <source_file_ -r <new_sampling_rate> -c 1 <output_file>)</output_file></new_sampling_rate>
How can you see the file’s attributes using FFmpeg?
ffmpeg -i audio_16K_mono.wav
What will ffmpeg -i audio_16K_mono.wav return
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
Totriman audio file, e.g. from the 60th to the 80th second (20 seconds new duration):
ffmpeg -i audio.wav -ss 60 -t 20 audio_small.wav
What is -i for?
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.
What is -ss for?
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 do you seek in the input file?
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 do you seek in the output file?
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:
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.
faster, slower
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’):
file ‘file1.wav’
file ‘file2.wav’
file ‘file3.wav’
ffmpeg -f concat -i list_of_files_to_concat -c copy output.wav
Basic conversion:
ffmpeg -i in.mp4 out.avi
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.:
ffmpeg -i output.wav -f segment -segment_time 1 -c copy out%05d.wav
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:
ffmpeg -i stereo.wav -map_channel 0.0.1 -map_channel 0.0.0 stereo_inverted.wav
To create astereo file from two mono files, say left.wav and right.wav:
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