# Video & Audio Media Converter (`moving_beacon-owner1/my-actor-71`) Actor

Transform your audio and video files effortlessly! With the power of FFmpeg and yt-dlp, you can seamlessly convert between various formats to suit your needs. Whether you're fine-tuning your media collection or sharing your favourite content, this tool makes it simple and efficient!

- **URL**: https://apify.com/moving\_beacon-owner1/my-actor-71.md
- **Developed by:** [Jamshaid Arif](https://apify.com/moving_beacon-owner1) (community)
- **Categories:** Other, Developer tools, Automation
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, NaN bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-usage

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## 🎥 Video & Audio Media Converter 

All-in-one **serverless media converter** running on [Apify](https://apify.com). Converts video and audio files between formats using FFmpeg and yt-dlp.

### 🛠️ Tools

| ## | Tool | Description |
|---|------|-------------|
| 1 | **MP4 → MP3** | Extract audio track from MP4 video |
| 2 | **MKV → MP4** | Remux (fast copy) or re-encode MKV to MP4 |
| 3 | **Video → GIF** | Create animated GIF with palette optimization |
| 4 | **Audio Bitrate** | Re-encode audio at different bitrate / format |
| 5 | **YouTube → MP3** | Download YouTube audio via yt-dlp |

### ⚡ Quick Start

#### Via Apify Console

1. Go to the Actor page on Apify
2. Select a **Tool** from the dropdown
3. Paste the **Input File URL** (direct link to your media file)
4. Tweak options (bitrate, FPS, format, etc.)
5. Click **Start** — the output file URL appears in the dataset

#### Via API

```bash
curl -X POST "https://api.apify.com/v2/acts/<YOUR_ACTOR_ID>/runs?token=<YOUR_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{
    "tool": "mp4_to_mp3",
    "input_file_url": "https://example.com/video.mp4",
    "audio_bitrate": "256k"
  }'
````

#### YouTube Download Example

```json
{
    "tool": "youtube_to_mp3",
    "youtube_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
    "audio_bitrate": "320k",
    "audio_output_format": "mp3"
}
```

### 📥 Input Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `tool` | enum | `mp4_to_mp3` | Which converter to use |
| `input_file_url` | string | — | Direct URL to the media file |
| `youtube_url` | string | — | YouTube URL (tool 5 only) |
| `audio_bitrate` | enum | `192k` | Target bitrate: 64k–320k |
| `audio_output_format` | enum | `mp3` | Output format: mp3, aac, ogg, flac |
| `mkv_codec_mode` | enum | `copy` | Copy (fast) or re-encode (H.264) |
| `encoding_preset` | enum | `medium` | FFmpeg preset for re-encoding |
| `gif_fps` | int | `15` | GIF frame rate |
| `gif_width` | int | `480` | GIF width in pixels |
| `gif_start_time` | float | `0` | Start time in seconds |
| `gif_duration` | float | `5` | GIF duration in seconds |

### 📤 Output

Results are pushed to the **default dataset** with this schema:

```json
{
    "tool": "mp4_to_mp3",
    "status": "success",
    "input_file": "video.mp4",
    "output_file": "video.mp3",
    "output_url": "https://api.apify.com/v2/key-value-stores/.../records/video.mp3",
    "file_size_mb": 3.42,
    "duration_seconds": 1.87,
    "message": "Audio extracted at 192k."
}
```

The converted file is stored in the Actor's **Key-Value Store** and accessible via `output_url`.

### 🏗️ Project Structure

```
apify-media-converter/
├── .actor/
│   ├── actor.json          ## Actor metadata & config
│   └── input_schema.json   ## Input UI schema
├── src/
│   ├── __init__.py
│   └── main.py             ## Actor logic (all 5 tools)
├── Dockerfile              ## FFmpeg + yt-dlp + Python
├── requirements.txt
└── README.md
```

### ⚠️ Stream Validation

The Actor checks for missing streams **before** attempting conversion:

- MP4→MP3: verifies audio stream exists
- MKV→MP4: verifies video stream exists
- Video→GIF: verifies video stream exists
- Audio Bitrate: verifies audio stream exists

If a stream is missing, the Actor returns a clear error instead of a cryptic FFmpeg crash.

# Actor input Schema

## `tool` (type: `string`):

Which conversion to perform.

## `input_file_url` (type: `string`):

Direct URL to the input media file. Required for all tools except YouTube→MP3.

## `youtube_url` (type: `string`):

YouTube video URL. Only used with the YouTube→MP3 tool.

## `audio_bitrate` (type: `string`):

Target audio bitrate for MP3 extraction, audio re-encoding, or YouTube download.

## `audio_output_format` (type: `string`):

Output format for audio bitrate converter and YouTube downloader.

## `mkv_codec_mode` (type: `string`):

Copy streams (fast, no quality loss) or re-encode to H.264+AAC.

## `encoding_preset` (type: `string`):

FFmpeg encoding preset (only used when re-encoding MKV→MP4).

## `gif_fps` (type: `string`):

Frame rate for GIF output. Lower = smaller file.

## `gif_width` (type: `string`):

Output GIF width in pixels. Height is auto-scaled.

## `gif_start_time` (type: `number`):

Start position in the video for GIF extraction.

## `gif_duration` (type: `number`):

Duration of the GIF clip.

## Actor input object example

```json
{
  "tool": "mp4_to_mp3",
  "audio_bitrate": "192k",
  "audio_output_format": "mp3",
  "mkv_codec_mode": "copy",
  "encoding_preset": "medium",
  "gif_fps": "15",
  "gif_width": "480",
  "gif_start_time": 0,
  "gif_duration": 5
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("moving_beacon-owner1/my-actor-71").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("moving_beacon-owner1/my-actor-71").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call moving_beacon-owner1/my-actor-71 --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=moving_beacon-owner1/my-actor-71",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Video & Audio Media Converter",
        "description": "Transform your audio and video files effortlessly! With the power of FFmpeg and yt-dlp, you can seamlessly convert between various formats to suit your needs. Whether you're fine-tuning your media collection or sharing your favourite content, this tool makes it simple and efficient!",
        "version": "0.0",
        "x-build-id": "zOS2vlqmojqSS9VwH"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/moving_beacon-owner1~my-actor-71/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-moving_beacon-owner1-my-actor-71",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/moving_beacon-owner1~my-actor-71/runs": {
            "post": {
                "operationId": "runs-sync-moving_beacon-owner1-my-actor-71",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/moving_beacon-owner1~my-actor-71/run-sync": {
            "post": {
                "operationId": "run-sync-moving_beacon-owner1-my-actor-71",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "tool"
                ],
                "properties": {
                    "tool": {
                        "title": "Conversion Tool",
                        "enum": [
                            "mp4_to_mp3",
                            "mkv_to_mp4",
                            "video_to_gif",
                            "audio_bitrate",
                            "youtube_to_mp3"
                        ],
                        "type": "string",
                        "description": "Which conversion to perform.",
                        "default": "mp4_to_mp3"
                    },
                    "input_file_url": {
                        "title": "Input File URL",
                        "type": "string",
                        "description": "Direct URL to the input media file. Required for all tools except YouTube→MP3."
                    },
                    "youtube_url": {
                        "title": "YouTube URL",
                        "type": "string",
                        "description": "YouTube video URL. Only used with the YouTube→MP3 tool."
                    },
                    "audio_bitrate": {
                        "title": "Audio Bitrate",
                        "enum": [
                            "64k",
                            "128k",
                            "192k",
                            "256k",
                            "320k"
                        ],
                        "type": "string",
                        "description": "Target audio bitrate for MP3 extraction, audio re-encoding, or YouTube download.",
                        "default": "192k"
                    },
                    "audio_output_format": {
                        "title": "Audio Output Format",
                        "enum": [
                            "mp3",
                            "aac",
                            "ogg",
                            "flac"
                        ],
                        "type": "string",
                        "description": "Output format for audio bitrate converter and YouTube downloader.",
                        "default": "mp3"
                    },
                    "mkv_codec_mode": {
                        "title": "MKV→MP4 Codec Mode",
                        "enum": [
                            "copy",
                            "reencode"
                        ],
                        "type": "string",
                        "description": "Copy streams (fast, no quality loss) or re-encode to H.264+AAC.",
                        "default": "copy"
                    },
                    "encoding_preset": {
                        "title": "Encoding Preset",
                        "enum": [
                            "ultrafast",
                            "fast",
                            "medium",
                            "slow"
                        ],
                        "type": "string",
                        "description": "FFmpeg encoding preset (only used when re-encoding MKV→MP4).",
                        "default": "medium"
                    },
                    "gif_fps": {
                        "title": "GIF Frames Per Second",
                        "enum": [
                            "10",
                            "15",
                            "20",
                            "25"
                        ],
                        "type": "string",
                        "description": "Frame rate for GIF output. Lower = smaller file.",
                        "default": "15"
                    },
                    "gif_width": {
                        "title": "GIF Width (px)",
                        "enum": [
                            "320",
                            "480",
                            "640",
                            "800"
                        ],
                        "type": "string",
                        "description": "Output GIF width in pixels. Height is auto-scaled.",
                        "default": "480"
                    },
                    "gif_start_time": {
                        "title": "GIF Start Time (seconds)",
                        "minimum": 0,
                        "type": "number",
                        "description": "Start position in the video for GIF extraction.",
                        "default": 0
                    },
                    "gif_duration": {
                        "title": "GIF Duration (seconds)",
                        "minimum": 0.5,
                        "maximum": 60,
                        "type": "number",
                        "description": "Duration of the GIF clip.",
                        "default": 5
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
