Blareprefix
Blareprefix

Reputation: 870

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?

Upvotes: 3

Views: 2920

Answers (3)

sole007
sole007

Reputation: 727

To generate thumbnail from rtmp video feed use ffmpeg tool. I have used this on Android app, NodeJS server and it never disappoints. And not just thumbnail. And it work like a charm.

ffmpeg -i <rtmp_feed_url> -frames:v 1 <destination_filepath>

Upvotes: 0

med benzekri
med benzekri

Reputation: 603

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});

Upvotes: 0

posit labs
posit labs

Reputation: 9471

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

Upvotes: 4

Related Questions