conduit r1247 - in trunk: . conduit/datatypes conduit/modules
- From: jstowers svn gnome org
- To: svn-commits-list gnome org
- Subject: conduit r1247 - in trunk: . conduit/datatypes conduit/modules
- Date: Fri, 18 Jan 2008 23:40:29 +0000 (GMT)
Author: jstowers
Date: Fri Jan 18 23:40:28 2008
New Revision: 1247
URL: http://svn.gnome.org/viewvc/conduit?rev=1247&view=rev
Log:
2008-01-19 John Stowers <john stowers gmail com>
* conduit/datatypes/Video.py:
* conduit/modules/AudioVideoConverterModule.py: Be more robust with
audio/video mimetype dectection and conversion
Modified:
trunk/ChangeLog
trunk/conduit/datatypes/Video.py
trunk/conduit/modules/AudioVideoConverterModule.py
Modified: trunk/conduit/datatypes/Video.py
==============================================================================
--- trunk/conduit/datatypes/Video.py (original)
+++ trunk/conduit/datatypes/Video.py Fri Jan 18 23:40:28 2008
@@ -1,8 +1,12 @@
import conduit
import conduit.datatypes.File as File
+#The preset encodings must be robust. That means, in the case of ffmpeg,
+#you must be explicit with the options, otherwise it tries to retain sample
+#rates between the input and output files, leading to invalid rates in the output
PRESET_ENCODINGS = {
- "divx":{"vcodec":"mpeg4","acodec":"ac3","format":"avi","vtag":"DIVX","file_extension":"avi"},
+ "divx":{"vcodec":"mpeg4","acodec":"ac3","arate":44100,"abitrate":"64k","format":"avi","vtag":"DIVX","file_extension":"avi", "fps":15},
+ #breaks on single channel audio files because ffmpeg vorbis encoder only suuport stereo
"ogg":{"vcodec":"theora","acodec":"vorbis","format":"ogg","file_extension":"ogg"},
#needs mencoder or ffmpeg compiled with mp3 support
"flv":{"arate":22050,"abitrate":32,"format":"flv","acodec":"mp3","mencoder":True,"file_extension":"flv"}
Modified: trunk/conduit/modules/AudioVideoConverterModule.py
==============================================================================
--- trunk/conduit/modules/AudioVideoConverterModule.py (original)
+++ trunk/conduit/modules/AudioVideoConverterModule.py Fri Jan 18 23:40:28 2008
@@ -36,9 +36,7 @@
#audio options
if kwargs.get('acodec', None): command += "-acodec %(acodec)s "
if kwargs.get('arate', None): command += "-ar %(arate)s "
- if kwargs.get('abitrate', None):
- if kwargs.get('acodec', None) != 'ac3':
- command += "-ab %(abitrate)s "
+# if kwargs.get('abitrate', None): command += "-ab %(abitrate)s "
if kwargs.get('achannels', None): command += "-ac %(achannels)s "
#output file, overwrite and container format
if kwargs.get('format', None): command += "-f %(format)s "
@@ -91,6 +89,15 @@
return conduit.GLOBALS.cancelled
class AudioVideoConverter:
+
+ #These commands are run to determine attributes about the file
+ #(such as size and duration) prior to transcode. They should be
+ #Robust and work with ALL input files, even if the transode step may
+ #later fail
+
+ VIDEO_INSPECT_COMMAND = 'ffmpeg -an -y -t 0:0:0.001 -i "%s" -f image2 "%s" 2>&1'
+ AUDIO_INSPECT_COMMAND = 'ffmpeg -fs 1 -y -i "%s" -f wav "%s" 2>&1'
+
def __init__(self):
self.conversions = {
"file/video,file/video" : self.transcode_video,
@@ -98,16 +105,31 @@
"file/audio,file/audio" : self.transcode_audio,
"file,file/audio" : self.file_to_audio
}
+
+ def _is_video(self, f):
+ mimetype = f.get_mimetype()
+ if mimetype.startswith("video/"):
+ return True
+ elif mimetype == "application/ogg":
+ return True
+ else:
+ log.debug("File is not video type: %s" % mimetype)
+
+ def _is_audio(self, f):
+ mimetype = f.get_mimetype()
+ if mimetype.startswith("audio/"):
+ return True
+ else:
+ log.debug("File is not audio type: %s" % mimetype)
def transcode_video(self, video, **kwargs):
- if not video.get_mimetype().startswith("video/"):
- log.debug("File is not video type")
+ if not self._is_video(video):
return None
input_file = video.get_local_uri()
#run ffmpeg over the video to work out its format, and duration
c = Utils.CommandLineConverter()
- c.build_command('ffmpeg -fs 1 -y -i "%s" -f avi "%s" 2>&1')
+ c.build_command(AudioVideoConverter.VIDEO_INSPECT_COMMAND)
ok,output = c.convert(input_file,"/dev/null",save_output=True)
if not ok:
@@ -159,14 +181,13 @@
return video
def transcode_audio(self, audio, **kwargs):
- if not audio.get_mimetype().startswith("audio/"):
- log.debug("File is not audio type")
+ if not self._is_audio(audio):
return None
input_file = audio.get_local_uri()
#run ffmpeg over the video to work out its format, and duration
c = Utils.CommandLineConverter()
- c.build_command('ffmpeg -fs 1 -y -i "%s" -f wav "%s" 2>&1')
+ c.build_command(AudioVideoConverter.AUDIO_INSPECT_COMMAND)
ok,output = c.convert(input_file,"/dev/null",save_output=True)
if not ok:
@@ -207,8 +228,7 @@
return audio
def file_to_audio(self, f, **kwargs):
- t = f.get_mimetype()
- if t.startswith("audio/"):
+ if self._is_audio(f):
a = Audio.Audio(
URI=f._get_text_uri()
)
@@ -221,8 +241,7 @@
return None
def file_to_video(self, f, **kwargs):
- t = f.get_mimetype()
- if t.startswith("video/"):
+ if self._is_video(f):
v = Video.Video(
URI=f._get_text_uri()
)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]