How to download Facebook videos
Introduction
Sometimes, I need to download videos from Facebook posts. There are some solutions available like browser extensions or websites overloaded with ads, but often they stop working after some time or even further, don’t allow for downloading videos from the private groups.
Because of that, I decided to dig into Facebook’s page source and prepare a remedy for my issue. For sure it can automated, but it’s good enough for me at this moment.
The tutorial is focused on desktop users and requires some technical knowledge, but I will try to explain it step by step so don’t be discouraged - you follow it anyway. 🚀
Getting video and audio files
Facebook splits videos into two files - video and audio and sends them to the user in smaller packages. Fortunately, their method is based on requesting specific bytes from one file, it’s similar to the HTTP range requests. So our mission is only to find those two files on the website.
The best approach for me to do it is to open the Facebook website, which contains only the video that I wish to download. To do it, simply click on the publication date of the post. The links should have the following structure:
https://www.facebook.com/groups/{group_id}/posts/${post_id}
Next, open Devtools in your browser (F12), go to the network tab, filter the requests to the Fetch/XHR
type and search for scontent
. The requests which are incoming from scontent
domain are blobs stored on the CDN.
If your requests tab is empty, try to play the video for a while, especially from the fragment which is not fetched yet. In the requests tab, you will find many requests to the one blob (it’s video) and one to the audio file. Click on them, go to the Headers subtab and find Requests URL
. Copy it and remove the bytestart
and byteend
query parameters. Open them in a new tab and download them. In Chrome, you can play the video and audio beforehand, so double-check if those files are those you desired.
Huh… The hardest part is behind us. 😅 Now, we have to blend two files together.
Using FFmpeg to merge video and audio
To achieve it, we will use FFmpeg, a free command-line tool for non-commercial usage.
I will skip the installation process, it depends on your operating system, please follow the official ffmpeg website.
Open your download directory and execute the following command:
ffmpeg -i video.mp4 -i audio.mp4 -c:v copy -c:a aac output.mp4
…and that’s it 😁 - the output.mp4
file includes both audio and video.
Parameters explanation:
-i
input file-c:v copy
specifies decoder/encode, for the video stream (v
) we indicate just to copy the stream-c:a aac
same as above, but this time for the audio stream (a
) and we use aac codec