Skip to content

Commit

Permalink
Convert ffmpeg to typescript (#4256)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaylor89 authored and dmanjunath committed Nov 14, 2022
1 parent c58357a commit 182191b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
8 changes: 7 additions & 1 deletion creator-node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions creator-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"@types/death": "^1.1.2",
"@types/eth-sig-util": "^2.1.1",
"@types/express": "4.17.12",
"@types/ffmpeg-static": "^3.0.1",
"@types/fs-extra": "^9.0.13",
"@types/ioredis": "^4.28.10",
"@types/lodash": "^4.14.182",
Expand Down
6 changes: 3 additions & 3 deletions creator-node/src/TranscodingQueue.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { segmentFile, transcodeFileTo320 } = require('./ffmpeg')
const { Queue, QueueEvents, Worker } = require('bullmq')
const os = require('os')

const config = require('./config')
const ffmpeg = require('./ffmpeg')
const { logger: genericLogger } = require('./logging')
const { clusterUtils } = require('./utils')

Expand Down Expand Up @@ -58,7 +58,7 @@ class TranscodingQueue {
logContext
)

const response = await ffmpeg.segmentFile(fileDir, fileName, {
const response = await segmentFile(fileDir, fileName, {
logContext
})
await this.logStatus(
Expand Down Expand Up @@ -86,7 +86,7 @@ class TranscodingQueue {
logContext
)

const transcodeFilePath = await ffmpeg.transcodeFileTo320(
const transcodeFilePath = await transcodeFileTo320(
fileDir,
fileName,
{
Expand Down
33 changes: 22 additions & 11 deletions creator-node/src/ffmpeg.js → creator-node/src/ffmpeg.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
const config = require('./config')
const fs = require('fs-extra')
const path = require('path')
const ffmpeg = require('ffmpeg-static').path
const spawn = require('child_process').spawn
const { logger: genericLogger } = require('./logging')
import type { LogContext } from './apiHelpers'

import config from './config'
import fs from 'fs-extra'
import path from 'path'
import { logger as genericLogger } from './logging'
import { spawn } from 'child_process'
import ffmpegPath from 'ffmpeg-static'
// The typing for the ffmpeg-static model is incorrect
// so this line is here to fix that
const ffmpeg = (ffmpegPath as unknown as { path: string }).path

/**
* Segments file into equal size chunks without re-encoding.
Expand All @@ -22,7 +27,11 @@ const { logger: genericLogger } = require('./logging')
m3u8FilePath {string}: the m3u8 file path
}
*/
function segmentFile(fileDir, fileName, { logContext }) {
export function segmentFile(
fileDir: string,
fileName: string,
{ logContext }: { logContext: LogContext }
) {
const logger = genericLogger.child(logContext)

return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -95,10 +104,14 @@ function segmentFile(fileDir, fileName, { logContext }) {
* @param {Object} params
* @param {string} params.fileDir the directory of the uploaded track artifact
* @param {string} params.fileName the uploaded track artifact filename
* @param {Object} params.logContext the log context used to instantiate a logger
* @param {LogContext} params.logContext the log context used to instantiate a logger
* @returns {Promise<string>} the path to the transcode
*/
async function transcodeFileTo320(fileDir, fileName, { logContext }) {
export async function transcodeFileTo320(
fileDir: string,
fileName: string,
{ logContext }: { logContext: LogContext }
) {
const logger = genericLogger.child(logContext)

const sourcePath = path.resolve(fileDir, fileName)
Expand Down Expand Up @@ -155,5 +168,3 @@ async function transcodeFileTo320(fileDir, fileName, { logContext }) {
})
})
}

module.exports = { segmentFile, transcodeFileTo320 }

0 comments on commit 182191b

Please sign in to comment.