def transcode(self, media_file): """Transcode an existing MediaFile. The MediaFile may be stored already by another storage engine. New MediaFiles will be created for each transcoding generated by this method. :type media_file: :class:`~mediacore.model.media.MediaFile` :param media_file: The MediaFile object to transcode. :raises CannotTranscode: If this storage engine can't or won't transcode the file. :rtype: NoneType :returns: Nothing """ if isinstance(media_file.storage, PandaStorage): return profile_names = self._data[PANDA_PROFILES] if not profile_names \ or media_file.type != VIDEO \ or not download_uri(media_file): raise CannotTranscode panda_helper = self.panda_helper() state_update_url = url_for( controller='/panda/admin/media', action='panda_update', file_id=media_file.id, qualified=True ) # We can only tell panda to encode this video once the transaction has # been committed, otherwise panda get's a 404 when they try to download # the file from us. def transcode(): try: panda_helper.transcode_media_file(media_file, profile_names, state_update_url=state_update_url) except PandaException, e: log.exception(e)
def transcode_media_file(self, media_file, profile_ids, state_update_url=None): uri = download_uri(media_file) if not uri: raise PandaException('Cannot transcode because no download URL exists.') transcode_details = self.client.transcode_file(str(uri), profile_ids, state_update_url) self.associate_video_id(media_file, transcode_details['id'])