> For the complete documentation index, see [llms.txt](https://wilcode-net.gitbook.io/all-social-media-video-downloader-apify/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wilcode-net.gitbook.io/all-social-media-video-downloader-apify/merge-audio-and-video-for-instagram-facebook.md).

# Merge Audio & Video for Instagram/Facebook

### Overview <a href="#api-request" id="api-request"></a>

The difference between **Get Direct Link** and **Download and Merge** is that the video will be downloaded, audio and video will be merged and then the share link will be created

Proxy is required to get the list of download links.

{% hint style="success" %}
By default the video will have no sound. This method is only for those who want to download videos from Instagram/Facebook with audio available.
{% endhint %}

{% hint style="success" %}
The **mergeAV** field currently only works on: Facebook, Instagram

\
In the future, if social networks or other platforms separate audio and video, updates will be supported by a field called **mergeAV**, which is used to combine audio and video.
{% endhint %}

{% hint style="danger" %}
Because the video is downloaded, it will consume more proxy usage capacity
{% endhint %}

### API Request <a href="#api-request" id="api-request"></a>

**Endpoint:** [https://api.apify.com/v2/acts/wilcode\~all-social-media-video-downloader/runs?token=\<YOUR\_API\_TOKEN>](https://api.apify.com/v2/acts/wilcode~all-social-media-video-downloader/runs?token=<YOUR_API_TOKEN>)

**Method:** POST

**Headers:**

```json
{
  "Content-Type": "application/json"
}
```

**Request Body:**

```json
{
  "url": "https://www.facebook.com/reel/1231817508603093",
  "proxySettings": {
    "useApifyProxy": true,
    "apifyProxyGroups": ["RESIDENTIAL"],
    "apifyProxyCountry": "CA"
  },
  "mergeAV": true
}
```

{% hint style="success" %}
If you are integrating Actor as download API, you can always set **mergeAV** value. When the url supports **mergeAV** it will automatically merge Audio and video, when url not support it will not be affected

This will help the API get all the urls and when the url is supported it will be automatically merged
{% endhint %}

### cURL

```sh
curl -X POST "https://api.apify.com/v2/acts/wilcode~all-social-media-video-downloader/runs?token=<YOUR_API_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://www.facebook.com/reel/1231817508603093",
    "proxySettings": {
      "useApifyProxy": true,
      "apifyProxyGroups": ["RESIDENTIAL"],
      "apifyProxyCountry": "CA"
    },
    "mergeAV": true
  }'
```

### JSON Results <a href="#json-results" id="json-results"></a>

```json
{
    "title": "Video title",
    "uploader": "Channel Name",
    "channel": "Channel Name",
    "upload_date": "20240706",
    "duration": 100,
    "description": "",
    "like_count": 478,
    "comment_count": 19,
    "thumbnail": "image thumbnail url",
    "formats": [
      {
        "resolution": "720x1080",
        "url": "url download"
      },
      {
        "resolution": "1080x1920",
        "url": "url download"
      },
      {
        "resolution": "audio only",
        "url": "url download"
      },
    ],
    "download": [
      {
        "resolution": 720,
        "url": "https://api.apify.com/v2/key-value-stores/amhvXQKACHs124/records/downloaded_video_1732199392399.mp4"
      }
    ]
}
```

{% hint style="info" %}
The list of download links and resolutions will be listed in the formats attribute.
{% endhint %}

{% hint style="success" %}
When the body has the **mergeAV** field, the result will have an additional **download** field

In the download field there will be the **url** and **resolution**
{% endhint %}

{% hint style="info" %}
The download **url** is the file saved in your **Storage** (**Apify**), this link will be automatically generated
{% endhint %}

{% hint style="danger" %}
This link will automatically expire and the file will be deleted from your **Storage** in 7 days.
{% endhint %}

{% hint style="danger" %}
**Why does the video sometimes crash while downloading?**

* Due to unstable proxy, the video download fails while downloading
* You need to change proxy or change proxy country (if using **Apify** Proxy)
  {% endhint %}

### Other language examples

#### Fetch in JavaScript

```javascript
const fetch = require('node-fetch');

const endpoint = 'https://api.apify.com/v2/acts/wilcode~all-social-media-video-downloader/runs?token=<YOUR_API_TOKEN>';

const requestBody = {
  url: 'https://www.facebook.com/reel/1231817508603093',
  proxySettings: {
    useApifyProxy: true,
    apifyProxyGroups: ['RESIDENTIAL'],
    apifyProxyCountry: 'CA'
  },
  "mergeAV": true
};

fetch(endpoint, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(requestBody)
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));
```

#### Python

```python
import requests

endpoint = 'https://api.apify.com/v2/acts/wilcode~all-social-media-video-downloader/runs?token=<YOUR_API_TOKEN>'

headers = {
    'Content-Type': 'application/json'
}

body = {
    'url': 'https://www.facebook.com/reel/1231817508603093',
    'proxySettings': {
        'useApifyProxy': True,
        'apifyProxyGroups': ['RESIDENTIAL'],
        'apifyProxyCountry': 'CA'
    },
    'mergeAV': true
}

response = requests.post(endpoint, headers=headers, json=body)
print(response.json())
```

#### C\#

```csharp
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static async Task Main(string[] args)
    {
        string endpoint = "https://api.apify.com/v2/acts/wilcode~all-social-media-video-downloader/runs?token=<YOUR_API_TOKEN>";

        // Define request body
        var requestBody = new
        {
            url = "https://www.facebook.com/reel/1231817508603093",
            proxySettings = new
            {
                useApifyProxy = true,
                apifyProxyGroups = new[] { "RESIDENTIAL" },
                apifyProxyCountry = "CA"
            },
            mergeAV = true
        };

        // Convert request body to JSON
        string jsonBody = System.Text.Json.JsonSerializer.Serialize(requestBody);

        using (HttpClient client = new HttpClient())
        {
            // Set headers
            client.DefaultRequestHeaders.Add("Content-Type", "application/json");

            // Send POST request
            HttpResponseMessage response = await client.PostAsync(
                endpoint,
                new StringContent(jsonBody, Encoding.UTF8, "application/json")
            );

            // Get response content
            string responseContent = await response.Content.ReadAsStringAsync();

            // Print response
            Console.WriteLine("Response:");
            Console.WriteLine(responseContent);
        }
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wilcode-net.gitbook.io/all-social-media-video-downloader-apify/merge-audio-and-video-for-instagram-facebook.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
