Skip to content

Commit

Permalink
fix: 推流地址
Browse files Browse the repository at this point in the history
  • Loading branch information
galaxy-s10 committed Aug 26, 2023
1 parent c33e63f commit a131aea
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/controller/init.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class InitController {
.toString();
if (user.live_room.cdn === 2) {
liveUrl = (live_room_id: number) => ({
rtmp_url: `${SERVER_LIVE.PushDomain}/${SERVER_LIVE.AppName}/roomId___${live_room_id}?token=${rtmptoken}`,
rtmp_url: `${SERVER_LIVE.PushDomain}/${SERVER_LIVE.AppName}/roomId___${live_room_id}`,
flv_url: `${SERVER_LIVE.PullDomain}/${SERVER_LIVE.AppName}/roomId___${live_room_id}.flv`,
hls_url: `${SERVER_LIVE.PullDomain}/${SERVER_LIVE.AppName}/roomId___${live_room_id}.m3u8`,
});
Expand Down
4 changes: 2 additions & 2 deletions src/controller/liveRoom.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ class LiveRoomController {
.toString();
const rtmp_url = `${SERVER_LIVE.PushDomain}/${
SERVER_LIVE.AppName
}/roomId___${liveRoom.live_room!.id!}?token=${key}`;
}/roomId___${liveRoom.live_room!.id!}`;
await this.common.update({
id: liveRoom.live_room!.id!,
key,
rtmp_url,
});
successHandler({ ctx, data: { rtmp_url, liveRoom } });
successHandler({ ctx, data: { rtmp_url, key } });
}
} else {
throw new CustomError(message, code, code);
Expand Down
2 changes: 1 addition & 1 deletion src/controller/userLiveRoom.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class UserLiveRoomController {
// @ts-ignore
await liveRoom.setAreas([1]);
const liveUrl = (live_room_id: number) => ({
rtmp_url: `${SERVER_LIVE.PushDomain}/${SERVER_LIVE.AppName}/roomId___${live_room_id}?token=${rtmptoken}`,
rtmp_url: `${SERVER_LIVE.PushDomain}/${SERVER_LIVE.AppName}/roomId___${live_room_id}`,
flv_url: `${SERVER_LIVE.PullDomain}/${SERVER_LIVE.AppName}/roomId___${live_room_id}.flv`,
hls_url: `${SERVER_LIVE.PullDomain}/${SERVER_LIVE.AppName}/roomId___${live_room_id}.m3u8`,
});
Expand Down
11 changes: 5 additions & 6 deletions src/init/initFFmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async function addLive({
let flv_url = '';
let hls_url = '';
let rtmp_url = '';
let token = '';
async function main() {
await liveService.deleteByLiveRoomId(live_room_id);
// 开发环境时判断initFFmpeg,是true的才初始化ffmpeg
Expand Down Expand Up @@ -65,9 +66,8 @@ async function addLive({
// ]);
// const { pid } = ffmpegCmd;
// console.log(chalkWARN('ffmpeg进程pid'), pid);
const ffmpegCmd = `ffmpeg -loglevel quiet -readrate 1 -stream_loop -1 -i ${localFile} -vcodec copy -acodec copy -f flv '${rtmp_url}'`;
const ffmpegSyncCmd = `ffmpeg -loglevel quiet -readrate 1 -stream_loop -1 -i ${localFile} -vcodec copy -acodec copy -f flv '${rtmp_url}' 1>/dev/null 2>&1 &`;
// const ffmpegCmd = `ffmpeg -loglevel quiet -readrate 1 -stream_loop -1 -i /Users/huangshuisheng/Desktop/hss/galaxy-s10/billd-live-server/src/video/fddm_mhsw.mp4 -vcodec copy -acodec copy -f flv 'rtmp://localhost/livestream/roomId___3?token=eff5e5d9116254a1aea19013f8bd3afe' 1>/dev/null 2>&1 &`;
const ffmpegCmd = `ffmpeg -loglevel quiet -readrate 1 -stream_loop -1 -i ${localFile} -vcodec copy -acodec copy -f flv '${rtmp_url}?token=${token}'`;
const ffmpegSyncCmd = `ffmpeg -loglevel quiet -readrate 1 -stream_loop -1 -i ${localFile} -vcodec copy -acodec copy -f flv '${rtmp_url}?token=${token}' 1>/dev/null 2>&1 &`;
try {
// WARN 使用execSync的话,命令最后需要添加:1>/dev/null 2>&1 &,否则会自动退出进程;
// 但是本地开发环境的时候,因为nodemon的缘故,每次热更新后,在ffmpeg推完流后,触发on_unpublish钩子,删除了live表里的直播记录
Expand Down Expand Up @@ -123,9 +123,8 @@ async function addLive({

if (cdn === 2) {
const liveRoomInfo = await liveRoomService.findKey(live_room_id);
rtmp_url = `${SERVER_LIVE.PushDomain}/${
SERVER_LIVE.AppName
}/roomId___${live_room_id}?token=${liveRoomInfo!.key!}`;
token = liveRoomInfo!.key!;
rtmp_url = `${SERVER_LIVE.PushDomain}/${SERVER_LIVE.AppName}/roomId___${live_room_id}`;
flv_url = `${SERVER_LIVE.PullDomain}/${SERVER_LIVE.AppName}/roomId___${live_room_id}.flv`;
hls_url = `${SERVER_LIVE.PullDomain}/${SERVER_LIVE.AppName}/roomId___${live_room_id}.m3u8`;
await main();
Expand Down

0 comments on commit a131aea

Please sign in to comment.