or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

facebook-upload.mdindex.mdtelegram-bot.mdtiktok-api.mdvideo-processing.md

video-processing.mddocs/

0

# Video Processing

1

2

File management, format conversion, metadata handling, and download queue management utilities. Provides comprehensive video processing capabilities including quality selection, batch processing, and automated workflows.

3

4

## Capabilities

5

6

### Video Quality Selection

7

8

Interactive quality selection for TikTok videos with multiple resolution options.

9

10

```javascript { .api }

11

/**

12

* Interactive video quality selection via command line

13

* @param videos - Array of available video quality options

14

* @returns Selected video quality object

15

*/

16

function chooseVideoQuality(videos: VideoQuality[]): VideoQuality;

17

18

interface VideoQuality {

19

/** Quality descriptor (e.g., "HD", "720p") */

20

quality?: string;

21

/** Video download URL */

22

url: string;

23

}

24

```

25

26

**Usage Examples:**

27

28

These functions are part of the main application workflow when running `node index.js`. They are not exported for direct import but are used internally:

29

30

```javascript

31

// When running the main application (node index.js)

32

// The user is presented with quality options automatically:

33

// Available video qualities:

34

// 1. HD

35

// 2. SD

36

// 3. Mobile

37

// Choose video quality (enter number): 1

38

39

// The function handles user input and returns selected quality

40

// Includes fallback for empty/invalid video arrays

41

if (!videos || videos.length === 0) {

42

console.log('No video qualities available. Using default.');

43

return videos[0];

44

}

45

```

46

47

### Metadata Management

48

49

Save and manage video metadata in JSON format for archival and reference.

50

51

```javascript { .api }

52

/**

53

* Save video metadata to JSON file

54

* @param metadata - Video metadata object to save

55

* @param filePath - Target file path for JSON output

56

*/

57

function saveMetadata(metadata: object, filePath: string): void;

58

```

59

60

**Usage Examples:**

61

62

This function is used internally by the main application during the download process:

63

64

```javascript

65

// During the downloadAndUpload workflow, metadata is automatically saved:

66

// Save metadata (happens automatically in main app)

67

const videoMetadata = result.result; // TikTok API result

68

saveMetadata(videoMetadata, path.resolve('download', `${namafile}_metadata.json`));

69

// Creates: ./download/video123_metadata.json

70

```

71

72

### Video Format Conversion

73

74

Convert videos between different formats using FFmpeg integration.

75

76

```javascript { .api }

77

/**

78

* Convert video to different format using FFmpeg

79

* @param inputPath - Source video file path

80

* @param outputPath - Target output file path

81

* @param format - Target video format (e.g., 'webm', 'avi', 'mov')

82

* @returns Promise resolving when conversion completes

83

*/

84

function convertVideo(inputPath: string, outputPath: string, format: string): Promise<void>;

85

```

86

87

**Usage Examples:**

88

89

Video conversion happens automatically in the main application workflow:

90

91

```javascript

92

// Conversion occurs automatically after download in the main app:

93

// Convert video (example to webm format) - from index.js

94

const webmPath = path.resolve('download', `${namafile}.webm`);

95

try {

96

await convertVideo(downloadPath, webmPath, 'webm');

97

console.log(`Video converted to WebM: ${webmPath}`);

98

} catch (error) {

99

console.log(`Error converting video: ${error.message}`);

100

}

101

```

102

103

### Complete Download and Upload Workflow

104

105

Integrated workflow combining download, processing, and upload operations.

106

107

```javascript { .api }

108

/**

109

* Complete integrated workflow: download TikTok video, process, and upload to Facebook

110

* Includes quality selection, metadata saving, format conversion, and error handling

111

* @param url - TikTok video URL to process

112

* @param retries - Number of retry attempts on failure (default: 3)

113

* @returns Promise resolving when workflow completes successfully

114

* @throws Logs errors but doesn't throw, handles retries internally

115

*/

116

async function downloadAndUpload(url: string, retries?: number): Promise<void>;

117

118

/**

119

* Interactive command-line interface functions

120

* These functions handle user input and CLI workflow

121

*/

122

interface CLIFunctions {

123

/** Prompt user to choose between single URL or list processing */

124

promptForInputMode(): 'single' | 'list';

125

/** Get single TikTok URL from user input */

126

promptForSingleUrl(): string;

127

/** Get file path containing URL list from user input */

128

promptForListFilePath(): string;

129

}

130

```

131

132

**Usage Examples:**

133

134

This function is the core workflow of the main application:

135

136

```javascript

137

// Called internally by the queue system and main application

138

// When user provides URL via CLI or when processing queue items:

139

await downloadAndUpload(url, retries);

140

141

// The function automatically:

142

// 1. Downloads video metadata and file

143

// 2. Saves metadata to JSON

144

// 3. Converts video format

145

// 4. Uploads to Facebook Reels

146

// 5. Handles errors with retries

147

```

148

149

### Batch URL Processing

150

151

Process multiple TikTok URLs from a text file with queue management.

152

153

