Use the workbench for video processing.

Patch submitted by Kushal
This commit is contained in:
Rodney Ewing 2013-08-07 15:31:40 -07:00
parent 316ede4705
commit 2ed6afb048

View File

@ -14,7 +14,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from tempfile import NamedTemporaryFile import os.path
import logging import logging
import datetime import datetime
@ -73,79 +73,77 @@ def process_video(proc_state):
queued_filename = proc_state.get_queued_filename() queued_filename = proc_state.get_queued_filename()
name_builder = FilenameBuilder(queued_filename) name_builder = FilenameBuilder(queued_filename)
medium_filepath = create_pub_filepath( medium_basename = name_builder.fill('{basename}-640p.webm')
entry, name_builder.fill('{basename}-640p.webm')) medium_filepath = create_pub_filepath(entry, medium_basename)
thumbnail_filepath = create_pub_filepath( thumbnail_basename = name_builder.fill('{basename}.thumbnail.jpg')
entry, name_builder.fill('{basename}.thumbnail.jpg')) thumbnail_filepath = create_pub_filepath(entry, thumbnail_basename)
# Create a temporary file for the video destination (cleaned up with workbench) # Create a temporary file for the video destination (cleaned up with workbench)
tmp_dst = NamedTemporaryFile(dir=workbench.dir, delete=False) tmp_dst = os.path.join(workbench.dir, medium_basename)
with tmp_dst: # Transcode queued file to a VP8/vorbis file that fits in a 640x640 square
# Transcode queued file to a VP8/vorbis file that fits in a 640x640 square progress_callback = ProgressCallback(entry)
progress_callback = ProgressCallback(entry)
dimensions = ( dimensions = (
mgg.global_config['media:medium']['max_width'], mgg.global_config['media:medium']['max_width'],
mgg.global_config['media:medium']['max_height']) mgg.global_config['media:medium']['max_height'])
# Extract metadata and keep a record of it # Extract metadata and keep a record of it
metadata = transcoders.VideoTranscoder().discover(queued_filename) metadata = transcoders.VideoTranscoder().discover(queued_filename)
store_metadata(entry, metadata) store_metadata(entry, metadata)
# Figure out whether or not we need to transcode this video or # Figure out whether or not we need to transcode this video or
# if we can skip it # if we can skip it
if skip_transcode(metadata): if skip_transcode(metadata):
_log.debug('Skipping transcoding') _log.debug('Skipping transcoding')
dst_dimensions = metadata['videowidth'], metadata['videoheight'] dst_dimensions = metadata['videowidth'], metadata['videoheight']
# Push original file to public storage # Push original file to public storage
_log.debug('Saving original...') _log.debug('Saving original...')
proc_state.copy_original(queued_filepath[-1]) proc_state.copy_original(queued_filepath[-1])
did_transcode = False did_transcode = False
else: else:
transcoder = transcoders.VideoTranscoder() transcoder = transcoders.VideoTranscoder()
transcoder.transcode(queued_filename, tmp_dst.name, transcoder.transcode(queued_filename, tmp_dst,
vp8_quality=video_config['vp8_quality'], vp8_quality=video_config['vp8_quality'],
vp8_threads=video_config['vp8_threads'], vp8_threads=video_config['vp8_threads'],
vorbis_quality=video_config['vorbis_quality'], vorbis_quality=video_config['vorbis_quality'],
progress_callback=progress_callback, progress_callback=progress_callback,
dimensions=dimensions) dimensions=dimensions)
dst_dimensions = transcoder.dst_data.videowidth,\ dst_dimensions = transcoder.dst_data.videowidth,\
transcoder.dst_data.videoheight transcoder.dst_data.videoheight
# Push transcoded video to public storage # Push transcoded video to public storage
_log.debug('Saving medium...') _log.debug('Saving medium...')
mgg.public_store.copy_local_to_storage(tmp_dst.name, medium_filepath) mgg.public_store.copy_local_to_storage(tmp_dst, medium_filepath)
_log.debug('Saved medium') _log.debug('Saved medium')
entry.media_files['webm_640'] = medium_filepath entry.media_files['webm_640'] = medium_filepath
did_transcode = True did_transcode = True
# Save the width and height of the transcoded video # Save the width and height of the transcoded video
entry.media_data_init( entry.media_data_init(
width=dst_dimensions[0], width=dst_dimensions[0],
height=dst_dimensions[1]) height=dst_dimensions[1])
# Temporary file for the video thumbnail (cleaned up with workbench) # Temporary file for the video thumbnail (cleaned up with workbench)
tmp_thumb = NamedTemporaryFile(dir=workbench.dir, suffix='.jpg', delete=False) tmp_thumb = os.path.join(workbench.dir, thumbnail_basename)
with tmp_thumb: # Create a thumbnail.jpg that fits in a 180x180 square
# Create a thumbnail.jpg that fits in a 180x180 square transcoders.VideoThumbnailerMarkII(
transcoders.VideoThumbnailerMarkII( queued_filename,
queued_filename, tmp_thumb,
tmp_thumb.name, 180)
180)
# Push the thumbnail to public storage # Push the thumbnail to public storage
_log.debug('Saving thumbnail...') _log.debug('Saving thumbnail...')
mgg.public_store.copy_local_to_storage(tmp_thumb.name, thumbnail_filepath) mgg.public_store.copy_local_to_storage(tmp_thumb, thumbnail_filepath)
entry.media_files['thumb'] = thumbnail_filepath entry.media_files['thumb'] = thumbnail_filepath
# save the original... but only if we did a transcoding # save the original... but only if we did a transcoding
# (if we skipped transcoding and just kept the original anyway as the main # (if we skipped transcoding and just kept the original anyway as the main