-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support RTMP and SRT stream output (#5)
- Loading branch information
Showing
4 changed files
with
106 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { ILogger } from '@eyevinn/hls-pull-push'; | ||
import { MyLogger } from './logger'; | ||
import { spawn } from 'child_process'; | ||
|
||
export class StreamOutput { | ||
private logger: ILogger; | ||
|
||
constructor(logger?: ILogger) { | ||
this.logger = logger || new MyLogger(process.env.NODE_ENV); | ||
} | ||
|
||
async startFetcher({ | ||
name, | ||
url, | ||
destinationUrl, | ||
h264encoder | ||
}: { | ||
name: string; | ||
url: string; | ||
destinationUrl: URL; | ||
h264encoder?: string; | ||
}) { | ||
this.logger.info( | ||
`Starting ffmpeg fetcher to fetch ${url} and push to ${destinationUrl}` | ||
); | ||
const container = destinationUrl.protocol === 'rtmp:' ? 'flv' : 'mpegts'; | ||
const process = spawn('ffmpeg', [ | ||
'-fflags', | ||
'+genpts', | ||
'-re', | ||
'-i', | ||
url, | ||
'-c:v', | ||
h264encoder || 'libx264', | ||
'-b:v', | ||
'8000k', | ||
'-c:a', | ||
'aac', | ||
'-f', | ||
container, | ||
destinationUrl.toString() | ||
]); | ||
this.logger.verbose(process.spawnargs.join(' ')); | ||
await new Promise((resolve, reject) => { | ||
process.on('close', resolve); | ||
process.stderr.on('data', (data) => { | ||
this.logger.info(data.toString()); | ||
}); | ||
process.on('error', reject); | ||
}); | ||
} | ||
} |