downloaderjavascript246
Flonnect Video to HLS / M3U8 Converter Engine
Converter video (MP4/MKV/WebM/URL) menjadi HLS stream (.m3u8 playlist, .ts segment chunks) dan file ZIP bundle ala Flonnect HLS Converter.
Vamz Spectre15 Okt 2026278 baris kode
Jalankan via Terminal / CLI:
# 1. Download file script
curl -sL "https://code.vamxapi.my.id/snippet/raw/flonnect-hls-converter" -o flonnect-hls-converter.js
# 2. Jalankan script
node flonnect-hls-converter.js
Dependencies npm yang Dibutuhkan:
npm install child_process, fs, path, os (membutuhkan ffmpeg, ffprobe, zip)Panduan Penggunaan:
curl -sL "https://code.vamxapi.my.id/snippet/raw/flonnect-hls-converter" -o flonnect-hls-converter.js && node flonnect-hls-converter.js "<video_path_or_url>"
flonnect-hls-converter.js(278 lines)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/**
* ========================================================
* Name: Flonnect Video to HLS / M3U8 Converter Engine [CommonJS]
* Target: https://flonnect.com/media-tools/hls-converter
*
* Cara Download:
* curl -sL "https://code.vamxapi.my.id/snippet/raw/flonnect-hls-converter" -o flonnect-hls-converter.js
*
* Cara Eksekusi:
* node flonnect-hls-converter.js "/path/to/video.mp4"
* node flonnect-hls-converter.js "https://example.com/video.mp4"
*
* Author: Vamz Spectre
* Source: https://vamxapi.my.id
* ========================================================
*/
const fs = require('fs');
const path = require('path');
const os = require('os');
const { execFileSync } = require('child_process');
function formatBytes(bytes) {
if (!bytes || bytes <= 0) return '0 B';
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
function probeVideo(filePath) {
try {
const raw = execFileSync(
'ffprobe',
[
'-v', 'error',
'-show_entries', 'format=duration,size,bit_rate:stream=width,height,codec_name,codec_type',
'-of', 'json',
filePath
],
{ encoding: 'utf8' }
);
const parsed = JSON.parse(raw);
const streams = parsed.streams || [];
const videoStream = streams.find((s) => s.codec_type === 'video') || {};
const audioStream = streams.find((s) => s.codec_type === 'audio') || {};
const duration = parseFloat(parsed.format?.duration || '0');
const size = parseInt(parsed.format?.size || '0', 10);
return {
duration_seconds: parseFloat(duration.toFixed(2)),
width: videoStream.width || null,
height: videoStream.height || null,
resolution: videoStream.width && videoStream.height ? `${videoStream.width}x${videoStream.height}` : null,
video_codec: videoStream.codec_name || 'unknown',
audio_codec: audioStream.codec_name || 'none',
size_bytes: size,
size_formatted: formatBytes(size)
};
} catch (err) {
return {
duration_seconds: null,
video_codec: 'unknown',
audio_codec: 'unknown',
error: err.message
};
}
}
async function downloadRemoteVideo(url) {
const parsed = new URL(url);
const ext = path.extname(parsed.pathname) || '.mp4';
const tempPath = path.join(os.tmpdir(), `flonnect_src_${Date.now()}${ext}`);
const res = await fetch(url, {
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124.0.0.0'
}
});
if (!res.ok) {
throw new Error(`Gagal mengunduh remote video (${res.status}): ${url}`);
}
const arrayBuffer = await res.arrayBuffer();
fs.writeFileSync(tempPath, Buffer.from(arrayBuffer));
return tempPath;
}
async function convertVideoToHls(inputSource, options = {}) {
let sourcePath = (inputSource || '').trim();
if (!sourcePath) {
throw new Error('Input video (file path atau URL) wajib disertakan!');
}
let isRemote = false;
if (sourcePath.startsWith('http://') || sourcePath.startsWith('https://')) {
isRemote = true;
sourcePath = await downloadRemoteVideo(sourcePath);
} else if (!fs.existsSync(sourcePath)) {
throw new Error(`File video tidak ditemukan di: "${sourcePath}"`);
}
try {
const videoInfo = probeVideo(sourcePath);
const segmentTime = options.segmentTime || 4;
const mode = options.mode || 'copy';
const createZip = options.createZip !== false;
const baseName = path.basename(sourcePath, path.extname(sourcePath));
const outDir =
options.outputDir ||
path.join(process.cwd(), `hls_${baseName}_${Date.now()}`);
if (!fs.existsSync(outDir)) {
fs.mkdirSync(outDir, { recursive: true });
}
const playlistName = 'index.m3u8';
const playlistPath = path.join(outDir, playlistName);
if (mode === 'adaptive' && videoInfo.height && videoInfo.height >= 480) {
const ffmpegArgs = [
'-i', sourcePath,
'-filter_complex',
'[v:0]split=2[v1][v2];[v1]scale=w=1280:h=720:force_original_aspect_ratio=decrease[v1out];[v2]scale=w=854:h=480:force_original_aspect_ratio=decrease[v2out]',
'-map', '[v1out]', '-c:v:0', 'libx264', '-crf:v:0', '23', '-preset:v:0', 'fast',
'-map', 'a:0?', '-c:a:0', 'aac', '-b:a:0', '128k',
'-map', '[v2out]', '-c:v:1', 'libx264', '-crf:v:1', '25', '-preset:v:1', 'fast',
'-map', 'a:0?', '-c:a:1', 'aac', '-b:a:1', '96k',
'-f', 'hls',
'-hls_time', String(segmentTime),
'-hls_playlist_type', 'vod',
'-hls_segment_filename', path.join(outDir, 'v%v/segment%d.ts'),
'-master_pl_name', 'master.m3u8',
'-var_stream_map', 'v:0,a:0 v:1,a:1',
path.join(outDir, 'v%v/prog_index.m3u8'),
'-y'
];
execFileSync('ffmpeg', ffmpegArgs, { encoding: 'utf8', stdio: 'pipe' });
} else {
const segmentPattern = path.join(outDir, 'segment_%03d.ts');
const ffmpegArgs = [
'-i', sourcePath,
'-codec:', 'copy',
'-start_number', '0',
'-hls_time', String(segmentTime),
'-hls_list_size', '0',
'-f', 'hls',
'-hls_segment_filename', segmentPattern,
playlistPath,
'-y'
];
try {
execFileSync('ffmpeg', ffmpegArgs, { encoding: 'utf8', stdio: 'pipe' });
} catch {
const reencodeArgs = [
'-i', sourcePath,
'-c:v', 'libx264',
'-preset', 'fast',
'-crf', '23',
'-c:a', 'aac',
'-b:a', '128k',
'-start_number', '0',
'-hls_time', String(segmentTime),
'-hls_list_size', '0',
'-f', 'hls',
'-hls_segment_filename', segmentPattern,
playlistPath,
'-y'
];
execFileSync('ffmpeg', reencodeArgs, { encoding: 'utf8', stdio: 'pipe' });
}
}
const allFiles = fs.readdirSync(outDir, { recursive: true });
const segments = allFiles.filter((f) => f.endsWith('.ts'));
const playlists = allFiles.filter((f) => f.endsWith('.m3u8'));
let zipPath = null;
let zipSize = null;
if (createZip) {
zipPath = `${outDir}.zip`;
try {
execFileSync('zip', ['-r', zipPath, '.'], {
cwd: outDir,
encoding: 'utf8'
});
if (fs.existsSync(zipPath)) {
zipSize = fs.statSync(zipPath).size;
}
} catch {}
}
const mainM3u8 = playlists.includes('master.m3u8')
? path.join(outDir, 'master.m3u8')
: playlistPath;
return {
status: true,
source: isRemote ? inputSource : path.basename(inputSource),
video_info: videoInfo,
hls: {
master_playlist: mainM3u8,
playlist_files: playlists,
segment_duration: segmentTime,
total_segments: segments.length,
segments_sample: segments.slice(0, 5),
output_directory: outDir,
zip_archive: zipPath,
zip_size_formatted: zipSize ? formatBytes(zipSize) : null
}
};
} finally {
if (isRemote && fs.existsSync(sourcePath)) {
try {
fs.unlinkSync(sourcePath);
} catch {}
}
}
}
module.exports = { convertVideoToHls, probeVideo, formatBytes };
const cliArg = process.argv[2] ? process.argv[2].trim() : null;
async function runCli() {
if (!cliArg) {
console.log(
JSON.stringify(
{
status: false,
message: 'Parameter video (file path atau URL) belum ditentukan.',
usage: 'node flonnect-hls-converter.js <video_path_or_url> [options]',
options: [
'--time=<detik> Durasi per chunk TS (default: 4)',
'--adaptive Aktifkan multi-bitrate HLS (720p/480p/360p)',
'--no-zip Jangan kompres ke .zip'
],
examples: [
'node flonnect-hls-converter.js "./video.mp4"',
'node flonnect-hls-converter.js "https://files.catbox.moe/sample.mp4"',
'node flonnect-hls-converter.js "./video.mp4" --time=4 --adaptive'
]
},
null,
2
)
);
process.exit(1);
}
const options = {};
for (let i = 3; i < process.argv.length; i++) {
const arg = process.argv[i];
if (arg.startsWith('--time=')) {
options.segmentTime = parseFloat(arg.split('=')[1]);
}
if (arg === '--adaptive') options.mode = 'adaptive';
if (arg === '--no-zip') options.createZip = false;
}
const res = await convertVideoToHls(cliArg, options);
console.log(JSON.stringify(res, null, 2));
}
if (
process.argv[1] &&
(process.argv[1].endsWith('flonnect-hls-converter.js') ||
process.argv[1].endsWith('flonnect-hls-converter.cjs'))
) {
runCli().catch((err) => {
console.error(JSON.stringify({ status: false, error: err.message }, null, 2));
process.exit(1);
});
}