项目作者: scrwdrv

项目描述 :
A simple ffmpeg and ffprobe child process handler, easy to add commands and execute
高级语言: TypeScript
项目地址: git://github.com/scrwdrv/ffmpeg-command.git
创建时间: 2019-12-23T07:44:17Z
项目社区:https://github.com/scrwdrv/ffmpeg-command

开源协议:MIT License

下载


ffmpeg-command

A simple ffmpeg and ffprobe child process handler, easy to add commands and execute

Installation

In order to be able to use this module, make sure you have FFmpeg installed on your system (including all necessary encoding libraries like libmp3lame or libx264).

  1. npm i ffmpeg-command

Usage

ffmpeg

  1. import FFmpegCmd from 'ffmpeg-command';
  2. const ffmpegCmd = new FFmpegCmd({ loglevel: 'info', cwd: './video' });
  3. ffmpegCmd.add(`-i example.mp4 -af volumedetect -vn -sn -dn -f null /dev/null`);
  4. console.log(ffmpegCmd.cmd());
  5. //ffmpeg -threads 0 -hide_banner -y -loglevel info -i example.mp4 -af volumedetect -vn -sn -dn -f null /dev/null
  6. ffmpegCmd.exec().then((stdout) => {
  7. console.log(stdout);
  8. /*
  9. Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'example.mp4':
  10. Metadata:
  11. major_brand : mp42
  12. minor_version : 0
  13. compatible_brands: isommp42
  14. creation_time : 2018-06-28T20:53:15.000000Z
  15. Duration: 00:01:45.44, start: 0.000000, bitrate: 571 kb/s
  16. Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 406x720 [SAR 1:1 DAR 203:360], 441 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc (default)
  17. Metadata:
  18. creation_time : 2018-06-28T20:53:15.000000Z
  19. handler_name : ISO Media file produced by Google Inc. Created on: 06/28/2018.
  20. Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
  21. Metadata:
  22. creation_time : 2018-06-28T20:53:15.000000Z
  23. handler_name : ISO Media file produced by Google Inc. Created on: 06/28/2018.
  24. Stream mapping:
  25. Stream #0:1 -> #0:0 (aac (native) -> pcm_s16le (native))
  26. Press [q] to stop, [?] for help
  27. Output #0, null, to 'NUL':
  28. Metadata:
  29. major_brand : mp42
  30. minor_version : 0
  31. compatible_brands: isommp42
  32. encoder : Lavf58.29.100
  33. Stream #0:0(eng): Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s (default)
  34. Metadata:
  35. creation_time : 2018-06-28T20:53:15.000000Z
  36. handler_name : ISO Media file produced by Google Inc. Created on: 06/28/2018.
  37. encoder : Lavc58.54.100 pcm_s16le
  38. size=N/A time=00:01:45.44 bitrate=N/A speed= 462x
  39. video:0kB audio:18164kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
  40. [Parsed_volumedetect_0 @ 00000236d9632d80] n_samples: 9299968
  41. [Parsed_volumedetect_0 @ 00000236d9632d80] mean_volume: -22.8 dB
  42. [Parsed_volumedetect_0 @ 00000236d9632d80] max_volume: -2.7 dB
  43. [Parsed_volumedetect_0 @ 00000236d9632d80] histogram_2db: 12
  44. [Parsed_volumedetect_0 @ 00000236d9632d80] histogram_3db: 141
  45. [Parsed_volumedetect_0 @ 00000236d9632d80] histogram_4db: 367
  46. [Parsed_volumedetect_0 @ 00000236d9632d80] histogram_5db: 1027
  47. [Parsed_volumedetect_0 @ 00000236d9632d80] histogram_6db: 2215
  48. [Parsed_volumedetect_0 @ 00000236d9632d80] histogram_7db: 4398
  49. [Parsed_volumedetect_0 @ 00000236d9632d80] histogram_8db: 7799
  50. */
  51. }).catch((err) => {
  52. console.log(err);
  53. });

ffprobe

  1. import { ffprobe } from 'ffmpeg-command';
  2. ffprobe('./video/example.mp4').then((json) => {
  3. console.log(json);
  4. /*
  5. { streams:
  6. [ { index: 0,
  7. codec_name: 'h264',
  8. codec_long_name: 'H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10',
  9. profile: 'Main',
  10. codec_type: 'video',
  11. codec_time_base: '1001/48000',
  12. codec_tag_string: 'avc1',
  13. codec_tag: '0x31637661',
  14. width: 406,
  15. height: 720,
  16. coded_width: 416,
  17. coded_height: 720,
  18. has_b_frames: 1,
  19. sample_aspect_ratio: '1:1',
  20. display_aspect_ratio: '203:360',
  21. pix_fmt: 'yuv420p',
  22. level: 30,
  23. color_range: 'tv',
  24. color_space: 'bt709',
  25. color_transfer: 'bt709',
  26. color_primaries: 'bt709',
  27. chroma_location: 'left',
  28. refs: 1,
  29. is_avc: 'true',
  30. nal_length_size: '4',
  31. r_frame_rate: '24000/1001',
  32. avg_frame_rate: '24000/1001',
  33. time_base: '1/90000',
  34. start_pts: 0,
  35. start_time: '0.000000',
  36. duration_ts: 9489480,
  37. duration: '105.438667',
  38. bit_rate: '441202',
  39. bits_per_raw_sample: '8',
  40. nb_frames: '2528',
  41. disposition: [Object],
  42. tags: [Object] },
  43. { index: 1,
  44. codec_name: 'aac',
  45. codec_long_name: 'AAC (Advanced Audio Coding)',
  46. profile: 'LC',
  47. codec_type: 'audio',
  48. codec_time_base: '1/44100',
  49. codec_tag_string: 'mp4a',
  50. codec_tag: '0x6134706d',
  51. sample_fmt: 'fltp',
  52. sample_rate: '44100',
  53. channels: 2,
  54. channel_layout: 'stereo',
  55. bits_per_sample: 0,
  56. r_frame_rate: '0/0',
  57. avg_frame_rate: '0/0',
  58. time_base: '1/44100',
  59. start_pts: 0,
  60. start_time: '0.000000',
  61. duration_ts: 4649984,
  62. duration: '105.441814',
  63. bit_rate: '125605',
  64. nb_frames: '4541',
  65. disposition: [Object],
  66. tags: [Object] } ],
  67. format:
  68. { filename: './video/example.mp4',
  69. nb_streams: 2,
  70. nb_programs: 0,
  71. format_name: 'mov,mp4,m4a,3gp,3g2,mj2',
  72. format_long_name: 'QuickTime / MOV',
  73. start_time: '0.000000',
  74. duration: '105.441811',
  75. size: '7528318',
  76. bit_rate: '571182',
  77. probe_score: 100,
  78. tags:
  79. { major_brand: 'mp42',
  80. minor_version: '0',
  81. compatible_brands: 'isommp42',
  82. creation_time: '2018-06-28T20:53:15.000000Z' } } }
  83. */
  84. }).catch((err) => {
  85. console.log(err);
  86. });