Video Conversion API
Convert video between MP4, MOV, AVI, MKV, and WEBM. Video encodes can take minutes, so this is an async, submit-then-poll endpoint rather than one blocking request — same ffmpeg engine behind TransConvert's website converter.
curl -X POST \ .../api/v1/convert-async.php \ -H "Authorization: Bearer ..." \ -F "category=video" \ -F "target=MP4" \ -F "file=@clip.mov" # { "job_id": "job_...", "status": "queued" }
動画や音声の変換には数分かかることがあり、1つの同期リクエストを開いたままにするには長すぎます — そのため上記のエンドポイントとは異なり、送信してからポーリングする方式を使います。ファイルを送信するとすぐにjob_idが返されるので、完了するまでそのステータスをポーリングしてください。
ジョブを送信する
https://transconvert.com/api/v1/convert-async.php
| Field | Description |
|---|---|
Authorization | Required. "Bearer tc_live_...". |
category | Set to "video". |
target | Required. Output format code: "MP4", "MOV", "AVI", "MKV", or "WEBM". |
file | Required. The video file. |
curl -X POST \ https://transconvert.com/api/v1/convert-async.php \ -H "Authorization: Bearer tc_live_your_key_here" \ -F "category=video" \ -F "target=MP4" \ -F "file=@clip.mov" \ -o output.mp4
<?php $ch = curl_init('https://transconvert.com/api/v1/convert-async.php'); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ['Authorization: Bearer tc_live_your_key_here'], CURLOPT_POSTFIELDS => [ 'category' => 'video', 'target' => 'MP4', 'file' => new CURLFile('clip.mov'), ], ]); $response = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($status === 200) { file_put_contents('output.mp4', $response); } else { $error = json_decode($response, true); echo $error['error']['message']; }
const form = new FormData(); form.append('category', 'video'); form.append('target', 'MP4'); form.append('file', new Blob([fs.readFileSync('clip.mov')]), 'clip.mov'); const res = await fetch('https://transconvert.com/api/v1/convert-async.php', { method: 'POST', headers: { Authorization: 'Bearer tc_live_your_key_here' }, body: form, }); if (res.ok) { fs.writeFileSync('output.mp4', Buffer.from(await res.arrayBuffer())); } else { const { error } = await res.json(); console.error(error.message); }
import requests with open('clip.mov', 'rb') as f: response = requests.post( 'https://transconvert.com/api/v1/convert-async.php', headers={'Authorization': 'Bearer tc_live_your_key_here'}, data={'category': 'video', 'target': 'MP4'}, files={'file': f}, ) if response.status_code == 200: with open('output.mp4', 'wb') as out: out.write(response.content) else: print(response.json()['error']['message'])
# gem install multipart-post require 'net/http' require 'net/http/post/multipart' url = URI('https://transconvert.com/api/v1/convert-async.php') File.open('clip.mov') do |file| req = Net::HTTP::Post::Multipart.new url, 'category' => 'video', 'target' => 'MP4', 'file' => UploadIO.new(file, 'application/octet-stream', 'clip.mov') req['Authorization'] = 'Bearer tc_live_your_key_here' res = Net::HTTP.start(url.host, url.port, use_ssl: true) do |http| http.request(req) end if res.code == '200' File.write('output.mp4', res.body) else puts JSON.parse(res.body)['error']['message'] end end
// Gradle: implementation("com.squareup.okhttp3:okhttp:4.+") OkHttpClient client = new OkHttpClient(); RequestBody body = new MultipartBody.Builder() .setType(MultipartBody.FORM) .addFormDataPart("category", "video") .addFormDataPart("target", "MP4") .addFormDataPart("file", "clip.mov", RequestBody.create(new File("clip.mov"), MediaType.parse("application/octet-stream"))) .build(); Request request = new Request.Builder() .url("https://transconvert.com/api/v1/convert-async.php") .header("Authorization", "Bearer tc_live_your_key_here") .post(body) .build(); try (Response response = client.newCall(request).execute()) { if (response.isSuccessful()) { Files.write(Paths.get("output.mp4"), response.body().bytes()); } else { System.err.println(response.body().string()); } }
ステータスをポーリングする
取得したjob_idを使って、数秒ごとにこのエンドポイントをポーリングしてください。「status」はqueued、processing、completed、failedのいずれかです。
https://transconvert.com/api/v1/job-status.php?job_id=job_...
curl -H "Authorization: Bearer tc_live_your_key_here" \ https://transconvert.com/api/v1/job-status.php?job_id=job_...
結果をダウンロードする
ステータスが「completed」になると、レスポンスにdownload_urlが含まれます — これは同じステータスURLに&download=1を付加したものです。このURLをリクエストすると、このページの他のエンドポイントと同じヘッダーで変換済みファイルの生データがストリーミングされます。結果はダウンロードされた時点で削除されるか、一度もダウンロードされなかった場合は短い保持期間の後に自動的に削除されます。
scheduleジョブの結果はダウンロード後すぐに削除されるか、一度もダウンロードされなかった場合は短い保持期間の後に自動的に削除されます — 早めにダウンロードしてください。
エラー
失敗時は必ず、プログラムで分岐に使える "code" と、人が読める "message" を含むJSONエラーが返されます。エラーによっては追加のフィールドを含むこともあります(例えば quota_exceeded には "limit" と "used" が含まれます)。
| Status & code | When it happens |
|---|---|
401 missing_key | Authorizationヘッダーが送信されませんでした。 |
401 invalid_key | キーが存在しないか、失効しています。 |
403 account_suspended | このキーを所有するアカウントは停止されています。 |
403 plan_required | アカウントがFreeプランです — API利用にはBasic、Lite、Pro、Teamのいずれかのプランが必要です。 |
400 invalid_category | "category" が "image" または "document" ではありませんでした。 |
400 invalid_target | 「target」がそのカテゴリでサポートされている出力形式ではありません。 |
400 no_file | ファイルが送信されなかったか、アップロードに失敗しました — フィールド名は "file" にする必要があります。 |
413 file_too_large | ファイルがプランの最大アップロードサイズを超えています。 |
429 quota_exceeded | プランの月間変換分の割り当てを使い切りました。翌月の初めにリセットされます。 |
429 concurrency_limit | このアカウントで同時に実行中の変換が多すぎます(ウェブサイトと共有されています) — いずれかが完了するのを待ってから再試行してください。 |
404 job_not_found | このアカウントには、そのIDのジョブが存在しません(他のアカウントのjob_idを指定した場合も同じエラーが返され、存在の有無が判別されることはありません)。 |
410 result_gone | ジョブは完了しましたが、結果はすでに削除されています(結果はダウンロード後すぐに、または一度もダウンロードされなかった場合は短い保持期間の後に自動的に削除されます)。 |
400/415/422/500/503 conversion_failed | ファイル自体を変換できませんでした — 理由は "message" に記載されています。ステータスコードは理由によって異なります: 400/415/422 は、何度再試行してもそのファイルやtargetでは成功しないことを意味します。500/503 はサーバー側の問題であり、特に503は短い間隔での再試行を試す価値があります。 |
Supported formats
MP4, MOV, AVI, MKV, WEBM