001/** 002 * Copyright 2011 The University of Southampton, Yahoo Inc., and the 003 * individual contributors. All rights reserved. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.openimaj.web.video; 018 019import java.net.MalformedURLException; 020import java.net.URL; 021import java.util.concurrent.atomic.AtomicBoolean; 022 023import org.openimaj.image.MBFImage; 024import org.openimaj.video.Video; 025import org.openimaj.video.xuggle.XuggleVideo; 026 027import com.github.axet.vget.VGet; 028import com.github.axet.vget.info.VideoInfoUser; 029 030/** 031 * A wrapper around {@link VGet}, which supports video download from youtube, vimeo 032 * and a few other video sites. Just providing the URL uses the first video URL 033 * {@link VGet} finds. You can also provide a {@link VideoInfoUser} to control 034 * the quality of video downloaded 035 * 036 * @author Sina Samangooei (ss@ecs.soton.ac.uk) 037 * 038 */ 039public class VGetVideo extends Video<MBFImage>{ 040 041 private XuggleVideo vid; 042 043 /** 044 * @param url 045 * @throws MalformedURLException 046 */ 047 public VGetVideo(String url) throws MalformedURLException { 048 VGet v = new VGet(new URL(url)); 049 v.extract(); 050 this.vid = new XuggleVideo(v.getVideo().getInfo().getSource()); 051 052 } 053 054 /** 055 * @param url 056 * @param iu 057 * @throws MalformedURLException 058 */ 059 public VGetVideo(String url, VideoInfoUser iu) throws MalformedURLException{ 060 VGet v = new VGet(new URL(url)); 061 AtomicBoolean stop = new AtomicBoolean(false); 062 v.extract(iu,stop, new Runnable() { @Override public void run() {}}); 063 this.vid = new XuggleVideo(v.getVideo().getInfo().getSource()); 064 } 065 066 @Override 067 public MBFImage getNextFrame() { 068 return vid.getNextFrame(); 069 } 070 071 @Override 072 public MBFImage getCurrentFrame() { 073 return vid.getCurrentFrame(); 074 } 075 076 @Override 077 public int getWidth() { 078 return vid.getWidth(); 079 } 080 081 @Override 082 public int getHeight() { 083 return vid.getHeight(); 084 } 085 086 @Override 087 public long getTimeStamp() { 088 return vid.getTimeStamp(); 089 } 090 091 @Override 092 public double getFPS() { 093 return vid.getFPS(); 094 } 095 096 @Override 097 public boolean hasNextFrame() { 098 return vid.hasNextFrame(); 099 } 100 101 @Override 102 public long countFrames() { 103 return vid.countFrames(); 104 } 105 106 @Override 107 public void reset() { 108 vid.reset(); 109 } 110 111}