Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 455
Blareprefix Avatar asked Jun 21 '26 12:06

Blareprefix


1 Answers

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

like image 142
posit labs Avatar answered Jun 24 '26 06:06

posit labs