# HG changeset patch # User esr # Date 1406064172 18000 # Node ID b6466fff5800774f4817fcdbf82d4230c2a236cb Initial version diff -r 000000000000 -r b6466fff5800 video_datatypes/datatypes_conf.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/video_datatypes/datatypes_conf.xml Tue Jul 22 16:22:52 2014 -0500 @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff -r 000000000000 -r b6466fff5800 video_datatypes/readme.rst --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/video_datatypes/readme.rst Tue Jul 22 16:22:52 2014 -0500 @@ -0,0 +1,43 @@ +Video Datatypes +=============== + +Please feel free to submit PRs/bug reports. + +Requirements +============ + +Requires ffmpeg for fps/resolution detection + +:: + + sudo apt-get install ffmpeg + +Formats Supported +================= + +- mp4 +- flv + +Features +======== + +- Metadata is sourced for video resolution and fps. +- Sniffing is currently unavailable + +Licence +======= + +Video datatypes for Galaxy Copyright (C) 2014 Eric Rasche + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation, either version 3 of the License, or (at your +option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see http://www.gnu.org/licenses/. diff -r 000000000000 -r b6466fff5800 video_datatypes/video.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/video_datatypes/video.py Tue Jul 22 16:22:52 2014 -0500 @@ -0,0 +1,72 @@ +""" +Video classes +""" + +import logging +#import magic +import subprocess, re + +import data +from galaxy.datatypes.binary import Binary +from galaxy.datatypes.metadata import MetadataElement +log = logging.getLogger(__name__) + +# Currently these supported binary data types must be manually set on upload + +#class Video( data.Data ): +class Video( Binary ): + + MetadataElement( name="resolution_x", default=0, desc="Width of video stream", readonly=True, visible=True, optional=True, no_value=0 ) + MetadataElement( name="resolution_y", default=0, desc="Height of video stream", readonly=True, visible=True, optional=True, no_value=0 ) + MetadataElement( name="fps", default=0, desc="FPS of video stream", readonly=True, visible=True, optional=True, no_value=0 ) + + def _get_resolution(self, filename): + video_stream = re.compile(r'Stream #(?P\d+)\.(?P\d+).*: Video: (?P[^,]*), (?P[^,]*), (?P\d+)x(?P\d+) [^,]*, (?P\d+) (?P.b/s), (?P\d+) fps') + audio_stream= re.compile(r'Stream #(?P\d+)\.(?P\d+).*: Audio: (?P[^,]*), (?P\d+)Hz, (?P[^,]+), [^,]*, (?P\d+) (?P.b/s)') + #Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/esr/Documents/galaxy-galaxy-dist-d3b1f484c4b6/Juli - Elektrisches Gefhl-ft8DwXUxaB8.mp4': + #Metadata: + #major_brand : mp42 + #minor_version : 0 + #compatible_brands: isommp42 + #creation_time : 2014-03-07 06:55:07 + #Duration: 00:03:43.81, start: 0.000000, bitrate: 555 kb/s + #Stream #0.0(und): Video: h264 (Constrained Baseline), yuv420p, 480x360 [PAR 1:1 DAR 4:3], 457 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc + #Stream #0.1(und): Audio: aac, 44100 Hz, stereo, s16, 95 kb/s + #Metadata: + #creation_time : 2014-03-07 06:55:07 + + + p = subprocess.Popen(['ffmpeg', '-i', filename], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = p.communicate() + match = video_stream.search(stderr) + if match: + x = match.group('resx') + y = match.group('resy') + fps = match.group('fps') + else: + x = y = fps = 0 + return x, y, fps + + def set_meta(self, dataset, **kwd): + (x, y, fps) = self._get_resolution( dataset.file_name ) + dataset.metadata.resolution_y = y + dataset.metadata.resolution_x = x + dataset.metadata.fps = fps + +class Mp4( Video ): + file_ext = "mp4" + + def sniff(self, filename): + with magic.Magic(flags=magic.MAGIC_MIME_TYPE) as m: + return m.id_filename(filename) is 'video/mp4' +Binary.register_unsniffable_binary_ext("mp4") + +class Flv( Video ): + file_ext = "flv" + + def sniff(self, filename): + with magic.Magic(flags=magic.MAGIC_MIME_TYPE) as m: + return m.id_filename(filename) is 'video/x-flv' + +Binary.register_unsniffable_binary_ext("flv")