# CremyX Media Tools (`andrew_babo/cremyx-media-tools`) Actor

ffmpeg / ffprobe / yt-dlp / aria2c as a service: probe metadata, extract 16 kHz mono WAV, build 480p proxies, rough cuts, and YouTube downloads. Chainable through key-value store refs.

- **URL**: https://apify.com/andrew\_babo/cremyx-media-tools.md
- **Developed by:** [Andrew Babo](https://apify.com/andrew_babo) (community)
- **Categories:** Videos, Developer tools
- **Stats:** 1,066 total users, 793 monthly users, 96.5% runs succeeded, 0 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/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — 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

## cremyx-media-tools

ffmpeg / ffprobe / yt-dlp / aria2c chạy trên Apify. Thay cho việc bắt user cài
những tool này trên máy.

- Actor ID: `9BJXSNONxKn3OGsyW` (`cremyx-media-tools`)
- Base image: `apify/actor-node:22` (Alpine)
- Build hiện tại: `0.4` — proxy single-pass, remux copy-first, audio16k range

### Input

```jsonc
{
  "op": "audio16k",                     // probe | plan_shards | audio16k | proxy | cut | ytdlp | ingest | remux | capabilities
  "source": "https://…/video.mp4",      // hoặc "kv:<storeId>/<key>"
  "options": { },                       // xem bảng dưới
  // audio16k: { format: "mp3", bitrate: "32k", start: 120, dur: 60 }
  "output": { "signed_upload_url": null },
  "cleanup": "on_success",              // on_success | always | off
  "callback": { "url": "https://…", "secret_header": { "name": "x-secret", "value": "…" } }
}
```

### Các `op`

| `op` | Kết quả | `options` |
|---|---|---|
| `probe` | Không sinh file, chỉ `meta` (duration, w/h, fps, codec, channels…) | — |
| `audio16k` | `audio.wav` — PCM 16 kHz mono, đầu vào chuẩn cho ASR/diarize; hỗ trợ mp3/opus để giảm dung lượng shard | `sample_rate` (mặc định 16000), `format` (`wav` mặc định, `mp3`, `opus`), `bitrate` (mp3 mặc định `32k`), `start`/`dur` hoặc `start_sec`/`duration_sec` |
| `proxy` | `proxy.mp4` — bản 480p nhẹ để phân tích (vision, xem trước) | `height` (480), `fps` (25), `crf` (28), `preset` (ultrafast) |
| `cut` | `cut_01.mp4`, `cut_02.mp4`… (tối đa 200 đoạn) | `segments: [{ start_sec, end_sec, name }]`, `reencode` (false = cắt copy stream, nhanh nhưng bám keyframe), `crf` |
| `ytdlp` | `download.mp4` tải bằng yt-dlp + aria2c 16 luồng | `format` (mặc định `bv*+ba/b`), `aria2c` (true) |
| `ingest` | tải + chuẩn hoá thành MP4 h264/aac faststart | tuỳ chọn ytdlp + `max_height`, `crf`, `preset` |
| `remux` | đưa container/codec về MP4, copy trước rồi mới transcode phần không tương thích | `copy_only`, `max_height`, `transcode_audio` |
| `capabilities` | trả ops/features/vCPU, không cần source | — |

`op=ytdlp` **không** hỗ trợ cookie / nội dung cần đăng nhập — cố ý, để không
phải gửi thông tin đăng nhập lên cloud.

### Output

```jsonc
{
  "status": "success",
  "op": "audio16k",
  "artifacts": [
    { "name": "audio", "kv_key": "audio.wav", "url": "https://api.apify.com/v2/key-value-stores/…/records/audio.wav",
      "bytes": 183244, "stored_in": "key_value_store", "content_type": "audio/wav" }
  ],
  "meta": { "duration_sec": 5.7, "sample_rate": 16000, "channels": 1, "source": { /* probe */ } },
  "timings": { "work_ms": 900, "publish_ms": 120, "total_ms": 1100 },
  "cleanup": "on_success",
  "errors": null
}
```

Kết quả nằm ở 3 nơi: dòng dataset, record `RESULT` trong key-value store của
run, và webhook `callback` (nếu có).

### Ví dụ

Tách audio cho ASR:

```bash
curl -X POST "https://api.apify.com/v2/acts/cremyx-media-tools/runs?token=$APIFY_TOKEN" \
  -H 'content-type: application/json' \
  -d '{"op":"audio16k","source":"https://example.com/interview.mp4"}'
```

Cắt 3 đoạn, không re-encode:

```jsonc
{
  "op": "cut",
  "source": "https://example.com/long.mp4",
  "options": {
    "segments": [
      { "start_sec": 12.5, "end_sec": 41.0, "name": "hook" },
      { "start_sec": 130,  "end_sec": 168,  "name": "point_1" },
      { "start_sec": 402,  "end_sec": 447,  "name": "cta" }
    ],
    "reencode": true
  }
}
```

`reencode: true` cho cắt đúng frame (dùng khi ghép lại); `false` nhanh hơn
nhiều nhưng điểm cắt nhảy về keyframe gần nhất.

### Nối tiếp actor khác

`artifacts[].kv_key` + `storeId` của run tạo thành ref `kv:<storeId>/<key>`. Các op `ingest`, `remux` và `capabilities` có trong build 0.4; client nên gọi `capabilities` trước khi dùng contract mới.
Đưa thẳng ref đó vào `source` của `cremyx-asr` / `cremyx-diarize` /
`cremyx-vision` — file không phải tải về máy rồi upload lại.

### Dung lượng

- Mọi file trung gian chỉ nằm trong key-value store **mặc định của run**
  (unnamed) → Apify tự xoá theo hạn giữ dữ liệu của gói.
- `cleanup: "always"` + `output.signed_upload_url` → file đi thẳng về storage
  của bạn, Apify chỉ còn vài KB JSON.
- Dọn hàng loạt: `node scripts/purge-old-stores.mjs --days 3 --apply`.

### Shard plan (fan-out song song — v2)

Video dài → KHÔNG để 1 run xử lý cả file. Client gọi `op: "plan_shards"` trước:

```json
{ "op": "plan_shards", "source": "https://.../video.mp4", "options": { "shard_sec": 120 } }
```

Trả về `meta.shards: [{index, start_sec, duration_sec, is_last}]`. Client chạy **1 run mỗi shard** (song song) trên actor ASR/diarize/vision với `options.start_sec`/`duration_sec` tương ứng, rồi tự merge kết quả (timestamp đã được offset về timeline gốc; bỏ các phần tử có `_overlap: true` khi nối).

### ytdlp — YouTube bot check (v2)

Khi YouTube trả `Sign in to confirm you're not a bot`, actor trả lỗi `bot_check:` với hướng khắc phục. Truyền một hoặc cả hai:

```json
{ "op": "ytdlp", "source": "https://youtube.com/watch?v=...",
  "options": {
    "cookies": "<nội dung file cookies.txt định dạng Netscape, export từ trình duyệt đã đăng nhập>",
    "apify_proxy": { "groups": ["RESIDENTIAL"], "country": "US" },
    "player_client": "android,web_safari"
  } }
```

- `cookies` (nội dung file) hoặc `cookies_url` (HTTPS tới file cookies.txt) — không bao giờ log.
- `apify_proxy` dùng Apify Proxy (khuyến nghị RESIDENTIAL), hoặc `proxy` = URL proxy tự có.
- `player_client`: danh sách client thử lần lượt (mặc định `android,web_safari`).

### Chaining qua URL công khai

Qua proxy xoay tài khoản Apify, `kv:` từ run khác sẽ lỗi quyền truy cập (mỗi tài khoản chỉ đọc store của chính nó). Hãy truyền `artifacts[].url` (URL công khai) của run trước vào `source` của run sau.

### artifacts\[].upload\_status

Mỗi phần tử trong `artifacts` kèm `upload_status`:

| Giá trị | Ý nghĩa |
|---|---|
| `uploaded` | Đã ghi xong lên KV store / signed URL đích |
| `skipped` | Bỏ qua vì đã tồn tại (idempotent) hoặc `output` không yêu cầu publish |
| `failed` | Ghi thất bại — xem `artifacts[].error` |

Dùng field này để phân biệt "actor chạy xong nhưng chưa có file" với "file đã sẵn sàng tải".

# Actor input Schema

## `op` (type: `string`):

probe = ffprobe metadata. plan\_shards = shard plan, returned both as meta.shards and top-level shards \[{index,startSec,endSec,durationSec}]. audio16k = mono speech audio (wav|mp3|opus) with optional range. proxy = fast 480p analysis proxy. cut = trim segments. ytdlp = raw download by page URL. resolve = print the DIRECT media URLs (yt-dlp -g) with no download at all (options.want=audio|video|both, options.height, options.audio\_format, options.video\_format); ASR/vision actors range-read those URLs. ingest = download + guarantee h264/aac faststart mp4. remux = any container/codec to mp4 (stream-copy compatible streams, transcode only incompatible streams). capabilities = report ops/features/vcpus of this build and does not need source. audio\_shard = resolve + range-read + encode ONE audio window straight from a PAGE URL in a single run (options.start\_sec/duration\_sec/format/bitrate) — same exit IP as the resolve, so signed URLs stay valid and a client can fan out N shards without hosting the full track. video\_window = resolve + range-read + cut ONE full-res video window straight from a PAGE URL in a single run (options.start\_sec/duration\_sec/height/crf/preset/with\_audio); the output timeline starts at 0 and meta.offset\_sec says where it came from, so a client never waits for a hosted copy of the whole video. audio\_full = download the WHOLE audio track ONCE and host it as mono 16 kHz mp3/wav/opus (options.format/bitrate/sample\_rate) so every ASR shard range-reads that KV URL instead of hitting YouTube per shard.

## `source` (type: `string`):

https:// URL, or kv:<storeId>/<key> to read a record produced by an earlier run. For op=ytdlp this is the page URL. Required for every op except capabilities.

## `options` (type: `object`):

Per-op options. plan\_shards: shard\_sec (default 120), overlap\_sec (default 1). audio16k: sample\_rate, format (wav|mp3|opus; default wav), bitrate (e.g. "64k"), start/dur (or start\_sec/duration\_sec) to cut one window. proxy: height, fps, crf, audio (default true — op=asd needs it). cut: segments\[{start\_sec,end\_sec,name}], reencode, crf. ytdlp: format, aria2c, cookies (Netscape file content), cookies\_url, proxy (proxy URL), apify\_proxy {groups:\["RESIDENTIAL"],country}, player\_client (default "android,web\_safari"). ingest/remux: max\_height, crf, preset, audio\_kbps, copy\_only, transcode\_audio, kv\_key. Failures always return {ok:false, reason: OOM\_LIMIT|TIMEOUT|UPSTREAM\_BLOCKED|BAD\_INPUT|INTERNAL} — never SUCCEEDED with zero items.

## `output` (type: `object`):

{ signed\_upload\_url } to PUT a single artifact straight to your own storage — keeps heavy files off Apify entirely.

## `cleanup` (type: `string`):

on\_success = keep only the result artifacts in the run's key-value store (Apify expires them). always = also drop the artifact from the store after it was pushed to signed\_upload\_url. off = keep everything for debugging.

## `callback` (type: `object`):

{ url, secret\_header: { name, value } } — POSTed with the result JSON when the run finishes.

## Actor input object example

```json
{
  "op": "probe",
  "cleanup": "on_success"
}
```

# Actor output Schema

## `results` (type: `string`):

Full run result JSON: status, op, artifacts \[{name, kv\_key, url, bytes}], meta, timings, errors.

## `resultRecord` (type: `string`):

The same result JSON stored as the RESULT record of the default key-value store.

# 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("andrew_babo/cremyx-media-tools").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("andrew_babo/cremyx-media-tools").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).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 andrew_babo/cremyx-media-tools --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,andrew_babo/cremyx-media-tools"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/9BJXSNONxKn3OGsyW/builds/eP0hhEEy4wuK1vrla/openapi.json
