1 /**
2 * Copyright (c) 2011, The University of Southampton and the individual contributors.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * * Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * * Neither the name of the University of Southampton nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 package org.openimaj.tools.imagecollection.collection;
31
32 import java.io.File;
33 import java.io.FileOutputStream;
34 import java.io.IOException;
35 import java.io.InputStream;
36
37 import org.junit.Before;
38 import org.junit.Rule;
39 import org.junit.Test;
40 import org.junit.rules.TemporaryFolder;
41 import org.openimaj.tools.imagecollection.collection.video.YouTubeVideoImageCollection;
42 import org.openimaj.video.xuggle.XuggleVideoWriter;
43
44 public class XuggleVideoImageCollectionTest {
45 @Rule
46 public TemporaryFolder folder = new TemporaryFolder();
47
48 String aVideo = "/org/openimaj/video/data/a_video.avi";
49 private File videoFile;
50
51 // private ImageCollectionConfig fileConfig;
52 // private ImageCollectionConfig urlConfig;
53
54 @Before
55 public void setup() throws IOException {
56 final InputStream s = XuggleVideoImageCollectionTest.class.getResourceAsStream(aVideo);
57 videoFile = folder.newFile("xuggle.avi");
58
59 final FileOutputStream fos = new FileOutputStream(videoFile);
60 int read = 0;
61 final byte[] buffer = new byte[1024];
62 while ((read = s.read(buffer)) != -1) {
63 fos.write(buffer, 0, read);
64 }
65 fos.close();
66 // final String jsonVideoFile = String.format("{video:{file:\"%s\"}}",
67 // videoFile);
68 // final String jsonVideoURL = String.format("{video:{url:\"%s\"}}",
69 // videoFile);
70
71 // fileConfig = new ImageCollectionConfig(jsonVideoFile);
72 // urlConfig = new ImageCollectionConfig(jsonVideoURL);
73 }
74
75 @Test
76 public void testURLFileXuggleVideoImageCollection() throws ImageCollectionSetupException {
77 // try{
78 // FromFile fileVideo = new XuggleVideoImageCollection.FromFile();
79 // fileVideo.setup(fileConfig);
80 // List<ImageCollectionEntry<MBFImage>> fileFrames = fileVideo.getAll();
81 // FromURL urlVideo = new XuggleVideoImageCollection.FromURL();
82 // urlVideo.setup(urlConfig);
83 // List<ImageCollectionEntry<MBFImage>> urlFrames = urlVideo.getAll();
84 // assertTrue(urlFrames.size() > 0);
85 // assertEquals(urlFrames.size(),fileFrames.size());
86 // }
87 // catch(UnsatisfiedLinkError e){
88 //
89 // }
90
91 }
92
93 @Test
94 public void testYouTubeVideoImageCollection() throws ImageCollectionSetupException {
95 // try{
96 // String youtubeURLStr = "http://www.youtube.com/watch?v=QP9p_XkCR68";
97 // String youtubeJSON =
98 // String.format("{video:{url:\"%s\"}}",youtubeURLStr);
99 // ImageCollectionConfig youtubeConfig = new
100 // ImageCollectionConfig(youtubeJSON);
101 //
102 // YouTubeVideoImageCollection col = new YouTubeVideoImageCollection();
103 // col.setup(youtubeConfig);
104 //
105 // int i = 0;
106 // for(@SuppressWarnings("unused") ImageCollectionEntry<MBFImage> im :
107 // col){
108 // if(i++ > 10) return;
109 //
110 // }
111 // }
112 // catch(UnsatisfiedLinkError e){
113 //
114 // }
115 // catch(NoClassDefFoundError e){
116 //
117 // }
118 }
119
120 public static void main(String[] args) throws ImageCollectionSetupException {
121 final String youtubeURLStr = "http://www.youtube.com/watch?v=QP9p_XkCR68";
122 final YouTubeVideoImageCollection col = new YouTubeVideoImageCollection(youtubeURLStr);
123 final XuggleVideoWriter io = new XuggleVideoWriter("/Users/ss/Desktop/xuggleout.mpg", col.video.getWidth(),
124 col.video.getHeight(), col.video.getFPS());
125 io.process(col.video);
126 }
127 }