offs = pre_capture / framerate
offs = max(4, offs * 2)
- logging.debug('creating movie preview for %(path)s with an offset of %(offs)s seconds ...' % {
+ logging.debug('creating movie preview for %(path)s with an offset of %(offs)s seconds...' % {
'path': full_path, 'offs': offs})
- cmd = 'ffmpeg -i "%(path)s" -f mjpeg -vframes 1 -ss %(offs)s -y %(path)s.thumb' % {
- 'path': full_path, 'offs': offs}
+ cmd = 'ffmpeg -i "%(path)s" -f mjpeg -vframes 1 -ss %(offs)s -y %(path)s.thumb'
try:
- subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
+ subprocess.check_output(cmd % {'path': full_path, 'offs': offs}, shell=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
logging.error('failed to create movie preview for %(path)s: %(msg)s' % {
return None
+ if os.path.getsize(full_path + '.thumb') == 0:
+ logging.debug('movie was too short, grabbing first frame from %(path)s...' % {'path': full_path})
+
+ # try again, this time grabbing the very first frame
+ try:
+ subprocess.check_output(cmd % {'path': full_path, 'offs': 0}, shell=True, stderr=subprocess.STDOUT)
+
+ except subprocess.CalledProcessError as e:
+ logging.error('failed to create movie preview for %(path)s: %(msg)s' % {
+ 'path': full_path, 'msg': unicode(e)})
+
+ return None
+
return full_path + '.thumb'
mediaListDiv.append(entryDiv);
});
- setTimeout(function () {
- mediaListDiv.find('img.media-list-preview').each(function () {
- if (this._src) {
- this.src = this._src;
- }
-
- delete this._src;
- });
- }, 1000);
+ mediaListDiv.scroll();
});
}
groupsDiv.append(groupButton);
});
-
- showGroup(keys[0]);
}
else {
groupsDiv.html('(no media files)');
buttons: '',
content: dialogDiv,
onShow: function () {
- dialogDiv.scrollTop(dialogDiv.prop('scrollHeight'));
+ //dialogDiv.scrollTop(dialogDiv.prop('scrollHeight'));
+ if (keys.length) {
+ showGroup(keys[0]);
+ }
+ }
+ });
+ });
+
+ /* install the media list scroll event handler */
+ mediaListDiv.scroll(function () {
+ var height = mediaListDiv.height();
+
+ mediaListDiv.find('img.media-list-preview').each(function () {
+ if (!this._src) {
+ return;
+ }
+
+ var $this = $(this);
+ var entryDiv = $this.parent();
+ if (!entryDiv.is(':visible')) {
+ return;
+ }
+
+ var top1 = entryDiv.position().top;
+ var top2 = top1 + entryDiv.height();
+
+ if ((top1 >= 0 && top1 <= height) ||
+ (top2 >= 0 && top2 <= height)) {
+
+ this.src = this._src;
+ delete this._src;
}
});
});