3.3 KiB
FFmpeg
FFmpeg is a free and open-source suite consisting of many audio and video tools and libraries.
Usage
Convert from format to another
The following line is an example for a conversion of a video and audio capable
format - in this case .webm - to an audio format - in this case .flac:
ffmpeg -i audio.webm -c:a flac audio.flac.
For audio to audio conversion the following example is used:
ffmpeg -i audio.m4a -f flac audio.flac.
Concatenate multiple video files with matching audio-tracks
First you need to create a text file files.txt that includes a line for every
video you want to concatenate in the form of:
file '<path to the video>'
You have to give the absolute path towards the files. Make sure the videos are in correct order. To concatenate these video files you can run:
ffmpeg -f concat -safe 0 -i files.txt -map 0 -c copy output.mp4
If the video files you want to concatenate are not mp4 files change the above command accordingly.
Two-Pass Encoding
Two pass encoding - as described in the official FFmpeg documentation
- uses two passes.
The first pass analyzes the input data and outputs a descriptor file.
The second pass actually encodes the data.
The following is an example where the file
inputis encoded withlibx264tomp4video withlibfdk_aacaudio. The video bitrate is555kand the audio bitrate is128k.
ffmpeg -y -i input -c:v libx264 -b:v 555k -pass 1 -c:a libfdk_aac -b:a 128k -f mp4 /dev/null && \
ffmpeg -i input -c:v libx264 -b:v 555k -pass 2 -c:a libfdk_aac -b:a 128k output.mp4
Encode Audio/Video to Target Size
For the encoding of a file to a target size the target bitrate of the output
video is needed.
An explanation of this was given by
aergistal on Stack Overflow.
This can easily be done with the calculation bitrate = target size / duration
in Bits/Second.
Afterwards the encoding can be done by using Two-Pass Encoding as explained in
a previous section.
Note that the bitrate for videos is split amongst a bitrate for video and a
bitrate for audio.
The target bitrate has to be equal to or greater than the sum of both video
bitrate and audio bitrate.
Create a Virtual Camera Using an IP Video Stream
The following section will create a virtual webcam from an IP video stream like
the one provided by IP Webcam Android app.
For this a free V4L2 video device will be needed.
To information on how to create it navigate to the V4L2 entry and its sections on
permanent and
temporary creation of V4L2 video devices.
The following command will create a video device using the pixel format planar YUV 4:2:0.
In this example it is assumed that the IP link is http://192.168.178.66:8080/videofeed and the
V4L2 video device that is not used but exists is /dev/video8.
If any of those differs on a given system adjustments are needed.
ffmpeg -i http://192.168.178.66:8080/videofeed -f v4l2 -pix_fmt yuv420p /dev/video8