```javascript { .api }

154

/**

155

* Process multiple URLs from a text file

156

* @param filePath - Path to file containing URLs (one per line)

157

*/

158

function processUrlList(filePath: string): void;

159

```

160

161

**Usage Examples:**

162

163

This function is used when the user chooses "list" mode in the main application:

164

165

```javascript

166

// When user runs: node index.js

167

// And selects "list" option, then provides file path

168

// The function reads urls.txt containing:

169

// https://vm.tiktok.com/ZSFxxxxxx/

170

// https://vm.tiktok.com/ZSFyyyyyy/

171

// https://vm.tiktok.com/ZSFzzzzzz/

172

173

// processUrlList('./urls.txt') is called internally

174

// Automatically adds all URLs to download queue

175

```

176

177

### Download Queue Management

178

179

Concurrent download and upload processing with queue system.

180

181

```javascript { .api }

182

/**

183

* Better-queue instance for managing concurrent downloads

184

*/

185

const downloadQueue: Queue;

186

187

interface QueueTask {

188

/** TikTok URL to process */

189

url: string;

190

}

191

192

/**

193

* Queue configuration options

194

*/

195

interface QueueConfig {

196

/** Number of concurrent workers */

197

concurrent: number;

198

}

199

200

// Queue events

201

downloadQueue.on('drain', () => void); // All tasks completed

202

```

203

204

**Usage Examples:**

205

206

```javascript

207

import Queue from 'better-queue';

208

209

// Queue is pre-configured with concurrent: 2

210

const downloadQueue = new Queue(async (task, cb) => {

211

await downloadAndUpload(task.url);

212

cb(null, task);

213

}, { concurrent: 2 });

214

215

// Add single URL to queue

216

downloadQueue.push({ url: 'https://vm.tiktok.com/ZSFxxxxxx/' });

217

218

// Monitor queue completion

219

downloadQueue.on('drain', () => {

220

console.log('All downloads completed!');

221

});

222

223

// Add multiple URLs

224

const urls = [

225

'https://vm.tiktok.com/ZSFxxxxxx/',

226

'https://vm.tiktok.com/ZSFyyyyyy/'

227

];

228

urls.forEach(url => downloadQueue.push({ url }));

229

```

230

231

## File System Organization

232

233

### Directory Structure

234

235

The video processing system organizes files in a structured manner:

236

237

```

238

project-root/

239

├── download/ # Main download directory

240

│ ├── {videoId}.mp4 # Downloaded video files

241

│ ├── {videoId}_metadata.json # Video metadata

242

│ └── {videoId}.webm # Converted video files

243

├── cookies.json # Facebook session cookies

244

└── config.json # Bot configuration

245

```

246

247

### File Naming Conventions

248

249

```javascript { .api }

250

// File naming patterns

251

const patterns = {

252

/** Original downloaded video */

253

video: `{videoId}.mp4`,

254

/** Video metadata */

255

metadata: `{videoId}_metadata.json`,

256

/** Converted video */

257

converted: `{videoId}.{format}`

258

};

259

```

260

261

## Download Progress Tracking

262

263

Visual progress indicators for download operations using the `progress` package:

264

265

```javascript { .api }

266

// Progress bar configuration

267

const progressBarOptions = {

268

width: 40,

269

complete: '<',

270

incomplete: '•',

271

renderThrottle: 1,

272

format: `[ Downloading ] [:bar] :percent in :elapseds`

273

};

274

```

275

276

## Error Handling and Retry Logic

277

278

Comprehensive error handling with automatic retry mechanisms:

279

280

**Retry Configuration**:

281

- Default retry attempts: 3

282

- Exponential backoff for network errors

283

- Graceful degradation for missing data

284

285

**Common Error Scenarios:**

286

287

1. **Network Connectivity Issues**:

288

- TikTok API timeouts or rate limiting

289

- Axios download failures

290

- Puppeteer browser connection issues

291

292

2. **Invalid TikTok URLs**:

293

- URLs that don't match expected formats

294

- Deleted or private videos

295

- Regional restrictions

296

297

3. **Missing Video Data**:

298

- Empty response from TikTok API

299

- No video qualities available

300

- Corrupted API response

301

302

4. **Facebook Upload Failures**:

303

- Invalid session cookies

304

- Videos exceeding 90-second limit

305

- Facebook UI changes breaking selectors

306

- Network issues during upload

307

308

5. **File System Errors**:

309

- Insufficient disk space

310

- Permission issues in download directory

311

- File already exists conflicts

312

313

6. **Video Processing Errors**:

314

- FFmpeg conversion failures

315

- Unsupported video formats

316

- Corrupted video files

317

318

7. **Queue System Errors**:

319

- Memory issues with large queues

320

- Concurrent processing limits

321

- Task callback errors

322

323

**Error Recovery**:

324

```javascript

325

// Automatic retry with decreasing attempts

326

if (retries > 0) {

327

console.log(`Error occurred. Retrying... (${retries} attempts left)`);

328

await downloadAndUpload(url, retries - 1);

329

} else {

330

console.log(`Failed to process URL after multiple attempts: ${url}`);

331

}

332

```