Capture Thumbnail Whilte Downloading Youtube Video

守給你的承諾、 提交于 2019-12-11 00:25:46

问题


I want to capture a thumbnail of Youtube video on certain timeline. (e.g. 3.2sec) I used ytdl and fluent-ffmpeg with node.js to implement it. It was possible to capture a thumbnail when the downloading has finished.

var fs = require('fs');
var ytdl = require('ytdl');
var ffmpeg = require('fluent-ffmpeg');
var videostream = fs.createWriteStream('video.flv');
var myytdl = ytdl('http://www.youtube.com/watch?v=A02s8omM_hI');
myytdl.pipe(videostream);
videostream.on('close',function() {
  console.log('Downloading complete...');
  var proc = new ffmpeg({ source: 'video.flv', nolog: true })
  .withSize('150x100')
  .takeScreenshots(1, '/home/test', function(err) {
    console.log(err || 'Screenshots were saved');
  });
});

However, I couldn't implement to capture a thumbnail while downloading. Basic idea of what I want to do is as below.

  1. Download Youtube video starting at X sec. (Worked)
  2. Pipe it to Readable/Writable(Duplex) Memory Stream (Need Advise)
  3. During downloading, check if stream has enough data to capture the first frame, which is at X sec. (Need Advise)
  4. Capture the first frame, then stop downloading

For 2, I've realized that node.js will have Duplex Stream on coming v0.9.x, but it seems not working properly. Anyone who has good idea to implement bullet 2,3?

来源:https://stackoverflow.com/questions/14099513/capture-thumbnail-whilte-downloading-youtube-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!