@vpalmisano/webrtcperf 4.0.6 → 4.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -82,7 +82,7 @@ async function prepareFakeMedia({ videoPath, videoWidth, videoHeight, videoFrame
82
82
  ` ${audioMap} -ar 48000 ${destAudioPathTmp}` +
83
83
  (destMp4PathTmp
84
84
  ? ` ${videoMap} -c:v libx264 -crf 10 -f mp4 -movflags faststart ${destMp4PathTmp}` +
85
- ` ${audioMap} -c:a aac -b:a 192k ${destM4aPathTmp}`
85
+ ` ${audioMap} -c:a aac -ar 48000 -b:a 192k -f mp4 -movflags faststart ${destM4aPathTmp}`
86
86
  : ''));
87
87
  await fs_1.promises.rename(destVideoPathTmp, destVideoPath);
88
88
  await fs_1.promises.rename(destAudioPathTmp, destAudioPath);
@@ -1 +1 @@
1
- {"version":3,"file":"media.js","sourceRoot":"","sources":["../../src/media.ts"],"names":[],"mappings":";;AA8BA,4CAwHC;AAtJD,2BAA+C;AAE/C,mCAAyD;AAEzD,MAAM,GAAG,GAAG,IAAA,cAAM,EAAC,kBAAkB,CAAC,CAAA;AAEtC,MAAM,kBAAkB,GAAG,6EAA6E,CAAA;AASxG;;;;;;;;;;;;;;GAcG;AACI,KAAK,UAAU,gBAAgB,CAAC,EACrC,SAAS,EACT,UAAU,EACV,WAAW,EACX,cAAc,EACd,SAAS,EACT,aAAa,EACb,aAAa,EACb,cAAc,EACd,WAAW,EACX,YAAY,GAYb;IACC,GAAG,CAAC,KAAK,CAAC,kBAAkB,EAAE;QAC5B,SAAS;QACT,UAAU;QACV,WAAW;QACX,cAAc;QACd,SAAS;QACT,aAAa;QACb,aAAa;QACb,cAAc;QACd,WAAW;QACX,YAAY;KACb,CAAC,CAAA;IACF,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAA;IACrC,CAAC;IACD,IAAI,CAAC,SAAS,CAAC,UAA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AChB,GAAG,EAAE,WAAW;KACjB,CAAA;AACH,CAAC","sourcesContent":["import { existsSync, promises as fs } from 'fs'\n\nimport { logger, runShellCommand, sha256 } from './utils'\n\nconst log = logger('webrtcperf:media')\n\nconst DEFAULT_VIDEO_PATH = 'https://github.com/vpalmisano/webrtcperf/releases/download/v2.0.4/video.mp4'\n\nexport type MediaPath = {\n video: string\n audio: string\n mp4: string\n m4a: string\n}\n\n/**\n * Converts the video file into raw audio and video files.\n * @param {*} config\n * @param {string} config.videoPath the video to convert\n * @param {string} config.videoWidth the output video width\n * @param {string} config.videoHeight the output video height\n * @param {string} config.videoFramerate the output video framerate\n * @param {string} config.videoSeek the seek position in seconds\n * @param {string} config.videoDuration the output video duration in seconds\n * @param {boolean} config.videoCacheRaw if true and the destinations raw files\n * exist on file system, the conversion step is skipped\n * @param {string} config.videoCachePath the destination directory path; if not\n * existing, it will be created\n * @param {string} config.videoFormat the raw video format (y4m or mjpeg)\n */\nexport async function prepareFakeMedia({\n videoPath,\n videoWidth,\n videoHeight,\n videoFramerate,\n videoSeek,\n videoDuration,\n videoCacheRaw,\n videoCachePath,\n videoFormat,\n useFakeMedia,\n}: {\n videoPath: string\n videoWidth: number\n videoHeight: number\n videoFramerate: number\n videoSeek: number\n videoDuration: number\n videoCacheRaw: boolean\n videoCachePath: string\n videoFormat: string\n useFakeMedia: boolean\n}): Promise<MediaPath> {\n log.debug('prepareFakeMedia', {\n videoPath,\n videoWidth,\n videoHeight,\n videoFramerate,\n videoSeek,\n videoDuration,\n videoCacheRaw,\n videoCachePath,\n videoFormat,\n useFakeMedia,\n })\n if (!videoPath) {\n throw new Error('empty video path')\n }\n if (!videoPath.startsWith('http') && !videoPath.startsWith('generate:') && !existsSync(videoPath)) {\n log.warn(`video not found: ${videoPath}, using default test video`)\n videoPath = DEFAULT_VIDEO_PATH\n }\n\n await fs.mkdir(videoCachePath, { recursive: true })\n const name = sha256(videoPath)\n\n const destVideoPath = `${videoCachePath}/${name}_${videoWidth}x${videoHeight}_${videoFramerate}fps.${videoFormat}`\n const destAudioPath = `${videoCachePath}/${name}.wav`\n const destMp4Path = useFakeMedia\n ? ''\n : `${videoCachePath}/${name}_${videoWidth}x${videoHeight}_${videoFramerate}fps.mp4`\n const destM4aPath = useFakeMedia ? '' : `${videoCachePath}/${name}.m4a`\n\n if (\n !existsSync(destVideoPath) ||\n !existsSync(destAudioPath) ||\n (destMp4Path && !existsSync(destMp4Path)) ||\n (destM4aPath && !existsSync(destM4aPath)) ||\n !videoCacheRaw\n ) {\n log.info(\n `Converting ${videoPath} to ${destVideoPath}, ${destAudioPath}${destMp4Path ? `, ${destMp4Path}` : ''}${destM4aPath ? `, ${destM4aPath}` : ''}`,\n )\n const destVideoPathTmp = `${videoCachePath}/${name}_${videoWidth}x${videoHeight}_${videoFramerate}fps.tmp.${videoFormat}`\n const destAudioPathTmp = `${videoCachePath}/${name}.tmp.wav`\n const destMp4PathTmp = useFakeMedia\n ? ''\n : `${videoCachePath}/${name}_${videoWidth}x${videoHeight}_${videoFramerate}fps.tmp.mp4`\n const destM4aPathTmp = useFakeMedia ? '' : `${videoCachePath}/${name}.tmp.m4a`\n\n try {\n let source = `-i \"${videoPath}\"`\n const videoMap = `-map 0:v`\n const audioMap = videoPath.startsWith('generate:') ? '-map 1:a' : '-map 0:a'\n if (videoPath === 'generate:null') {\n source =\n `-f lavfi -i color=size=${videoWidth}x${videoHeight}:rate=${videoFramerate}:color=black` +\n ` -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=48000`\n } else if (videoPath === 'generate:test') {\n source =\n `-f lavfi -i testsrc=size=${videoWidth}x${videoHeight}:rate=${videoFramerate} -pix_fmt yuv420p` +\n ` -f lavfi -i sine=frequency=220:beep_factor=4:sample_rate=48000`\n }\n await runShellCommand(\n `ffmpeg -loglevel warning -y -threads 0 ${source}` +\n ` -s ${videoWidth}:${videoHeight}` +\n ` -r ${videoFramerate}` +\n ` -ss ${videoSeek} -t ${videoDuration} -shortest -af apad` +\n ` ${videoMap} ${destVideoPathTmp}` +\n ` ${audioMap} -ar 48000 ${destAudioPathTmp}` +\n (destMp4PathTmp\n ? ` ${videoMap} -c:v libx264 -crf 10 -f mp4 -movflags faststart ${destMp4PathTmp}` +\n ` ${audioMap} -c:a aac -b:a 192k ${destM4aPathTmp}`\n : ''),\n )\n await fs.rename(destVideoPathTmp, destVideoPath)\n await fs.rename(destAudioPathTmp, destAudioPath)\n if (destMp4PathTmp) {\n await fs.rename(destMp4PathTmp, destMp4Path)\n }\n if (destM4aPathTmp) {\n await fs.rename(destM4aPathTmp, destM4aPath)\n }\n } catch (err) {\n log.error(`Error converting video: ${(err as Error).stack}`)\n fs.unlink(destVideoPathTmp).catch(e => log.debug(e.message))\n fs.unlink(destAudioPathTmp).catch(e => log.debug(e.message))\n if (destMp4PathTmp) {\n fs.unlink(destMp4PathTmp).catch(e => log.debug(e.message))\n }\n throw err\n }\n }\n\n return {\n video: destVideoPath,\n audio: destAudioPath,\n mp4: destMp4Path,\n m4a: destM4aPath,\n }\n}\n"]}
1
+ {"version":3,"file":"media.js","sourceRoot":"","sources":["../../src/media.ts"],"names":[],"mappings":";;AA8BA,4CAwHC;AAtJD,2BAA+C;AAE/C,mCAAyD;AAEzD,MAAM,GAAG,GAAG,IAAA,cAAM,EAAC,kBAAkB,CAAC,CAAA;AAEtC,MAAM,kBAAkB,GAAG,6EAA6E,CAAA;AASxG;;;;;;;;;;;;;;GAcG;AACI,KAAK,UAAU,gBAAgB,CAAC,EACrC,SAAS,EACT,UAAU,EACV,WAAW,EACX,cAAc,EACd,SAAS,EACT,aAAa,EACb,aAAa,EACb,cAAc,EACd,WAAW,EACX,YAAY,GAYb;IACC,GAAG,CAAC,KAAK,CAAC,kBAAkB,EAAE;QAC5B,SAAS;QACT,UAAU;QACV,WAAW;QACX,cAAc;QACd,SAAS;QACT,aAAa;QACb,aAAa;QACb,cAAc;QACd,WAAW;QACX,YAAY;KACb,CAAC,CAAA;IACF,IAAI,CAAC,SAAS,EAAE,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,CAAC;IACH,CAAC;IAED,OAAO;QACL,KAAK,EAAE,aAAa;QACpB,KAAK,EAAE,aAAa;QACpB,GAAG,EAAE,WAAW;QAChB,GAAG,EAAE,WAAW;KACjB,CAAA;AACH,CAAC","sourcesContent":["import { existsSync, promises as fs } from 'fs'\n\nimport { logger, runShellCommand, sha256 } from './utils'\n\nconst log = logger('webrtcperf:media')\n\nconst DEFAULT_VIDEO_PATH = 'https://github.com/vpalmisano/webrtcperf/releases/download/v2.0.4/video.mp4'\n\nexport type MediaPath = {\n video: string\n audio: string\n mp4: string\n m4a: string\n}\n\n/**\n * Converts the video file into raw audio and video files.\n * @param {*} config\n * @param {string} config.videoPath the video to convert\n * @param {string} config.videoWidth the output video width\n * @param {string} config.videoHeight the output video height\n * @param {string} config.videoFramerate the output video framerate\n * @param {string} config.videoSeek the seek position in seconds\n * @param {string} config.videoDuration the output video duration in seconds\n * @param {boolean} config.videoCacheRaw if true and the destinations raw files\n * exist on file system, the conversion step is skipped\n * @param {string} config.videoCachePath the destination directory path; if not\n * existing, it will be created\n * @param {string} config.videoFormat the raw video format (y4m or mjpeg)\n */\nexport async function prepareFakeMedia({\n videoPath,\n videoWidth,\n videoHeight,\n videoFramerate,\n videoSeek,\n videoDuration,\n videoCacheRaw,\n videoCachePath,\n videoFormat,\n useFakeMedia,\n}: {\n videoPath: string\n videoWidth: number\n videoHeight: number\n videoFramerate: number\n videoSeek: number\n videoDuration: number\n videoCacheRaw: boolean\n videoCachePath: string\n videoFormat: string\n useFakeMedia: boolean\n}): Promise<MediaPath> {\n log.debug('prepareFakeMedia', {\n videoPath,\n videoWidth,\n videoHeight,\n videoFramerate,\n videoSeek,\n videoDuration,\n videoCacheRaw,\n videoCachePath,\n videoFormat,\n useFakeMedia,\n })\n if (!videoPath) {\n throw new Error('empty video path')\n }\n if (!videoPath.startsWith('http') && !videoPath.startsWith('generate:') && !existsSync(videoPath)) {\n log.warn(`video not found: ${videoPath}, using default test video`)\n videoPath = DEFAULT_VIDEO_PATH\n }\n\n await fs.mkdir(videoCachePath, { recursive: true })\n const name = sha256(videoPath)\n\n const destVideoPath = `${videoCachePath}/${name}_${videoWidth}x${videoHeight}_${videoFramerate}fps.${videoFormat}`\n const destAudioPath = `${videoCachePath}/${name}.wav`\n const destMp4Path = useFakeMedia\n ? ''\n : `${videoCachePath}/${name}_${videoWidth}x${videoHeight}_${videoFramerate}fps.mp4`\n const destM4aPath = useFakeMedia ? '' : `${videoCachePath}/${name}.m4a`\n\n if (\n !existsSync(destVideoPath) ||\n !existsSync(destAudioPath) ||\n (destMp4Path && !existsSync(destMp4Path)) ||\n (destM4aPath && !existsSync(destM4aPath)) ||\n !videoCacheRaw\n ) {\n log.info(\n `Converting ${videoPath} to ${destVideoPath}, ${destAudioPath}${destMp4Path ? `, ${destMp4Path}` : ''}${destM4aPath ? `, ${destM4aPath}` : ''}`,\n )\n const destVideoPathTmp = `${videoCachePath}/${name}_${videoWidth}x${videoHeight}_${videoFramerate}fps.tmp.${videoFormat}`\n const destAudioPathTmp = `${videoCachePath}/${name}.tmp.wav`\n const destMp4PathTmp = useFakeMedia\n ? ''\n : `${videoCachePath}/${name}_${videoWidth}x${videoHeight}_${videoFramerate}fps.tmp.mp4`\n const destM4aPathTmp = useFakeMedia ? '' : `${videoCachePath}/${name}.tmp.m4a`\n\n try {\n let source = `-i \"${videoPath}\"`\n const videoMap = `-map 0:v`\n const audioMap = videoPath.startsWith('generate:') ? '-map 1:a' : '-map 0:a'\n if (videoPath === 'generate:null') {\n source =\n `-f lavfi -i color=size=${videoWidth}x${videoHeight}:rate=${videoFramerate}:color=black` +\n ` -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=48000`\n } else if (videoPath === 'generate:test') {\n source =\n `-f lavfi -i testsrc=size=${videoWidth}x${videoHeight}:rate=${videoFramerate} -pix_fmt yuv420p` +\n ` -f lavfi -i sine=frequency=220:beep_factor=4:sample_rate=48000`\n }\n await runShellCommand(\n `ffmpeg -loglevel warning -y -threads 0 ${source}` +\n ` -s ${videoWidth}:${videoHeight}` +\n ` -r ${videoFramerate}` +\n ` -ss ${videoSeek} -t ${videoDuration} -shortest -af apad` +\n ` ${videoMap} ${destVideoPathTmp}` +\n ` ${audioMap} -ar 48000 ${destAudioPathTmp}` +\n (destMp4PathTmp\n ? ` ${videoMap} -c:v libx264 -crf 10 -f mp4 -movflags faststart ${destMp4PathTmp}` +\n ` ${audioMap} -c:a aac -ar 48000 -b:a 192k -f mp4 -movflags faststart ${destM4aPathTmp}`\n : ''),\n )\n await fs.rename(destVideoPathTmp, destVideoPath)\n await fs.rename(destAudioPathTmp, destAudioPath)\n if (destMp4PathTmp) {\n await fs.rename(destMp4PathTmp, destMp4Path)\n }\n if (destM4aPathTmp) {\n await fs.rename(destM4aPathTmp, destM4aPath)\n }\n } catch (err) {\n log.error(`Error converting video: ${(err as Error).stack}`)\n fs.unlink(destVideoPathTmp).catch(e => log.debug(e.message))\n fs.unlink(destAudioPathTmp).catch(e => log.debug(e.message))\n if (destMp4PathTmp) {\n fs.unlink(destMp4PathTmp).catch(e => log.debug(e.message))\n }\n throw err\n }\n }\n\n return {\n video: destVideoPath,\n audio: destAudioPath,\n mp4: destMp4Path,\n m4a: destM4aPath,\n }\n}\n"]}
@@ -549,8 +549,6 @@ webrtcperf.config = {
549
549
  VIDEO_WIDTH: ${this.videoWidth},
550
550
  VIDEO_HEIGHT: ${this.videoHeight},
551
551
  VIDEO_FRAMERATE: ${this.videoFramerate},
552
- RANDOM_AUDIO_PERIOD: ${this.randomAudioPeriod},
553
- USE_FAKE_MEDIA: ${this.useFakeMedia},
554
552
  };
555
553
  try {
556
554
  webrtcperf.params = JSON.parse('${JSON.stringify(this.scriptParams)}' || '{}');