'Generate ffmpeg thumbnail from stream in Node.js

Im using node.js together with ffmpeg to receive an rtmp-stream and output this into m3u8-format.

[ '-y',
  '-fflags',
  'nobuffer',
  '-analyzeduration',
  '1000000',
  '-i',
  'rtmp://localhost:1935/live/ANMZJ2ZRUiMhKaAoygRXwAfHe',
  '-c:v',
  'copy',
  '-c:a',
  'aac',
  '-f',
  'tee',
  '-map',
  '0:a?',
  '-map',
  '0:v?',
  '-y',
  '-an',
  '[hls_time=10:hls_list_size=0]./media/live/ANMZJ2ZRUiMhKaAoygRXwAfHe/SX3otgDdf6/index.m3u8|' ]

Together with this functionality I would also like to output a thumbnail. I tried to do this using the following format but without success.

[ '-y',
  '-fflags',
  'nobuffer',
  '-analyzeduration',
  '1000000',
  '-i',
  'rtmp://localhost:1935/live/ANMZJ2ZRUiMhKaAoygRXwAfHe',
  '-c:v',
  'copy',
  '-c:a',
  'aac',
  '-f',
  'tee',
  '-map',
  '0:a?',
  '-map','0:v?',
  '-y',
  '-an',
  '-vf' ,
  'fps=1',
  'C:/Users/media/out.png'
  '[hls_time=10:hls_list_size=0]./media/live/ANMZJ2ZRUiMhKaAoygRXwAfHe/SX3otgDdf6/index.m3u8|' ]

The way I send this information to ffmpeg is by

this.ffmpeg_exec = spawn(ffmpeg_path, args);

Im unable to create a thumbnail using this approach. Does anyone know the problem/solution?



Solution 1:[1]

You have a log of extra arguments in the second command! You really only need the input, number of frames, and output.

[ '-i',
  'rtmp://localhost:1935/live/ANMZJ2ZRUiMhKaAoygRXwAfHe',
  '-frames:v',
  '1',
  'C:/Users/media/out.png'
]

Docs for -frames:v https://ffmpeg.org/ffmpeg.html#Video-Options

Solution 2:[2]

fluent-ffmpeg support stream input and output :

var FfmpegCommand = require('fluent-ffmpeg');
var ffmpeg = FfmpegCommand();
  ffmpeg.input(stream)
  .seekInput("00:00:01.000")
  .outputFormat("image2")
  .pipe(res,{end:true});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 posit labs
Solution 2