Video Embed & Thumbnail Generator - Version 4.6.22

Version Description

  • January 30, 2019 =
  • Modularized video file formats that can be encoded by the plugin to allow other plugins to modify, delete, or create new formats.
  • Added Custom WEBM VP9 format option.
  • Renamed WEBM format to WEBM VP8.
  • Fixed bug that deleted unfinished video encode queue entries every 24 hours.
  • Fixed bug that created duplicate encodes of non-H.264 files in some situations.
  • Fixed bug that inconsistently prevented thumbnail generation in the Media Library.
  • Fixed bug that disabled embed from URL "insert into post" button if FFMPEG was not set up on server.
  • Stopped appending timecode numbers to thumbnail filenames.
  • Stopped removing special characters from the end of filenames of generated thumbnails and encoded files.
  • Attempting to fix misconfigured locale settings that can sometimes cause video files with diacritics (accent marks, umlauts, etc) to generate "File not found" errors when using FFMPEG.
  • Removed old Media Library video thumbnail display functionality that was preventing some Media Libraries from loading.
  • Now allowing https FFMPEG input.
Download this release

Release Info

Developer kylegilman
Plugin Icon 128x128 Video Embed & Thumbnail Generator
Version 4.6.22
Comparing to
See all releases

Code changes from version 4.6.21 to 4.6.22

js/kgvid_video_plugin_admin.js CHANGED
@@ -119,7 +119,7 @@ function kgvid_thumb_video_loaded(postID) { //sets up mini custom player for mak
119
  ed_media.on( 'escape',
120
  function(postID) {
121
  return function() {
122
- if ( jQuery('#show-thumb-video-'+postID+' :nth-child(2)').html() == kgvidL10n.hidevideo ) {
123
  kgvid_reveal_thumb_video(postID);
124
  }
125
  //kgvid_break_video_on_close(postID);
@@ -131,6 +131,7 @@ function kgvid_thumb_video_loaded(postID) { //sets up mini custom player for mak
131
  video.removeAttribute('height'); //disables changes made by mejs
132
  video.removeAttribute('style');
133
  video.setAttribute('width', '200');
 
134
 
135
  var playButton = jQuery(".kgvid-play-pause");
136
  var seekBar = jQuery(".kgvid-seek-bar");
@@ -300,23 +301,35 @@ function kgvid_reveal_video_stats(postID) {
300
 
301
  }
302
 
303
- function kgvid_reveal_thumb_video(postID) {
304
 
305
- jQuery('#show-thumb-video-'+postID+' :first').toggleClass( 'kgvid-down-arrow kgvid-right-arrow' );
306
- var text = jQuery('#show-thumb-video-'+postID+' :nth-child(2)');
307
- video = document.getElementById('thumb-video-'+postID);
 
 
 
 
 
 
 
308
 
309
- if ( text.html() == kgvidL10n.choosefromvideo ) { //video is being revealed
310
 
311
- if ( jQuery('#thumb-video-'+postID+'-player .mejs-container').attr('id') !== undefined ) { //this is the Media Library pop-up introduced in WordPress 4.0;
312
 
313
- jQuery('#thumb-video-'+postID+'-player .mejs-container .mejs-layers, #thumb-video-'+postID+'-player .mejs-container .mejs-controls').remove();
314
 
 
 
315
 
316
- }
317
 
 
 
 
318
  jQuery(video).data('busy', true);
319
- jQuery(video).removeAttr('src');
320
  jQuery(video).attr("preload", "metadata");
321
  video.load();
322
 
@@ -344,6 +357,7 @@ function kgvid_reveal_thumb_video(postID) {
344
  }
345
  else if ( text.html() == kgvidL10n.hidevideo ) { //video is being hidden
346
 
 
347
  video.pause();
348
  jQuery('#thumb-video-'+postID).off('timeupdate.kgvid');
349
  kgvid_break_video_on_close(postID);
@@ -384,19 +398,21 @@ function kgvid_generate_thumb(postID, buttonPushed) {
384
  var widthID = 'attachments-'+postID+'-kgflashmediaplayer-width';
385
  var heightID = 'attachments-'+postID+'-kgflashmediaplayer-height';
386
  var maxwidthID = 'attachments['+postID+'][kgflashmediaplayer-maxwidth]';
387
- var maxheightID = 'attachments['+postID+'][kgflashmediaplayer-maxheight]';
388
- var i=1;
389
  var increaser = 0;
390
  var iincreaser = 0;
391
  var page = "attachment";
 
 
 
392
 
393
- if ( jQuery('#thumb-video-'+postID).data('allowed') == "on" ) {
394
 
395
- video = document.getElementById('thumb-video-'+postID);
396
 
397
  if ( video.preload == "none" ) {
398
 
399
- jQuery(video).removeAttr('src');
400
  video.preload = "metadata";
401
  video.load();
402
  jQuery(video).data('busy', true);
@@ -412,7 +428,7 @@ function kgvid_generate_thumb(postID, buttonPushed) {
412
 
413
  setTimeout(function(){ //wait for video to start loading
414
 
415
- video = document.getElementById('thumb-video-'+postID);
416
 
417
  if ( jQuery(video).data('success') == false ) {
418
 
@@ -493,7 +509,7 @@ function kgvid_generate_thumb(postID, buttonPushed) {
493
  var video_aspect = video_height/video_width;
494
  var thumbnails = [];
495
 
496
- jQuery('#thumb-video-'+postID).on('seeked.kgvid', function(){ //when the video is finished seeking
497
 
498
  var thumbnail_saved = jQuery(video).data('thumbnail_data');
499
  if ( thumbnail_saved.length > 0 ) { //if there are any thumbnails that haven't been generated
@@ -501,9 +517,8 @@ function kgvid_generate_thumb(postID, buttonPushed) {
501
  if ( video.paused == false ) { video.pause(); }
502
 
503
  time_id = Math.round(video.currentTime*100);
504
- var time_display = kgvid_convert_to_timecode(video.currentTime);
505
 
506
- jQuery(thumbnailboxID).append('<div style="display:none;" class="kgvid_thumbnail_select" name="attachments['+postID+'][thumb'+time_id+']" id="attachments-'+postID+'-thumb'+time_id+'"><label for="kgflashmedia-'+postID+'-thumbradio'+time_id+'"><canvas class="kgvid_thumbnail" style="width:200px;height:'+Math.round(200*video_aspect)+'px;" id="'+postID+'_thumb_'+time_id+'"></canvas></label><br /><input type="radio" name="attachments['+postID+'][thumbradio'+time_id+']" id="kgflashmedia-'+postID+'-thumbradio'+time_id+'" value="'+video.currentTime+'" onchange="document.getElementById(\'attachments-'+postID+'-kgflashmediaplayer-thumbtime\').value = \''+time_display+'\'; document.getElementById(\'attachments-'+postID+'-kgflashmediaplayer-numberofthumbs\').value =\'1\';kgvid_save_canvas_thumb(\''+postID+'\', \''+time_id+'\', 1, 1);"></div>');
507
  var canvas = document.getElementById(postID+'_thumb_'+time_id);
508
  canvas = kgvid_draw_thumb_canvas(canvas, video);
509
  jQuery('#attachments-'+postID+'-thumb'+time_id).animate({opacity: 'toggle', height: 'toggle', width: 'toggle'}, 1000);
@@ -546,8 +561,13 @@ function kgvid_generate_thumb(postID, buttonPushed) {
546
  var thumbtimecode = kgvid_convert_from_timecode(specifictimecode);
547
  thumbnails = [thumbtimecode];
548
  }
 
549
  video.play();
550
- video.currentTime = thumbnails[0];
 
 
 
 
551
  jQuery(video).data('thumbnail_data', thumbnails);
552
 
553
  }
@@ -573,33 +593,22 @@ function kgvid_select_thumbnail(thumb_url, post_id, movieoffset, thumbnail) {
573
  unscaledThumb.src = thumbnail.src;
574
  var canvas = document.createElement("canvas");
575
  canvas = kgvid_draw_thumb_canvas(canvas, unscaledThumb);
576
- var thumb_url = canvas.toDataURL('image/jpeg', 0.8);
577
 
578
- kgvid_change_media_library_video_poster(post_id, thumb_url);
579
-
580
- /* this breaks the media modal
581
- setTimeout( function() {
582
- if(wp.media.frame.content.get()!==null){
583
- wp.media.frame.content.get().collection.props.set({ignore: (+ new Date())});
584
- }
585
- else{
586
- wp.media.frame.library.props.set({ignore: (+ new Date())});
587
- }
588
- }, 2000); */
589
 
590
  var time_display = kgvid_convert_to_timecode(movieoffset);
591
  jQuery('#attachments-'+post_id+'-kgflashmediaplayer-thumbtime').val(time_display);
592
  jQuery('#attachments-'+post_id+'-kgflashmediaplayer-numberofthumbs').val('1');
593
 
594
-
595
  }
596
 
597
  function kgvid_change_media_library_video_poster(post_id, thumb_url) {
598
 
599
- if ( jQuery('div[data-id='+post_id+'] .wp-video-shortcode video').length > 0 ) {
600
- jQuery('div[data-id='+post_id+'] .mejs-poster').css('background-image', 'url("'+thumb_url+'")');
601
- jQuery('div[data-id='+post_id+'] .mejs-poster img').attr('src', thumb_url);
602
- jQuery('div[data-id='+post_id+'] .wp-video-shortcode video').attr('poster', thumb_url);
603
  }
604
 
605
  }
@@ -619,12 +628,19 @@ function kgvid_save_canvas_thumb(postID, time_id, total, index) {
619
  jQuery.ajax({
620
  type: "POST",
621
  url: ajaxurl,
622
- data: { action:"kgvid_save_html5_thumb", security: kgflashmediaplayersecurity, url: video_url, offset: time_id, postID: postID, total: total, index: index, raw_png: png64dataURL }
 
623
  })
624
- .done( function(thumb_url) {
625
  if ( total == 1 ) {
626
  document.getElementsByName('attachments['+postID+'][kgflashmediaplayer-autothumb-error]')[0].value = '';
627
- jQuery('#attachments-'+postID+'-kgflashmediaplayer-poster').val(thumb_url).change();
 
 
 
 
 
 
628
  if ( typeof pagenow === 'undefined' || pagenow == 'attachment' ) { jQuery('#publish').click(); }
629
  kgvid_change_media_library_video_poster(postID, png64dataURL);
630
  }
@@ -632,16 +648,6 @@ function kgvid_save_canvas_thumb(postID, time_id, total, index) {
632
  kgvid_thumbnail_saveall_progress(postID, total);
633
  }
634
 
635
- /* this breaks the media modal
636
- setTimeout( function() {
637
- if(wp.media.frame.content.get()!==null){
638
- wp.media.frame.content.get().collection.props.set({ignore: (+ new Date())});
639
- }
640
- else{
641
- wp.media.frame.library.props.set({ignore: (+ new Date())});
642
- }
643
- }, 2000); */
644
-
645
  })
646
  .fail( function(xhr, textStatus, errorThrown) {
647
  document.getElementsByName('attachments['+postID+'][kgflashmediaplayer-autothumb-error]')[0].value = errorThrown;
@@ -740,6 +746,24 @@ function kgvid_thumb_video_manual(postID) {
740
 
741
 
742
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
743
  }
744
 
745
  function kgvid_enqueue_video_encode(postID, blogID) {
@@ -761,15 +785,7 @@ function kgvid_enqueue_video_encode(postID, blogID) {
761
  page = "queue";
762
  }
763
 
764
- var formats = new Array("fullres", "1080", "720", "480", "mobile", "ogg", "webm", "vp9", "custom");
765
- var kgvid_encode = new Object();
766
- jQuery.each(formats, function(key,formats) {
767
- kgvid_encode[formats] = "";
768
- if ( jQuery('#attachments-'+blog.id_text+postID+'-kgflashmediaplayer-encode'+formats).length > 0) {
769
- kgvid_encode[formats] = document.getElementById('attachments-'+blog.id_text+postID+'-kgflashmediaplayer-encode'+formats).checked;
770
- }
771
- });
772
- JSON.stringify(kgvid_encode);
773
 
774
  jQuery(encodeplaceholderid).empty();
775
  jQuery(encodeprogressplaceholderid).empty();
@@ -811,9 +827,8 @@ function kgvid_change_singleurl(url, basename, oldbasename) {
811
  });
812
  jQuery('#kgflashmediaplayer-table').data("kgvid_attachment_id", basename);
813
  jQuery('#attachments-'+oldbasename+'-kgflashmediaplayer-encodeboxes').attr('id', 'attachments-'+basename+'-kgflashmediaplayer-encodeboxes');
814
- document.getElementById('attachments-'+oldbasename+'-thumbnailplaceholder').id = 'attachments-'+basename+'-thumbnailplaceholder';
815
- //document.getElementById('attachments-'+basename+'-thumbnailplaceholder').setAttribute("onchange", "document.getElementById('attachments-"+basename+"-kgflashmediaplayer-thumbtime').value='';");
816
- document.getElementById('attachments-'+basename+'-kgflashmediaplayer-numberofthumbs').setAttribute("onchange", "document.getElementById('attachments-"+basename+"-kgflashmediaplayer-thumbtime').value='';");
817
  jQuery('#attachments-'+basename+'-thumbgenerate').replaceWith('<input disabled="disabled" type="button" id="attachments-'+basename+'-thumbgenerate" class="button-secondary" value="'+kgvidL10n.generate+'" name="thumbgenerate" onclick="kgvid_generate_thumb(\''+basename+'\', \'generate\');" >');
818
  jQuery('#attachments-'+basename+'-thumbrandomize').replaceWith('<input disabled="disabled" type="button" id="attachments-'+basename+'-thumbrandomize" class="button-secondary" value="'+kgvidL10n.randomize+'" name="thumbgenerate" onclick="kgvid_generate_thumb(\''+basename+'\', \'random\');" >');
819
  document.getElementById('attachments-'+basename+'-kgflashmediaplayer-width').setAttribute("onchange", "kgvid_set_dimension('"+basename+"', 'height', this.value);")
@@ -828,13 +843,12 @@ function kgvid_change_singleurl(url, basename, oldbasename) {
828
  document.getElementById('attachments-'+basename+'-thumbgenerate').title = "";
829
  document.getElementById('attachments-'+basename+'-thumbrandomize').disabled = false;
830
  document.getElementById('attachments-'+basename+'-thumbrandomize').title = "";
831
- //document.getElementById('attachments-'+basename+'-kgflashmediaplayer-encode').disabled = false;
832
  document.getElementById('attachments-'+basename+'-kgflashmediaplayer-encode').title = kgvidL10n.loading;
833
 
834
  }
835
  else {
836
- document.getElementById('attachments-'+basename+'-thumbgenerate').title = kgvidL10n.ffmpegnotfound;
837
- document.getElementById('attachments-'+basename+'-thumbrandomize').title = kgvidL10n.ffmpegnotfound;
838
  }
839
  document.getElementById('insertonlybutton').disabled = false;
840
  document.getElementById('insertonlybutton').title = "";
@@ -1151,16 +1165,7 @@ function kgvid_redraw_encode_checkboxes(movieurl, postID, page, blogID) {
1151
 
1152
  if ( kgflashmediaplayersecurity ) { //sometimes this tries to run after the media modal is closed
1153
 
1154
- var formats = new Array("fullres", "1080", "720", "480", "mobile", "ogg", "webm", "vp9", "custom");
1155
- var kgvid_encode = new Object();
1156
-
1157
- jQuery.each(formats, function(key,formats) {
1158
- kgvid_encode[formats] = "";
1159
- if ( jQuery('#attachments-'+blog.id_text+postID+'-kgflashmediaplayer-encode'+formats).length > 0) {
1160
- kgvid_encode[formats] = document.getElementById('attachments-'+blog.id_text+postID+'-kgflashmediaplayer-encode'+formats).checked;
1161
- }
1162
- });
1163
- JSON.stringify(kgvid_encode);
1164
 
1165
  jQuery.post(ajaxurl, { action:"kgvid_generate_encode_checkboxes", security: kgflashmediaplayersecurity, movieurl: movieurl, post_id: postID, page: page, blog_id: blog.ID, encodeformats: kgvid_encode }, function(data) {
1166
  jQuery('#attachments-'+blog.id_text+postID+'-kgflashmediaplayer-encodeboxes').empty();
119
  ed_media.on( 'escape',
120
  function(postID) {
121
  return function() {
122
+ if ( jQuery('#show-thumb-video-'+postID+' .kgvid-show-video').html() == kgvidL10n.hidevideo ) {
123
  kgvid_reveal_thumb_video(postID);
124
  }
125
  //kgvid_break_video_on_close(postID);
131
  video.removeAttribute('height'); //disables changes made by mejs
132
  video.removeAttribute('style');
133
  video.setAttribute('width', '200');
134
+ video.controls = '';
135
 
136
  var playButton = jQuery(".kgvid-play-pause");
137
  var seekBar = jQuery(".kgvid-seek-bar");
301
 
302
  }
303
 
304
+ function kgvid_remove_mejs_player(postID) {
305
 
306
+ if ( jQuery('#thumb-video-'+postID+'-player .mejs-container').attr('id') !== undefined && typeof mejs !== 'undefined' ) { //this is the Media Library pop-up introduced in WordPress 4.0
307
+
308
+ var mejs_id = jQuery('#thumb-video-'+postID+'-player .mejs-container').attr('id');
309
+ var mejs_player = eval('mejs.players.'+mejs_id);
310
+ if ( mejs_player.getSrc() !== null ) {
311
+ if ( !mejs_player.paused ) {
312
+ mejs_player.pause();
313
+ }
314
+ mejs_player.remove();
315
+ }
316
 
317
+ }
318
 
319
+ }
320
 
321
+ function kgvid_reveal_thumb_video(postID) {
322
 
323
+ jQuery('#show-thumb-video-'+postID+' :first').toggleClass( 'kgvid-down-arrow kgvid-right-arrow' );
324
+ var text = jQuery('#show-thumb-video-'+postID+' .kgvid-show-video');
325
 
326
+ if ( text.html() == kgvidL10n.choosefromvideo ) { //video is being revealed
327
 
328
+ kgvid_remove_mejs_player(postID);
329
+
330
+ video = document.getElementById('thumb-video-'+postID);
331
  jQuery(video).data('busy', true);
332
+ video.src = document.getElementsByName('attachments['+postID+'][kgflashmediaplayer-url]')[0].value;
333
  jQuery(video).attr("preload", "metadata");
334
  video.load();
335
 
357
  }
358
  else if ( text.html() == kgvidL10n.hidevideo ) { //video is being hidden
359
 
360
+ video = document.getElementById('thumb-video-'+postID);
361
  video.pause();
362
  jQuery('#thumb-video-'+postID).off('timeupdate.kgvid');
363
  kgvid_break_video_on_close(postID);
398
  var widthID = 'attachments-'+postID+'-kgflashmediaplayer-width';
399
  var heightID = 'attachments-'+postID+'-kgflashmediaplayer-height';
400
  var maxwidthID = 'attachments['+postID+'][kgflashmediaplayer-maxwidth]';
401
+ var i = 1;
 
402
  var increaser = 0;
403
  var iincreaser = 0;
404
  var page = "attachment";
405
+ var video_id = 'thumb-video-'+postID;
406
+
407
+ kgvid_remove_mejs_player(postID);
408
 
409
+ if ( jQuery('#'+video_id).data('allowed') == "on" ) {
410
 
411
+ video = document.getElementById(video_id);
412
 
413
  if ( video.preload == "none" ) {
414
 
415
+ video.src = document.getElementsByName('attachments['+postID+'][kgflashmediaplayer-url]')[0].value;
416
  video.preload = "metadata";
417
  video.load();
418
  jQuery(video).data('busy', true);
428
 
429
  setTimeout(function(){ //wait for video to start loading
430
 
431
+ video = document.getElementById(video_id);
432
 
433
  if ( jQuery(video).data('success') == false ) {
434
 
509
  var video_aspect = video_height/video_width;
510
  var thumbnails = [];
511
 
512
+ jQuery('#'+video_id).on('seeked.kgvid', function(){ //when the video is finished seeking
513
 
514
  var thumbnail_saved = jQuery(video).data('thumbnail_data');
515
  if ( thumbnail_saved.length > 0 ) { //if there are any thumbnails that haven't been generated
517
  if ( video.paused == false ) { video.pause(); }
518
 
519
  time_id = Math.round(video.currentTime*100);
 
520
 
521
+ jQuery(thumbnailboxID).append('<div style="display:none;" class="kgvid_thumbnail_select" name="attachments['+postID+'][thumb'+time_id+']" id="attachments-'+postID+'-thumb'+time_id+'"><label for="kgflashmedia-'+postID+'-thumbradio'+time_id+'"><canvas class="kgvid_thumbnail" style="width:200px;height:'+Math.round(200*video_aspect)+'px;" id="'+postID+'_thumb_'+time_id+'" data-movieoffset="'+video.currentTime+'"></canvas></label><br /><input type="radio" name="attachments['+postID+'][thumbradio'+time_id+']" id="kgflashmedia-'+postID+'-thumbradio'+time_id+'" value="'+video.currentTime+'" onchange="kgvid_save_canvas_thumb(\''+postID+'\', \''+time_id+'\', 1, 1);"></div>');
522
  var canvas = document.getElementById(postID+'_thumb_'+time_id);
523
  canvas = kgvid_draw_thumb_canvas(canvas, video);
524
  jQuery('#attachments-'+postID+'-thumb'+time_id).animate({opacity: 'toggle', height: 'toggle', width: 'toggle'}, 1000);
561
  var thumbtimecode = kgvid_convert_from_timecode(specifictimecode);
562
  thumbnails = [thumbtimecode];
563
  }
564
+
565
  video.play();
566
+
567
+ jQuery(video).on('loadeddata', function(){
568
+ video.currentTime = thumbnails[0];
569
+ });
570
+
571
  jQuery(video).data('thumbnail_data', thumbnails);
572
 
573
  }
593
  unscaledThumb.src = thumbnail.src;
594
  var canvas = document.createElement("canvas");
595
  canvas = kgvid_draw_thumb_canvas(canvas, unscaledThumb);
596
+ var thumb_dataurl = canvas.toDataURL('image/jpeg', 0.8);
597
 
598
+ kgvid_change_media_library_video_poster(post_id, thumb_dataurl);
 
 
 
 
 
 
 
 
 
 
599
 
600
  var time_display = kgvid_convert_to_timecode(movieoffset);
601
  jQuery('#attachments-'+post_id+'-kgflashmediaplayer-thumbtime').val(time_display);
602
  jQuery('#attachments-'+post_id+'-kgflashmediaplayer-numberofthumbs').val('1');
603
 
 
604
  }
605
 
606
  function kgvid_change_media_library_video_poster(post_id, thumb_url) {
607
 
608
+ if ( jQuery('div[data-id='+post_id+'] .wp-video-shortcode.mejs-container').length > 0 && typeof mejs !== 'undefined' ) {
609
+ var mejs_id = jQuery('div[data-id='+post_id+'] .wp-video-shortcode.mejs-container').attr('id');
610
+ var mejs_player = eval('mejs.players.'+mejs_id);
611
+ mejs_player.setPoster(thumb_url);
612
  }
613
 
614
  }
628
  jQuery.ajax({
629
  type: "POST",
630
  url: ajaxurl,
631
+ data: { action:"kgvid_save_html5_thumb", security: kgflashmediaplayersecurity, url: video_url, offset: time_id, postID: postID, total: total, index: index, raw_png: png64dataURL },
632
+ dataType: 'text'
633
  })
634
+ .done( function(data) {
635
  if ( total == 1 ) {
636
  document.getElementsByName('attachments['+postID+'][kgflashmediaplayer-autothumb-error]')[0].value = '';
637
+
638
+ jQuery('#attachments-'+postID+'-kgflashmediaplayer-numberofthumbs').val('1');
639
+
640
+ var time_display = kgvid_convert_to_timecode(canvas.dataset.movieoffset);
641
+ jQuery('#attachments-'+postID+'-kgflashmediaplayer-thumbtime').val(time_display);
642
+
643
+ jQuery('#attachments-'+postID+'-kgflashmediaplayer-poster').val(data).change();
644
  if ( typeof pagenow === 'undefined' || pagenow == 'attachment' ) { jQuery('#publish').click(); }
645
  kgvid_change_media_library_video_poster(postID, png64dataURL);
646
  }
648
  kgvid_thumbnail_saveall_progress(postID, total);
649
  }
650
 
 
 
 
 
 
 
 
 
 
 
651
  })
652
  .fail( function(xhr, textStatus, errorThrown) {
653
  document.getElementsByName('attachments['+postID+'][kgflashmediaplayer-autothumb-error]')[0].value = errorThrown;
746
 
747
 
748
 
749
+ }
750
+
751
+ function kgvid_list_videos_to_encode(postID, blog) {
752
+
753
+ var format_inputs = jQuery('#attachments-'+postID+'-kgflashmediaplayer-encodeboxes input[type=checkbox]');
754
+ var kgvid_encode = new Object();
755
+
756
+ jQuery.each(format_inputs, function(key,el) {
757
+ var format = jQuery(el).data('format');
758
+ kgvid_encode[format] = "";
759
+ if ( jQuery('#attachments-'+blog.id_text+postID+'-kgflashmediaplayer-encode'+format).length > 0) {
760
+ kgvid_encode[format] = document.getElementById('attachments-'+blog.id_text+postID+'-kgflashmediaplayer-encode'+format).checked;
761
+ }
762
+ });
763
+ JSON.stringify(kgvid_encode);
764
+
765
+ return kgvid_encode;
766
+
767
  }
768
 
769
  function kgvid_enqueue_video_encode(postID, blogID) {
785
  page = "queue";
786
  }
787
 
788
+ var kgvid_encode = kgvid_list_videos_to_encode(postID, blog);
 
 
 
 
 
 
 
 
789
 
790
  jQuery(encodeplaceholderid).empty();
791
  jQuery(encodeprogressplaceholderid).empty();
827
  });
828
  jQuery('#kgflashmediaplayer-table').data("kgvid_attachment_id", basename);
829
  jQuery('#attachments-'+oldbasename+'-kgflashmediaplayer-encodeboxes').attr('id', 'attachments-'+basename+'-kgflashmediaplayer-encodeboxes');
830
+ jQuery('#attachments-'+oldbasename+'-thumbnailplaceholder').attr('id', 'attachments-'+basename+'-thumbnailplaceholder');
831
+ jQuery('#attachments-'+basename+'-kgflashmediaplayer-numberofthumbs').attr("onchange", "document.getElementById('attachments-"+basename+"-kgflashmediaplayer-thumbtime').value='';");
 
832
  jQuery('#attachments-'+basename+'-thumbgenerate').replaceWith('<input disabled="disabled" type="button" id="attachments-'+basename+'-thumbgenerate" class="button-secondary" value="'+kgvidL10n.generate+'" name="thumbgenerate" onclick="kgvid_generate_thumb(\''+basename+'\', \'generate\');" >');
833
  jQuery('#attachments-'+basename+'-thumbrandomize').replaceWith('<input disabled="disabled" type="button" id="attachments-'+basename+'-thumbrandomize" class="button-secondary" value="'+kgvidL10n.randomize+'" name="thumbgenerate" onclick="kgvid_generate_thumb(\''+basename+'\', \'random\');" >');
834
  document.getElementById('attachments-'+basename+'-kgflashmediaplayer-width').setAttribute("onchange", "kgvid_set_dimension('"+basename+"', 'height', this.value);")
843
  document.getElementById('attachments-'+basename+'-thumbgenerate').title = "";
844
  document.getElementById('attachments-'+basename+'-thumbrandomize').disabled = false;
845
  document.getElementById('attachments-'+basename+'-thumbrandomize').title = "";
 
846
  document.getElementById('attachments-'+basename+'-kgflashmediaplayer-encode').title = kgvidL10n.loading;
847
 
848
  }
849
  else {
850
+ jQuery('#attachments-'+basename+'-thumbgenerate').attr('title', kgvidL10n.ffmpegnotfound);
851
+ jQuery('attachments-'+basename+'-thumbrandomize').attr('title', kgvidL10n.ffmpegnotfound);
852
  }
853
  document.getElementById('insertonlybutton').disabled = false;
854
  document.getElementById('insertonlybutton').title = "";
1165
 
1166
  if ( kgflashmediaplayersecurity ) { //sometimes this tries to run after the media modal is closed
1167
 
1168
+ var kgvid_encode = kgvid_list_videos_to_encode(postID, blog);
 
 
 
 
 
 
 
 
 
1169
 
1170
  jQuery.post(ajaxurl, { action:"kgvid_generate_encode_checkboxes", security: kgflashmediaplayersecurity, movieurl: movieurl, post_id: postID, page: page, blog_id: blog.ID, encodeformats: kgvid_encode }, function(data) {
1171
  jQuery('#attachments-'+blog.id_text+postID+'-kgflashmediaplayer-encodeboxes').empty();
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: kylegilman
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=kylegilman@gmail.com&item_name=Video%20Embed%20And%20Thumbnail%20Generator%20Plugin%20Donation
4
  Tags: video, video player, video gallery, video thumbnail, ffmpeg, resolution
5
  Requires at least: 4.4
6
- Tested up to: 4.9
7
- Stable tag: 4.6.21
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -14,7 +14,9 @@ Makes video thumbnails, allows resolution switching, and embeds responsive self-
14
 
15
  = A plugin to make embedding videos, generating thumbnails, and encoding files easier. =
16
 
17
- Still 100% free, but some advanced features will be converted to premium add-ons in the future. More info in the <a href="https://wordpress.org/support/topic/version-50-will-convert-some-free-features-to-paid-add-ons">support forum</a>.
 
 
18
 
19
  This plugin adds several fields to any video uploaded to the WordPress Media Library. Just choose a few options, make thumbnails, click "Insert into Post" and you'll get a shortcode in the post editor that will embed a flexible, responsive HTML5 video player with Flash fallback for unsupported browsers.
20
 
@@ -246,6 +248,20 @@ Enter the username & password in the plugin settings "FFMPEG Settings" tab, or u
246
 
247
  == Changelog ==
248
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  = 4.6.21 - October 6, 2018 =
250
  * Updated Video.js to version 5.20.5
251
  * Added option to constrain video gallery thumbnail aspect ratios when mixed aspect ratios are present in the gallery.
@@ -433,110 +449,6 @@ Enter the username & password in the plugin settings "FFMPEG Settings" tab, or u
433
  * Fixed bug that disabled the text track remove button when editing videos in the media library.
434
  * Fixed bug that redundantly localized the frontend script every time a video was embedded on a page.
435
 
436
- = 4.5.5 - August 20, 2015 =
437
- * Fixed a number of potential infinite loops and other recursion issues related to longstanding WordPress bug <a href='https://core.trac.wordpress.org/ticket/17817'>#17817</a>.
438
- * Changed video player names with spaces (WordPress Default, JW Player) to one word camel case for JavaScript functions (WordPressDefault, JWPlayer).
439
-
440
- = 4.5.4 - August 9, 2015 =
441
- * Added option to disable native controls on mobile devices when using the Video.js player.
442
- * Added Schema.org uploadDate and description tags which are required by Google for video listings.
443
- * Updated Video.js to version 4.12.11
444
- * Fixed undefined index error when editing videos with text tracks that don't have default enabled.
445
- * Fixed and localized "Saving..." overlay when saving browser-generated thumbnails.
446
- * Fixed bug that could generate an error when displaying the sample video on the plugin settings page.
447
-
448
- = 4.5.3 - July 11, 2015 =
449
- * Fixed error that could zero out view counts when editing videos.
450
- * Fixed 'strlen' error when updating videos with subtitles.
451
- * Attempting to enable 'default' subtitle tracks on more browsers, but implementation is inconsistent.
452
-
453
- = 4.5.2 - July 10, 2015 =
454
- * Fixed bug that failed to set the volume or count views when using the WordPress Default or JW Player.
455
- * Fixed bug that failed to count views when WordPress Default player was on autoplay.
456
- * Fixed Video.js inconsistent autoplay bug.
457
-
458
- = 4.5.1 - July 9, 2015 =
459
- * Fixed bug that accidentally deleted thumbnail image IDs from video meta when editing attachments.
460
- * Prevented automatic re-writing of video URLs to a local address if a popular cloud storage address is entered in the shortcode (Amazon AWS, Rackspace, etc).
461
- * Restored full-resolution thumbnails when width is set to a percentage.
462
-
463
- = 4.5 - July 7, 2015 =
464
- * This is probably the last completely free major release. Some advanced features will be converted to premium add-ons in the future. More info in the <a href="https://wordpress.org/support/plugin/video-embed-thumbnail-generator">support forum</a>.
465
- * Consolidated most video metadata database entries into a single array. This might slow things down the first time you load the Media Library.
466
- * Added pagination option for video galleries.
467
- * Added oEmbed provider data and option to allow oEmbed discovery from other sites.
468
- * Added experimental WEBM VP9 encoding format.
469
- * Added option to make the watermark overlay image a link.
470
- * Added video stats column to Media Library list view.
471
- * Added options for vertical video rotation and metadata removal using FFMPEG, now that some browsers recognize rotation metadata.
472
- * Added "default" attribute for subtitle/caption text tracks to turn tracks on when the video loads.
473
- * Added attachment edit hook that updates video thumbnail's parent post when the video's parent post changes.
474
- * Added error handling and reporting for in-browser thumbnails.
475
- * Added Video.js localization. Automatically changes Video.js language to the current WordPress language.
476
- * Updated Video.js to version 4.12.7
477
- * Updated Spanish translation.
478
- * Updated Facebook Open Graph video embedding tags.
479
- * Re-enabled native video player controls on mobile devices when using Video.js player for better responsive resizing and to allow Airplay & Chromecast controls.
480
- * Removed superfluous gallery height option.
481
- * Stopped inserting unnecessary width and height shortcode attributes when videos are set to the default width and height.
482
- * Stopped inserting unnecessary poster URL shortcode attribute when poster is set in the media library.
483
- * Fixed several bugs related to hosting media library files on external servers like Amazon S3.
484
- * Fixed bug that deleted replacement videos before encoding was finished when simultaneous encodes are enabled.
485
- * Fixed bug that dropped videos from the video encode queue when multiple videos were added to the database simultaneously, specifically when using Add From Server.
486
- * Fixed bug that created squashed encoded videos when they were shot vertically on a mobile device.
487
- * Fixed bug that added bad content to Open Graph video tag when other shortcodes were found before KGVID in the post.
488
- * Fixed bug that wrote multiple unnecessary meta entries to the database when image attachments were updated.
489
- * Fixed bug that disabled "Choose from Library" buttons in Firefox.
490
- * Fixed bug that incorrectly indicated thumbnail selection video files did not load in Firefox.
491
- * Fixed bug that allowed video thumbnails to overflow their container in the Media Library modal window in Firefox.
492
- * Fixed bug that allowed crossdomain in-browser thumbnails to load, but then fail when trying to save them in Safari.
493
- * Fixed bug that kept end of video overlay images on screen when user hit play again.
494
- * Fixed bug that incorrectly resized videos embedded through iframe.
495
- * Fixed bug that did not assign a default value to the qt-faststart/MP4Box application path for new installations.
496
- * Fixed bug that allowed selection of multiple thumbnails in Embed Video from URL window
497
- * Fixed number formatting of video play counter.
498
- * Fixed encode queue text indent bug.
499
-
500
- = 4.4.2 - November 3, 2014 =
501
- * Added Google Universal Analytics event tracking.
502
- * Updated Spanish, French and Belgian translations.
503
- * Updated Video.js to version 4.10.2
504
- * Fixed bug that could prevent the media library from loading.
505
- * Fixed bug that prevented pop-up gallery thumbnails from resizing responsively.
506
-
507
- = 4.4.1 - October 28, 2014 =
508
- * Fixed bug that loaded resolution selector plugin too late in the page.
509
- * Fixed bug that displayed the video poster image while switching resolutions.
510
-
511
- = 4.4 - October 28, 2014 =
512
- * Added H.264 HTML5 video resolution switcher for the Video.js player. Automatically selects the appropriate resolution for the size of the displayed video and allows manual user switching on desktop computers.
513
- * Added option to set videos to automatically fill their containers.
514
- * Added buttons to manually set other videos in the media library as alternate formats for the current video.
515
- * Added option to encode a custom resolution.
516
- * Added option to replace original video with a lower-resolution H.264 video, WEBM or OGV.
517
- * Added buttons to generate thumbnails and encode additional formats for all previously uploaded videos.
518
- * Added plugin admin scripts to the frontend when Insert Media button is loaded. Works with bbPress now.
519
- * Added option to encode 64 and 32 kbps audio.
520
- * Added option to set a different application path for qt-faststart or MP4Box.
521
- * Added option to disable stdin during FFMPEG encoding. Particularly useful for IIS users.
522
- * Updated Video.js to version 4.9.1
523
- * Changed download link to a forced download for videos in the media library. No right-clicking necessary.
524
- * Changed pop-up video gallery to use inline code rather than an AJAX query.
525
- * Changed embedded video IDs to allow the same video to be embedded multiple times on a page.
526
- * Changed volume slider on plugin settings page to drop-down menu to fix settings save errors in Windows.
527
- * Changed 480p video format label to 360p to accurately reflect resolution of 16:9 videos. Format has always been 480p only for 4:3 videos.
528
- * Changed AAC encoder preference to libfdk_aac > libfaac > Native FFmpeg AAC encoder (aac) > libvo_aacenc.
529
- * Restored display of moov atom fix process in FFMPEG test output.
530
- * Fixed bug that made pop-up video windows 0 pixels wide in iOS 8.
531
- * Fixed bug that couldn't find video attachements that have been redirected to a CDN.
532
- * Fixed bug that quickly faded out the end overlay image in IE.
533
- * Fixed bug that prevented replacing encoded videos if there were any other videos in the queue.
534
- * Fixed bug that left the GUID as the original filename if replacing the video with an mp4 changed the extension.
535
- * Fixed bug that incorrectly reported all encoding fps values over 99 as "10".
536
- * Fixed bug that didn't recognize videos had completed encoding if there were audio frames left in the queue.
537
- * Fixed bug that left title overlay on iOS videos using the WordPress Default player.
538
- * Fixed bug that made video galleries display as inline-block when the inline video option was disabled.
539
-
540
  <a href="http://www.kylegilman.net/2011/01/18/video-embed-thumbnail-generator-wordpress-plugin/">See the full changelog on my website.</a>
541
 
542
  == Upgrade Notice ==
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=kylegilman@gmail.com&item_name=Video%20Embed%20And%20Thumbnail%20Generator%20Plugin%20Donation
4
  Tags: video, video player, video gallery, video thumbnail, ffmpeg, resolution
5
  Requires at least: 4.4
6
+ Tested up to: 5.0
7
+ Stable tag: 4.6.22
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
14
 
15
  = A plugin to make embedding videos, generating thumbnails, and encoding files easier. =
16
 
17
+ Not compatible with the new Block Editor. Please continue to use the <a href="https://wordpress.org/plugins/classic-editor/">Classic Editor</a>.
18
+
19
+ Still 100% free, but some advanced features may be converted to premium add-ons in the future. More info in the <a href="https://wordpress.org/support/topic/version-50-will-convert-some-free-features-to-paid-add-ons">support forum</a>.
20
 
21
  This plugin adds several fields to any video uploaded to the WordPress Media Library. Just choose a few options, make thumbnails, click "Insert into Post" and you'll get a shortcode in the post editor that will embed a flexible, responsive HTML5 video player with Flash fallback for unsupported browsers.
22
 
248
 
249
  == Changelog ==
250
 
251
+ = 4.6.22 - January 30, 2019 =
252
+ * Modularized video file formats that can be encoded by the plugin to allow other plugins to modify, delete, or create new formats.
253
+ * Added Custom WEBM VP9 format option.
254
+ * Renamed WEBM format to WEBM VP8.
255
+ * Fixed bug that deleted unfinished video encode queue entries every 24 hours.
256
+ * Fixed bug that created duplicate encodes of non-H.264 files in some situations.
257
+ * Fixed bug that inconsistently prevented thumbnail generation in the Media Library.
258
+ * Fixed bug that disabled embed from URL "insert into post" button if FFMPEG was not set up on server.
259
+ * Stopped appending timecode numbers to thumbnail filenames.
260
+ * Stopped removing special characters from the end of filenames of generated thumbnails and encoded files.
261
+ * Attempting to fix misconfigured locale settings that can sometimes cause video files with diacritics (accent marks, umlauts, etc) to generate "File not found" errors when using FFMPEG.
262
+ * Removed old Media Library video thumbnail display functionality that was preventing some Media Libraries from loading.
263
+ * Now allowing https FFMPEG input.
264
+
265
  = 4.6.21 - October 6, 2018 =
266
  * Updated Video.js to version 5.20.5
267
  * Added option to constrain video gallery thumbnail aspect ratios when mixed aspect ratios are present in the gallery.
449
  * Fixed bug that disabled the text track remove button when editing videos in the media library.
450
  * Fixed bug that redundantly localized the frontend script every time a video was embedded on a page.
451
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
452
  <a href="http://www.kylegilman.net/2011/01/18/video-embed-thumbnail-generator-wordpress-plugin/">See the full changelog on my website.</a>
453
 
454
  == Upgrade Notice ==
video-embed-thumbnail-generator.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Video Embed & Thumbnail Generator
4
  Plugin URI: http://www.kylegilman.net/2011/01/18/video-embed-thumbnail-generator-wordpress-plugin/
5
  Description: Generates thumbnails, HTML5-compliant videos, and embed codes for locally hosted videos. Requires FFMPEG or LIBAV for encoding.
6
- Version: 4.6.21
7
  Author: Kyle Gilman
8
  Author URI: http://www.kylegilman.net/
9
  Text Domain: video-embed-thumbnail-generator
@@ -60,21 +60,12 @@ function kgvid_default_options_fn() {
60
  $edit_others_capable = kgvid_check_if_capable('edit_others_posts');
61
 
62
  $options = array(
63
- "version" => '4.6.21',
64
  "embed_method" => "Video.js",
65
  "jw_player_id" => "",
66
  "template" => false,
67
  "template_gentle" => "on",
68
  "replace_format" => "fullres",
69
- "encode_fullres" => false,
70
- "encode_1080" => "on",
71
- "encode_720" => "on",
72
- "encode_480" => "on",
73
- "encode_mobile" => "on",
74
- "encode_webm" => false,
75
- "encode_vp9" => false,
76
- "encode_ogg" => false,
77
- "encode_custom" => false,
78
  "custom_format" => array(
79
  'format' => 'h264',
80
  'width' => '',
@@ -198,6 +189,14 @@ function kgvid_default_options_fn() {
198
  "alwaysloadscripts" => false
199
  );
200
 
 
 
 
 
 
 
 
 
201
  return $options;
202
 
203
  }
@@ -279,17 +278,7 @@ function kgvid_get_attachment_meta($post_id) {
279
  'play_75' => '0',
280
  'completeviews' => '0',
281
  'pickedformat' => '',
282
- 'encode_fullres' => '',
283
- 'encode_1080' => '',
284
- 'encode_720' => '',
285
- 'encode_480' => '',
286
- 'encode_mobile' => '',
287
- 'encode_webm' => '',
288
- 'encode_ogg' => '',
289
- 'encodecustom_h264' => '',
290
- 'encodecustom_webm' => '',
291
- 'encodecustom_ogg' => '',
292
- 'encodecustom' => '',
293
  'rotate' => '',
294
  'autothumb-error' => '',
295
  'numberofthumbs' => $options['generate_thumbs'],
@@ -334,6 +323,30 @@ function kgvid_get_attachment_meta($post_id) {
334
 
335
  }
336
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
  }
338
 
339
  $kgvid_postmeta = array_merge($meta_key_array, $kgvid_postmeta); //make sure all keys are set
@@ -388,7 +401,7 @@ function kgvid_save_encode_queue($video_encode_queue) {
388
 
389
  }
390
 
391
- function kgvid_video_formats( $return_replace = false, $return_customs = true ) {
392
 
393
  $options = kgvid_get_options();
394
 
@@ -402,7 +415,8 @@ function kgvid_video_formats( $return_replace = false, $return_customs = true )
402
  "extension" => "mp4",
403
  "mime" => "video/mp4",
404
  "suffix" => "-fullres.mp4",
405
- "vcodec" => "libx264"
 
406
  ),
407
  "1080" => array(
408
  "name" => "1080p H.264",
@@ -414,7 +428,8 @@ function kgvid_video_formats( $return_replace = false, $return_customs = true )
414
  "mime" => "video/mp4",
415
  "suffix" => "-1080.mp4",
416
  "old_suffix" => "-1080.m4v",
417
- "vcodec" => "libx264"
 
418
  ),
419
  "720" => array(
420
  "name" => "720p H.264",
@@ -426,7 +441,8 @@ function kgvid_video_formats( $return_replace = false, $return_customs = true )
426
  "mime" => "video/mp4",
427
  "suffix" => "-720.mp4",
428
  "old_suffix" => "-720.m4v",
429
- "vcodec" => "libx264"
 
430
  ),
431
  "480" => array(
432
  "name" => "480p H.264",
@@ -438,7 +454,8 @@ function kgvid_video_formats( $return_replace = false, $return_customs = true )
438
  "mime" => "video/mp4",
439
  "suffix" => "-480.mp4",
440
  "old_suffix" => "-480.m4v",
441
- "vcodec" => "libx264"
 
442
  ),
443
  "mobile" => array(
444
  "name" => "360p H.264",
@@ -450,29 +467,32 @@ function kgvid_video_formats( $return_replace = false, $return_customs = true )
450
  "suffix" => "-360.mp4",
451
  "mime" => "video/mp4",
452
  "old_suffix" => "-ipod.m4v",
453
- "vcodec" => "libx264"
 
454
  ),
455
  "webm" => array(
456
- "name" => "WEBM",
457
- "label" => 'WEBM',
458
  "width" => INF,
459
  "height" => INF,
460
  "type" => "webm",
461
  "extension" => "webm",
462
  "mime" => "video/webm",
463
  "suffix" => ".webm",
464
- "vcodec" => "libvpx"
 
465
  ),
466
  "vp9" => array(
467
  "name" => "WEBM VP9",
468
  "label" => 'WEBM VP9',
469
  "width" => INF,
470
  "height" => INF,
471
- "type" => "webm",
472
  "extension" => "webm",
473
  "mime" => "video/webm",
474
  "suffix" => "-vp9.webm",
475
- "vcodec" => "libvpx-vp9"
 
476
  ),
477
  "ogg" => array(
478
  "name" => "OGV",
@@ -483,7 +503,8 @@ function kgvid_video_formats( $return_replace = false, $return_customs = true )
483
  "extension" => "ogv",
484
  "mime" => "video/ogg",
485
  "suffix" => ".ogv",
486
- "vcodec" => "libtheora"
 
487
  )
488
  );
489
 
@@ -499,7 +520,8 @@ function kgvid_video_formats( $return_replace = false, $return_customs = true )
499
  "extension" => "mp4",
500
  "mime" => "video/mp4",
501
  "suffix" => "-custom.mp4",
502
- "vcodec" => "libx264"
 
503
  ),
504
  "custom_webm" => array(
505
  "name" => __('Custom WEBM', 'video-embed-thumbnail-generator'),
@@ -510,7 +532,20 @@ function kgvid_video_formats( $return_replace = false, $return_customs = true )
510
  "extension" => "webm",
511
  "mime" => "video/webm",
512
  "suffix" => "-custom.webm",
513
- "vcodec" => "libvpx"
 
 
 
 
 
 
 
 
 
 
 
 
 
514
  ),
515
  "custom_ogg" => array(
516
  "name" => __('Custom OGV', 'video-embed-thumbnail-generator'),
@@ -521,7 +556,8 @@ function kgvid_video_formats( $return_replace = false, $return_customs = true )
521
  "extension" => "ogv",
522
  "mime" => "video/ogv",
523
  "suffix" => "-custom.ogv",
524
- "vcodec" => "libtheora"
 
525
  )
526
  );
527
  }
@@ -544,7 +580,7 @@ function kgvid_video_formats( $return_replace = false, $return_customs = true )
544
 
545
  if ( !$return_replace && $options['replace_format'] != 'fullres' ) { unset($video_formats[$options['replace_format']]); }
546
 
547
- return $video_formats;
548
 
549
  }
550
 
@@ -732,6 +768,32 @@ function kgvid_set_capabilities($capabilities) {
732
 
733
  }
734
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
735
  function kgvid_aac_encoders() {
736
 
737
  $aac_array = array("libfdk_aac", "libfaac", "aac", "libvo_aacenc");
@@ -1011,7 +1073,8 @@ function kgvid_sanitize_url($movieurl) {
1011
  else {
1012
  $movieurl = strtok($movieurl,'?');
1013
  $sanitized_url['noextension'] = preg_replace("/\\.[^.\\s]{3,4}$/", "", $movieurl);
1014
- $sanitized_url['basename'] = sanitize_file_name(basename($movieurl,'.'.$movie_extension));;
 
1015
  }
1016
 
1017
  $sanitized_url['singleurl_id'] = "singleurl_".preg_replace('/[^a-zA-Z0-9]/', '_', $sanitized_url['basename']);
@@ -1057,8 +1120,10 @@ function kgvid_check_ffmpeg_exists($options, $save) {
1057
  if (function_exists('escapeshellcmd')) {
1058
  $exec_enabled = true;
1059
  $test_path = rtrim($options['app_path'], '/');
 
1060
  $cmd = escapeshellcmd($test_path.'/'.$options['video_app'].' -i "'.plugin_dir_path(__FILE__).'images/sample-video-h264.mp4" -vframes 1 -f mjpeg '.$uploads['path'].'/ffmpeg_exists_test.jpg').' 2>&1';
1061
  exec ( $cmd, $output, $returnvalue );
 
1062
  }
1063
  else { $function = "ESCAPESHELLCMD"; }
1064
  }
@@ -1068,8 +1133,10 @@ function kgvid_check_ffmpeg_exists($options, $save) {
1068
 
1069
  if ( !file_exists($uploads['path'].'/ffmpeg_exists_test.jpg') ) { //if FFMPEG has not executed successfully
1070
  $test_path = substr($test_path, 0, -strlen($options['video_app'])-1 );
 
1071
  $cmd = escapeshellcmd($test_path.'/'.$options['video_app'].' -i "'.plugin_dir_path(__FILE__).'images/sample-video-h264.mp4" -vframes 1 -f mjpeg '.$uploads['path'].'/ffmpeg_exists_test.jpg');
1072
  exec ( $cmd );
 
1073
  }
1074
 
1075
  if ( file_exists($uploads['path'].'/ffmpeg_exists_test.jpg') ) { //FFMEG has executed successfully
@@ -1316,8 +1383,6 @@ function kgvid_get_video_dimensions($video = false) {
1316
  $ffmpegPath = $options['app_path']."/".$options['video_app'];
1317
  $movie_info = array();
1318
 
1319
- $video = str_replace("https://", "http://", $video);
1320
-
1321
  if ( strpos($video, 'http://') === 0 ) { //if it's a URL
1322
  $video_id = kgvid_url_to_id($video);
1323
  if ( $video_id ) {
@@ -1330,10 +1395,11 @@ function kgvid_get_video_dimensions($video = false) {
1330
  }
1331
  }
1332
  }
1333
-
1334
  $command = escapeshellcmd($ffmpegPath . ' -i "' . $video . '"');
1335
  $command = $command.' 2>&1';
1336
  exec ( $command, $output );
 
1337
  $lastline = end($output);
1338
  $lastline = prev($output)."<br />".$lastline;
1339
  $movie_info['output'] = addslashes($lastline);
@@ -1364,10 +1430,11 @@ function kgvid_get_video_dimensions($video = false) {
1364
  case "-90": $movie_info['rotate'] = 270; break;
1365
  default: $movie_info['rotate'] = ""; break;
1366
  }
1367
-
1368
  $command = escapeshellcmd($ffmpegPath . ' -i "' . $video . '" -codecs');
1369
  $command = $command.' 2>&1';
1370
  exec ( $command, $output );
 
1371
  $output = implode("\n", $output);
1372
  $configuration = array();
1373
  $video_lib_array = array('libtheora', 'libvorbis', 'libvpx', 'libvpx-vp9', 'libx264');
@@ -1544,7 +1611,6 @@ function kgvid_ffmpeg_watermark_strings( $ffmpeg_watermark, $movie_width, $rotat
1544
  }
1545
  else { $watermark_valign = ""; } //top justified
1546
 
1547
- $ffmpeg_watermark['url'] = str_replace("https://", "http://", $ffmpeg_watermark['url']);
1548
  if ( strpos($ffmpeg_watermark['url'], 'http://') === 0 ) {
1549
  $watermark_id = false;
1550
  $watermark_id = kgvid_url_to_id($ffmpeg_watermark['url']);
@@ -1595,21 +1661,31 @@ function kgvid_generate_encode_string($input, $output, $movie_info, $format, $wi
1595
  $qscale_flag = "qscale";
1596
  }
1597
 
 
 
 
 
1598
  if ( $options['rate_control'] == "crf" ) {
1599
  $crf_option = $video_formats[$format]['type'].'_CRF';
1600
- if ( $format == 'vp9' ) { $crf_option = 'h264_CRF'; }
 
 
1601
  $crf_flag = "crf";
1602
  if ( $video_formats[$format]['type'] == 'ogv' ) { $crf_flag = $qscale_flag; } //ogg doesn't do CRF
1603
  $rate_control_flag = " -".$crf_flag." ".$options[$crf_option];
1604
  }
1605
  else {
1606
- $rate_control_flag = " -".$video_bitrate_flag." ".round(floatval($options['bitrate_multiplier'])*$width*$height*30/1024)."k";
 
 
 
 
 
 
 
 
1607
  }
1608
 
1609
- $rotate_strings = kgvid_ffmpeg_rotate_strings($rotate, $width, $height);
1610
- $width = $rotate_strings['width']; //in case rotation requires swapping height and width
1611
- $height = $rotate_strings['height'];
1612
-
1613
  $watermark_strings = kgvid_ffmpeg_watermark_strings($options['ffmpeg_watermark'], $movie_info['width'], $rotate_strings['complex']);
1614
 
1615
  if ( $video_formats[$format]['type'] == 'h264' ) {
@@ -1646,8 +1722,13 @@ function kgvid_generate_encode_string($input, $output, $movie_info, $format, $wi
1646
  }
1647
  else { //if it's not H.264 the settings are basically the same
1648
  $ffmpeg_options = "-acodec libvorbis -".$audio_bitrate_flag." ".$options['audio_bitrate']."k -s ".$width."x".$height." -vcodec ".$video_formats[$format]['vcodec'];
1649
- if ( $video_formats[$format]['type'] == 'webm' && $options['rate_control'] == "crf" ) {
1650
- $ffmpeg_options .= " -".$video_bitrate_flag." ".round(floatval($options['bitrate_multiplier'])*1.25*$width*$height*30/1024)."k"; //set a max bitrate 25% larger than the ABR. Otherwise libvpx goes way too low.
 
 
 
 
 
1651
  }
1652
  }
1653
 
@@ -2338,7 +2419,7 @@ function kgvid_single_video_code($query_atts, $atts, $content, $post_id) {
2338
  $options = kgvid_get_options();
2339
  $code = "";
2340
  $id_array = array();
2341
- $video_formats = kgvid_video_formats();
2342
  $compatible = array("flv", "f4v", "mp4", "mov", "m4v", "ogv", "ogg", "webm");
2343
  $h264compatible = array("mp4", "mov", "m4v");
2344
 
@@ -3435,7 +3516,9 @@ function kgvid_encode_format_meta( $encodevideo_info, $video_key, $format, $stat
3435
 
3436
  if ( get_post_type($post_id) == "attachment" ) {
3437
  $kgvid_postmeta = kgvid_get_attachment_meta($post_id);
3438
- if ( array_key_exists('encode'.$format, $kgvid_postmeta) ) { $encodeset = $kgvid_postmeta['encode'.$format]; }
 
 
3439
  else { $encodeset = 'false'; }
3440
  $post = get_post($post_id);
3441
  $current_user = wp_get_current_user();
@@ -3446,7 +3529,10 @@ function kgvid_encode_format_meta( $encodevideo_info, $video_key, $format, $stat
3446
  }
3447
 
3448
  }
3449
- if ( $encodeset == "false" && strpos($format, 'custom_') === false ) { $encodeset = $options['encode_'.$format]; }
 
 
 
3450
 
3451
  if ( $encodeset == "on" || $status == "queued" ) { $checked = 'checked'; }
3452
 
@@ -3459,7 +3545,7 @@ function kgvid_encode_format_meta( $encodevideo_info, $video_key, $format, $stat
3459
 
3460
  if ( !empty($encodevideo_info) ) {
3461
 
3462
- if ( $encodevideo_info[$format]['exists'] ) { //if the video file exists
3463
 
3464
  if ( array_key_exists('id', $encodevideo_info[$format]) ) {
3465
  $child_id = $encodevideo_info[$format]['id'];
@@ -3539,8 +3625,8 @@ function kgvid_ajax_generate_encode_checkboxes() {
3539
  $encode_checked = $_POST['encodeformats'];
3540
  $kgvid_postmeta = kgvid_get_attachment_meta($post_id);
3541
  foreach ( $encode_checked as $format => $checked ) {
3542
- if ( $checked == "true" ) { $kgvid_postmeta['encode'.$format] = 'on'; }
3543
- else {$kgvid_postmeta['encode'.$format] = 'notchecked'; }
3544
  }
3545
  kgvid_save_attachment_meta($post_id, $kgvid_postmeta);
3546
  }
@@ -3625,6 +3711,7 @@ function kgvid_generate_encode_checkboxes($movieurl, $post_id, $page, $blog_id =
3625
  unset($video_formats['custom_h264']);
3626
  unset($video_formats['custom_webm']);
3627
  unset($video_formats['custom_ogg']);
 
3628
  }
3629
 
3630
  if ( $options['ffmpeg_exists'] == "notinstalled" ) {
@@ -3697,7 +3784,7 @@ function kgvid_generate_encode_checkboxes($movieurl, $post_id, $page, $blog_id =
3697
  if ( !empty($encodevideo_info) && !$encodevideo_info[$format]['exists']
3698
  && (
3699
  strpos($format, 'custom_') === 0 //skip custom formats that don't exist
3700
- || ( $format != 'fullres' && $options['encode_'.$format] == false && $options['hide_video_formats'] )
3701
  )
3702
  ) { continue; }
3703
 
@@ -3723,7 +3810,7 @@ function kgvid_generate_encode_checkboxes($movieurl, $post_id, $page, $blog_id =
3723
  if ( $meta_array['something_to_encode'] == true ) { $something_to_encode = true; }
3724
  if ( $meta_array['encoding_now'] == true ) { $encoding_now = true; }
3725
 
3726
- $checkboxes .= "\n\t\t\t".'<li><input class="kgvid_encode_checkbox" type="checkbox" id="attachments-'.$blog_id_text.$post_id.'-kgflashmediaplayer-encode'.$format.'" name="attachments'.$blog_name_text.'['.$post_id.'][kgflashmediaplayer-encode'.$format.']" '.$meta_array['checked'].' '.$ffmpeg_disabled_text.$meta_array['disabled'].'> <label for="attachments-'.$blog_id_text.$post_id.'-kgflashmediaplayer-encode'.$format.'">'.$format_stats['name'].'</label> <span id="attachments-'.$blog_id_text.$post_id.'-kgflashmediaplayer-meta'.$format.'" class="kgvid_format_meta">'.$meta_array['meta'].'</span>';
3727
 
3728
  if ( !$security_disabled && $is_attachment && empty($meta_array['disabled']) && $format != 'fullres' && $page != 'queue' ) { $checkboxes .= "<span id='pick-".$post_id."-".$format."' class='button kgvid_encode_checkbox_button' data-choose='".sprintf( __('Choose %s', 'video-embed-thumbnail-generator'), $format_stats['name'] )."' data-update='".sprintf( __('Set as %s', 'video-embed-thumbnail-generator'), $format_stats['name'] )."' onclick='kgvid_pick_format(this, \"".$post_id."\", \"".esc_attr($format_stats['mime'])."\", \"".$format."\", \"".esc_attr($movieurl)."\", \"".$blog_id."\");'>".__('Choose from Library', 'video-embed-thumbnail-generator')."</span>";
3729
  }
@@ -4836,7 +4923,7 @@ add_action('admin_init', 'kgvid_video_embed_options_init' );
4836
  $items['custom'] = __('Custom', 'video-embed-thumbnail-generator');
4837
 
4838
  echo "<div class='kgvid_video_app_required'>";
4839
- echo "<input ".checked( $options['encode_fullres'], "on", false )." id='encode_fullres' name='kgvid_video_embed_options[encode_fullres]' type='checkbox' /> <label for='encode_fullres'>".__('Replace original with', 'video-embed-thumbnail-generator');
4840
 
4841
  echo " <select id='replace_format' name='kgvid_video_embed_options[replace_format]' class='affects_ffmpeg' onchange='kgvid_change_replace_format();'>";
4842
  foreach($items as $value=>$name) {
@@ -4845,17 +4932,26 @@ add_action('admin_init', 'kgvid_video_embed_options_init' );
4845
  }
4846
  echo "</select> ";
4847
 
4848
-
4849
  echo "</label> <span class='kgvid_tooltip wp-ui-text-highlight'><span class='kgvid_tooltip_classic'>".__('If you have FFMPEG/LIBAV and the proper libraries installed, you can choose to replace your uploaded video with your preferred format, and also transcode into several additional formats depending on the resolution of your original source. Different browsers have different playback capabilities. Most desktop browsers can play H.264, and all modern mobile devices can play at least 360p H.264. If you create multiple H.264 resolutions, the highest resolution supported by the device will be served up automatically. The plugin will not upconvert your video, so if you upload a 720p video, it will not waste your time creating a 1080p version. There was a time when it seemed like a good idea to provide OGV or WEBM for some desktop browsers, but even Firefox allows H.264 playback on most operating systems now. I no longer recommend encoding OGV or WEBM. WEBM VP9 is a new technology and requires a version of FFMPEG or LIBAV newer than October 2013. Most browsers except Safari currently support it.', 'video-embed-thumbnail-generator')."</span></span><br />";
4850
- echo "<input ".checked( $options['encode_1080'], "on", false )." id='encode_1080' name='kgvid_video_embed_options[encode_1080]' type='checkbox' /> <label for='encode_1080'>1080p H.264</label><br />";
4851
- echo "<input ".checked( $options['encode_720'], "on", false )." id='encode_720' name='kgvid_video_embed_options[encode_720]' type='checkbox' /> <label for='encode_720'>720p H.264</label><br />";
4852
- echo "<input ".checked( $options['encode_480'], "on", false )." id='encode_480' name='kgvid_video_embed_options[encode_480]' type='checkbox' /> <label for='encode_480'>480p H.264</label><br />";
4853
- echo "<input ".checked( $options['encode_mobile'], "on", false )." id='encode_mobile' name='kgvid_video_embed_options[encode_mobile]' type='checkbox' /> <label for='encode_mobile'>360p H.264</label><br />";
4854
- echo "<input ".checked( $options['encode_webm'], "on", false )." id='encode_webm' name='kgvid_video_embed_options[encode_webm]' type='checkbox' /> <label for='encode_webm'>WEBM <small><em>(Firefox, Chrome, Android 2.3+, Opera)</em></small></label><br />";
4855
- echo "<input ".checked( $options['encode_vp9'], "on", false )." id='encode_vp9' name='kgvid_video_embed_options[encode_vp9]' type='checkbox' /> <label for='encode_vp9'>WEBM VP9 <small><em>(Android 4.4+, Firefox, Chrome, Opera, Edge)</em></small></label><br />";
4856
- echo "<input ".checked( $options['encode_ogg'], "on", false )." id='encode_ogg' name='kgvid_video_embed_options[encode_ogg]' type='checkbox' /> <label for='encode_ogg'>OGV <small><em>(Firefox, Chrome, Android 2.3+, Opera)</em></small></label><br />";
4857
- echo "<input ".checked( $options['encode_custom'], "on", false )." id='encode_custom' name='kgvid_video_embed_options[encode_custom]' type='checkbox' /> <label for='encode_custom'>".__('Custom', 'video-embed-thumbnail-generator');
4858
- $items = array( "H.264" => "h264" , "WEBM" => "webm", "OGV" => "ogg" );
 
 
 
 
 
 
 
 
 
 
4859
  echo " <select id='custom_format_type' name='kgvid_video_embed_options[custom_format][format]' class='affects_ffmpeg'>";
4860
  foreach($items as $name=>$value) {
4861
  $selected = ($options['custom_format']['format']==$value) ? 'selected="selected"' : '';
@@ -5032,7 +5128,7 @@ add_action('admin_init', 'kgvid_video_embed_options_init' );
5032
  $selected = ($options['rate_control']==$value) ? 'selected="selected"' : '';
5033
  echo "<option value='$value' $selected>$name</option>";
5034
  }
5035
- echo "</select> <span class='kgvid_tooltip wp-ui-text-highlight'><span class='kgvid_tooltip_classic'>".__('Constant Rate Factor (CRF) attempts to maintain a particular quality output for the entire video and only uses bits the encoder determines are necessary. Average Bit Rate is similar to the method used in older versions of this plugin. If CRF is selected, WEBM encoding will also use the ABR setting to set a max bit rate 25% higher than the ABR. Without a max bit rate setting WEBM files are terrible quality.', 'video-embed-thumbnail-generator')."</span></span>";
5036
  echo "</div>\n\t";
5037
  }
5038
 
@@ -5044,14 +5140,14 @@ add_action('admin_init', 'kgvid_video_embed_options_init' );
5044
  $selected = ($options['h264_CRF']==$i) ? 'selected="selected"' : '';
5045
  echo "<option value='".$i."' $selected>".$i."</option>";
5046
  }
5047
- echo "</select> H.264 & VP9 WEBM <span class='kgvid_tooltip wp-ui-text-highlight'><span class='kgvid_tooltip_classic'>".__('Lower values are higher quality. 18 is considered visually lossless. Default is 23.', 'video-embed-thumbnail-generator')."</span></span><br />";
5048
 
5049
  echo "<select id='webm_CRF' name='kgvid_video_embed_options[webm_CRF]' class='affects_ffmpeg'>";
5050
  for ($i = 4; $i <= 63; $i++ ) {
5051
  $selected = ($options['webm_CRF']==$i) ? 'selected="selected"' : '';
5052
  echo "<option value='".$i."' $selected>".$i."</option>";
5053
  }
5054
- echo "</select> WEBM <span class='kgvid_tooltip wp-ui-text-highlight'><span class='kgvid_tooltip_classic'>".__('Lower values are higher quality. Default is 10.', 'video-embed-thumbnail-generator')."</span></span><br />\n\t";
5055
 
5056
  echo "<select id='ogv_CRF' name='kgvid_video_embed_options[ogv_CRF]' class='affects_ffmpeg'>";
5057
  for ($i = 1; $i <= 10; $i++ ) {
@@ -5431,6 +5527,16 @@ function kgvid_update_settings() {
5431
  );
5432
  }
5433
 
 
 
 
 
 
 
 
 
 
 
5434
  if ( $options['version'] != $default_options['version'] ) { $options['version'] = $default_options['version']; }
5435
  if ( $options !== $options_old ) { update_option('kgvid_video_embed_options', $options); }
5436
  }
@@ -5476,7 +5582,12 @@ function kgvid_video_embed_options_validate($input) { //validate & sanitize inpu
5476
  }
5477
  else { $input['ffmpeg_exists'] = $options['ffmpeg_exists']; }
5478
 
5479
- if ( $input['ffmpeg_exists'] == "notinstalled" ) { $input['browser_thumbnails'] = "on"; } //in case a user had FFMPEG installed and disabled it, they can't choose to disable browser thumbnails if it's no longer installed
 
 
 
 
 
5480
 
5481
  if ( $input['ffmpeg_thumb_watermark']['url'] != '' ) { //can't use browser thumbnails with ffmpeg watermark
5482
  $input['browser_thumbnails'] = false;
@@ -5516,21 +5627,23 @@ function kgvid_video_embed_options_validate($input) { //validate & sanitize inpu
5516
  }
5517
  if ( $input['custom_format']['format'] == 'h264' ) {
5518
  $input['custom_format']['name'] .= ' H.264';
 
5519
  $input['custom_format']['extension'] = 'mp4';
5520
  $input['custom_format']['mime'] = 'video/mp4';
5521
  $input['custom_format']['vcodec'] = 'libx264';
5522
  }
5523
  else {
5524
  $input['custom_format']['name'] .= ' '.strtoupper($input['custom_format']['format']);
 
5525
  $input['custom_format']['extension'] = $video_formats[$input['custom_format']['format']]['extension'];
5526
  $input['custom_format']['mime'] = $video_formats[$input['custom_format']['format']]['mime'];
5527
  $input['custom_format']['vcodec'] = $video_formats[$input['custom_format']['format']]['vcodec'];
5528
- if ( $input['custom_format']['format'] == 'ogg' ) { $input['custom_format']['type'] = 'ogv'; }
5529
  }
5530
- if ( $input['custom_format']['format'] == 'ogg' ) { $input['custom_format']['type'] = 'ogv'; }
5531
- else { $input['custom_format']['type'] = $input['custom_format']['format']; }
5532
  $input['custom_format']['suffix'] = '-custom.'.$input['custom_format']['extension'];
5533
 
 
 
5534
  } // if the custom format has been set
5535
  else {
5536
 
@@ -5616,7 +5729,9 @@ function kgvid_ajax_save_settings() {
5616
  || strpos($setting, 'default_capabilities') !== false
5617
  || strpos($setting, 'ffmpeg_watermark') !== false
5618
  || strpos($setting, 'ffmpeg_thumb_watermark') !== false
5619
- || strpos($setting, 'custom_format') !== false )
 
 
5620
  {
5621
  $validated_options[$setting] = $value;
5622
  }
@@ -5727,8 +5842,12 @@ function kgvid_cron_new_attachment_handler($post_id, $force = false) {
5727
  foreach ( $thumb_output as $key=>$output ) {
5728
 
5729
  if ( $thumb_output[$key]['lastthumbnumber'] != 'break' ) {
5730
- if ( $numberofthumbs == 1 ) { $index = false; }
5731
- else { $index = $key; }
 
 
 
 
5732
  $thumb_id[$key] = kgvid_save_thumb($post_id, $post->post_title, $thumb_output[$key]['thumb_url'], $index);
5733
  }//end if there wasn't an error
5734
  else {
@@ -5771,7 +5890,7 @@ function kgvid_cron_new_attachment_handler($post_id, $force = false) {
5771
  if ( substr(basename($filepath, '.'.$extension), -10) == '-noreplace'
5772
  || ( array_key_exists('original_replaced', $kgvid_postmeta) && $kgvid_postmeta['original_replaced'] == $options['replace_format'] )
5773
  ) {
5774
- $options['encode_fullres'] = false;
5775
  }
5776
 
5777
  if ( $post->post_mime_type == 'image/gif' ) {
@@ -5781,7 +5900,7 @@ function kgvid_cron_new_attachment_handler($post_id, $force = false) {
5781
 
5782
  foreach ( $video_formats as $format => $format_stats ) {
5783
 
5784
- if ( array_key_exists('encode_'.$format, $options) && $options['encode_'.$format] == "on" ) {
5785
  $encode_checked[$format] = "true";
5786
  $something_to_encode = true;
5787
  }
@@ -5791,7 +5910,7 @@ function kgvid_cron_new_attachment_handler($post_id, $force = false) {
5791
  }
5792
 
5793
  if ( $something_to_encode ) {
5794
-
5795
  $output = kgvid_enqueue_videos($post_id, $movieurl, $encode_checked, $post->post_parent);
5796
  $output = kgvid_encode_videos();
5797
 
@@ -6002,7 +6121,7 @@ function kgvid_image_attachment_fields_to_edit($form_fields, $post) {
6002
  $thumbnail_html = '<div class="kgvid_thumbnail_box kgvid_chosen_thumbnail_box">'.$kgvid_postmeta['autothumb-error'].'</div>';
6003
  }
6004
  elseif ( !empty($thumbnail_url) ) {
6005
- $thumbnail_html = '<div class="kgvid_thumbnail_box kgvid_chosen_thumbnail_box"><img width="200" src="'.$thumbnail_url.'"></div>';
6006
  }
6007
 
6008
  $choose_from_video_content = "";
@@ -6090,7 +6209,6 @@ function kgvid_image_attachment_fields_to_edit($form_fields, $post) {
6090
  $form_fields["kgflashmediaplayer-autothumb-error"]["input"] = "hidden";
6091
  $form_fields["kgflashmediaplayer-autothumb-error"]["value"] = $kgvid_postmeta['autothumb-error'];
6092
 
6093
-
6094
  $form_fields["generator"]["label"] = _x("Thumbnails", 'Header for thumbnail section', 'video-embed-thumbnail-generator');
6095
  $form_fields["generator"]["input"] = "html";
6096
  $form_fields["generator"]["html"] = $choose_from_video_content.'
@@ -6277,45 +6395,6 @@ function kgvid_hide_video_children($wp_query_obj) {
6277
  }
6278
  add_action('pre_get_posts', 'kgvid_hide_video_children');
6279
 
6280
- function kgvid_change_video_icon($icon, $mime, $post_id) {
6281
-
6282
- $post = get_post($post_id);
6283
- $kgvid_postmeta = kgvid_get_attachment_meta($post_id);
6284
-
6285
- if ( substr($mime, 0, 5) == 'video' ) {
6286
-
6287
- if ( !empty($post->post_parent) && strpos(get_post_mime_type( $post->post_parent ), 'video') !== false
6288
- || get_post_meta($post->ID, '_kgflashmediaplayer-externalurl', true) != '' ) {
6289
- $post_id = $post->post_parent; //use post parent if this is a child video or encoded from an external url
6290
- }
6291
- $poster_id = get_post_meta($post_id, '_kgflashmediaplayer-poster-id', true);
6292
- if ( !empty($poster_id) ) {
6293
- $poster_src = wp_get_attachment_image_src( $poster_id, 'thumbnail' );
6294
- if ( is_ssl() ) { $poster_src[0] = str_replace( "http:", "https:", $poster_src[0] ); }
6295
- global $_current_video_icon_dir;
6296
- $_current_video_icon_dir = dirname($poster_src[0]);
6297
- // - Return your icon path
6298
- return $poster_src[0].'?kgvid';
6299
- }
6300
- }
6301
- return $icon;
6302
- }
6303
- add_filter('wp_mime_type_icon', 'kgvid_change_video_icon', 10, 3);
6304
-
6305
- function kgvid_video_icon_dir($dir) {
6306
-
6307
- global $_current_video_icon_dir;
6308
- if(!empty($_current_video_icon_dir))
6309
- {
6310
- $var = $_current_video_icon_dir;
6311
- $_current_video_icon_dir = null; //reset icon_dir if there's no thumbnail set
6312
- return $var;
6313
- }
6314
- return $dir;
6315
-
6316
- }
6317
- add_filter('icon_dir', 'kgvid_video_icon_dir');
6318
-
6319
  function kgvid_decode_base64_png($raw_png, $tmp_posterpath) {
6320
 
6321
  $raw_png = str_replace('data:image/png;base64,', '', $raw_png);
@@ -6341,7 +6420,8 @@ function kgvid_ajax_save_html5_thumb() {
6341
  $total = $_POST['total'];
6342
  $index = $_POST['index']+1;
6343
 
6344
- $posterfile = sanitize_file_name(pathinfo($video_url, PATHINFO_FILENAME)).'_thumb'.$movieoffset;
 
6345
  if (!file_exists($uploads['path'].'/thumb_tmp')) { mkdir($uploads['path'].'/thumb_tmp'); }
6346
  $tmp_posterpath = $uploads['path'].'/thumb_tmp/'.$posterfile.'.png';
6347
  $thumb_url = $uploads['url'].'/'.$posterfile.'.jpg';
@@ -6377,7 +6457,8 @@ function kgvid_ajax_save_html5_thumb() {
6377
  }
6378
 
6379
  kgvid_schedule_cleanup_generated_files('thumbs');
6380
- echo ($thumb_url);
 
6381
  }
6382
 
6383
  die();
@@ -6420,6 +6501,21 @@ function kgvid_save_thumb($post_id, $post_name, $thumb_url, $index=false) {
6420
  $tmp_posterpath = $uploads['path'].'/thumb_tmp/'.$posterfile;
6421
  $final_posterpath = $uploads['path'].'/'.$posterfile;
6422
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6423
  $success = false;
6424
  if ( !is_file($final_posterpath) ) { //if the file doesn't already exist
6425
  if ( is_file($tmp_posterpath) ) {
@@ -6463,15 +6559,6 @@ function kgvid_save_thumb($post_id, $post_name, $thumb_url, $index=false) {
6463
  $filename = preg_replace('/\.[^.]+$/', '', basename($thumb_url));
6464
  if ( $user_ID == 0 ) { $user_ID = $video->post_author; }
6465
 
6466
-
6467
- /*$file_array = array(
6468
- 'name' => basename($posterfile),
6469
- 'tmp_name' => $tmp_posterpath,
6470
- );
6471
-
6472
- //$return = apply_filters( 'wp_handle_upload', array( 'file' => $uploads['path'].'/'.$posterfile, 'url' => $thumb_url, 'type' => $wp_filetype['type'] ), 'sideload' );
6473
- //$thumb_id = media_handle_sideload( $file_array, $post_id, $desc );*/
6474
-
6475
  $attachment = array(
6476
  'guid' => $thumb_url,
6477
  'post_mime_type' => $wp_filetype['type'],
@@ -6544,8 +6631,8 @@ function kgvid_ajax_redraw_thumbnail_box() {
6544
  $thumbnail_src = wp_get_attachment_image_src($poster_id, 'thumbnail');
6545
  if ( is_array($thumbnail_src) && array_key_exists(0, $thumbnail_src) ) { $thumbnail_size_url = $thumbnail_src[0]; }
6546
  }
6547
- $response['thumb_url'] = get_post_meta($post_id, "_kgflashmediaplayer-poster", true);
6548
- $response['thumbnail_size_url'] = $thumbnail_size_url;
6549
  $response['thumb_error'] = $kgvid_postmeta['autothumb-error'];
6550
  echo json_encode($response);
6551
  die();
@@ -6572,9 +6659,8 @@ function kgvid_video_attachment_fields_to_save($post, $attachment) {
6572
  if( isset($attachment['kgflashmediaplayer-poster']) ) {
6573
 
6574
  $thumb_url = $attachment['kgflashmediaplayer-poster'];
6575
- $old_thumb_url = get_post_meta($post['ID'], '_kgflashmediaplayer-poster', true);
6576
 
6577
- if ( !empty($thumb_url) && $old_thumb_url != $thumb_url ) {
6578
  $thumb_id = kgvid_save_thumb($post['ID'], $post['post_title'], $thumb_url);
6579
  if ( $thumb_id ) {
6580
  $thumb_url = wp_get_attachment_url($thumb_id);
@@ -6627,9 +6713,9 @@ function kgvid_video_attachment_fields_to_save($post, $attachment) {
6627
 
6628
  $video_formats = kgvid_video_formats(false, false);
6629
  foreach ( $video_formats as $format => $format_stats ) {
6630
- if( !isset($attachment['kgflashmediaplayer-encode'.$format]) ) {
6631
- if ( $options['encode_'.$format] == false ) { $attachment['kgflashmediaplayer-encode'.$format] = "false"; }
6632
- else { $attachment['kgflashmediaplayer-encode'.$format] = "notchecked"; }
6633
  }
6634
  }
6635
 
@@ -7112,7 +7198,6 @@ function kgvid_make_thumbs($postID, $movieurl, $numberofthumbs, $i, $iincreaser,
7112
  $moviefilepath = get_attached_file($postID);
7113
  if ( !file_exists($moviefilepath) ) {
7114
  $moviefilepath = esc_url_raw(str_replace(" ", "%20", $movieurl));
7115
- $moviefilepath = str_replace("https://", "http://", $moviefilepath);
7116
  }
7117
 
7118
  $kgvid_postmeta = kgvid_get_attachment_meta($postID);
@@ -7135,15 +7220,13 @@ function kgvid_make_thumbs($postID, $movieurl, $numberofthumbs, $i, $iincreaser,
7135
  }
7136
  else {
7137
  $moviefilepath = esc_url_raw(str_replace(" ", "%20", $movieurl));
7138
- $moviefilepath = str_replace("https://", "http://", $moviefilepath);
7139
  $movie_info = kgvid_get_video_dimensions($moviefilepath);
7140
  }
7141
 
7142
  if ($movie_info['worked'] == true) { //if FFMPEG was able to open the file
7143
 
7144
- $movie_extension = pathinfo(parse_url($movieurl, PHP_URL_PATH), PATHINFO_EXTENSION);
7145
- $moviefilebasename = sanitize_file_name(basename($movieurl,'.'.$movie_extension));
7146
- $thumbnailfilebase = $uploads['url']."/thumb_tmp/".$moviefilebasename;
7147
 
7148
  $movie_width = $movie_info['width'];
7149
  $movie_height = $movie_info['height'];
@@ -7187,7 +7270,7 @@ function kgvid_make_thumbs($postID, $movieurl, $numberofthumbs, $i, $iincreaser,
7187
  $movieoffset = "0";
7188
  }
7189
 
7190
- $thumbnailfilename[$i] = $jpgpath.$moviefilebasename."_thumb".round($movieoffset).".jpg";
7191
  $thumbnailfilename[$i] = str_replace(" ", "_", $thumbnailfilename[$i]);
7192
 
7193
  if ( !empty($options['htaccess_login']) && strpos($moviefilepath, 'http://') === 0 ) {
@@ -7201,25 +7284,29 @@ function kgvid_make_thumbs($postID, $movieurl, $numberofthumbs, $i, $iincreaser,
7201
 
7202
  $ffmpeg_options = apply_filters( 'kgvid_thumbnail_ffmpeg_options', $ffmpeg_options );
7203
 
7204
- $thumbnailurl = $thumbnailfilebase."_thumb".round($movieoffset).'.jpg';
7205
- $thumbnailurl = str_replace(" ", "_", $thumbnailurl);
 
7206
 
 
7207
  exec(escapeshellcmd($ffmpegPath." ".$ffmpeg_options).$watermark_strings['filter'].escapeshellcmd(' "'.$thumbnailfilename[$i].'"'));
 
 
7208
  if ( is_file($thumbnailfilename[$i]) )
7209
  kgvid_schedule_cleanup_generated_files('thumbs');
7210
 
7211
- $thumbnaildisplaycode = '<div class="kgvid_thumbnail_select" name="attachments['.$postID.'][thumb'.$i.']" id="attachments-'.$postID.'-thumb'.$i.'"><label for="kgflashmedia-'.$postID.'-thumbradio'.$i.'"><img src="'.$thumbnailurl.'?'.rand().'" width="200" height="'.$thumbnailheight.'" class="kgvid_thumbnail"></label><br /><input type="radio" name="attachments['.$postID.'][thumbradio_'.$postID.']" id="kgflashmedia-'.$postID.'-thumbradio'.$i.'" value="'.str_replace('/thumb_tmp/', '/', $thumbnailurl).'" onchange="kgvid_select_thumbnail(this.value, \''.$postID.'\', '.$movieoffset.', jQuery(this).parent().find(\'img\')[0]);"></div>';
7212
 
7213
  $i++;
7214
 
7215
  $arr = array (
7216
- "thumbnaildisplaycode"=>$thumbnaildisplaycode,
7217
- "movie_width"=>$movie_width,
7218
- "movie_height"=>$movie_height,
7219
- "lastthumbnumber"=>$i,
7220
- "movieoffset"=>$movieoffset,
7221
- "thumb_url"=>str_replace('/thumb_tmp/', '/', $thumbnailurl),
7222
- "real_thumb_url" => $thumbnailurl
7223
  );
7224
 
7225
  return $arr;
@@ -7277,29 +7364,28 @@ function kgvid_enqueue_videos($postID, $movieurl, $encode_checked, $parent_id, $
7277
  foreach ( $video_formats as $format => $format_stats ) {
7278
  if ( array_key_exists($format, $encode_checked) && $encode_checked[$format] == "true" ) {
7279
  if ( !$encodevideo_info[$format]['exists'] ) {
7280
- if ( $format_stats['type'] == "h264" && $format != "fullres" &&
7281
- (
7282
- ( strpos($mime_type_check['type'], "mp4") !== false && $movie_height <= $format_stats['height'] ) ||
7283
- ( strpos($mime_type_check['type'], "mp4") === false && $movie_height < $format_stats['height'] )
 
 
7284
  )
7285
  ) {
7286
- $movie_extension = pathinfo($movieurl, PATHINFO_EXTENSION);
7287
- if ( $encode_checked['fullres'] == "true" || in_array($movie_extension, $h264extensions) || $movie_height < intval($format) ) {
7288
- $encode_formats[$format]['status'] = "lowres";
7289
- } //skip if the resolution of an existing video is lower than the HD format
7290
  }
7291
  else {
7292
  $encode_formats[$format]['status'] = "queued";
7293
  $encode_formats[$format]['name'] = $format_stats['name'];
7294
  $encode_list[$format] = $format_stats['name'];
7295
- if ( isset($kgvid_postmeta) ) { $kgvid_postmeta['encode'.$format] = 'on'; }
7296
  }
7297
  } // if video doesn't already exist
7298
  else { $encode_formats[$format]['status'] = "encoded"; }
7299
  } // if user wants to encode format
7300
  else {
7301
  $encode_formats[$format]['status'] = "notchecked";
7302
- if ( isset($kgvid_postmeta) ) { $kgvid_postmeta['encode'.$format] = 'notchecked'; }
7303
  }
7304
  }//end loop through video formats
7305
 
@@ -7334,11 +7420,17 @@ function kgvid_enqueue_videos($postID, $movieurl, $encode_checked, $parent_id, $
7334
  if ( $value['status'] == "queued" && array_key_exists($format, $encode_list) ) {
7335
  unset($encode_list[$format]);
7336
  }
7337
- elseif ( $value['status'] == "queued" && $encode_checked[$format] != "true" ) {
 
 
 
7338
  $queue_entry['encode_formats'][$format]['status'] = 'notchecked';
7339
  $encode_list[$format] = $video_formats[$format]['name'];
7340
  }
7341
- elseif ( $value['status'] == "encoding" || $encode_checked[$format] != "true" ) {
 
 
 
7342
  $queue_entry['encode_formats'][$format] = $entry['encode_formats'][$format];
7343
  } //don't edit queue entry for anything that's currently encoding or not checked
7344
 
@@ -7554,7 +7646,6 @@ function kgvid_encode_videos() {
7554
  if ( get_post_type($video['attachmentID']) == "attachment" ) { $moviefilepath = get_attached_file($video['attachmentID']); }
7555
  elseif ( empty($moviefilepath) || !file_exists($moviefilepath) ) {
7556
  $moviefilepath = str_replace(" ", "%20", esc_url_raw($video['movieurl']));
7557
- $moviefilepath = str_replace("https://", "http://", $moviefilepath);
7558
  }
7559
 
7560
  $movie_info = $video['movie_info'];
@@ -7606,8 +7697,7 @@ function kgvid_encode_videos() {
7606
  }
7607
  }
7608
 
7609
-
7610
- if ( $format_stats['type'] == "webm" || $format_stats['type'] == "ogv" ) { //if it's not H.264 they both work essentially the same
7611
  if ( ! $encodevideo_info[$queued_format]['exists'] || ($encodevideo_info['sameserver'] && filesize($encodevideo_info[$queued_format]['filepath']) < 24576) ) {
7612
  if ( $movie_info['configuration']['libvorbis'] == "true" && $movie_info['configuration'][$video_formats[$queued_format]['vcodec']] == "true" ) {
7613
 
@@ -7636,15 +7726,16 @@ function kgvid_encode_videos() {
7636
 
7637
  $logfile = $uploads['path'].'/'.str_replace(" ", "_", $encodevideo_info['moviefilebasename']).'_'.$queued_format.'_'.sprintf("%04s",mt_rand(1, 1000)).'_encode.txt';
7638
 
 
7639
  $cmd = escapeshellcmd($encode_string[1]).$encode_string[2].escapeshellcmd($encode_string[3]);
7640
-
7641
  if ( !empty($cmd) ) { $cmd = $cmd.' > "'.$logfile.'" 2>&1 & echo $!'; }
7642
-
7643
  else {
7644
  $arr = array ( "embed_display"=>"<span class='kgvid_warning'>".__("Error: Command 'escapeshellcmd' is disabled on your server.", 'video-embed-thumbnail-generator')."</span>" );
7645
  return $arr;
7646
  }
7647
  $process = new kgvid_Process($cmd);
 
7648
 
7649
  sleep(1);
7650
 
@@ -7707,8 +7798,11 @@ function kgvid_test_ffmpeg() {
7707
  $suffix = $video_formats[$options['sample_format']]['suffix'];
7708
 
7709
  $encode_string = $options['encode_string'];
 
 
7710
  $cmd = escapeshellcmd($encode_string[1]).$encode_string[2].escapeshellcmd($encode_string[3]);
7711
  exec ( $cmd.' 2>&1', $output );
 
7712
  $arr['output'] = implode("\n", $output);
7713
 
7714
  if ( file_exists($uploads['path']."/sample-video-h264".$suffix) ) {
@@ -7719,9 +7813,12 @@ function kgvid_test_ffmpeg() {
7719
 
7720
  if ( !empty($options['ffmpeg_watermark']['url']) ) {
7721
  if (!file_exists($uploads['path'].'/thumb_tmp')) { mkdir($uploads['path'].'/thumb_tmp'); }
 
 
7722
  $cmd = escapeshellcmd($options['app_path'].'/'.$options['video_app'].' -y -i "'.$uploads['path']."/sample-video-h264".$suffix.'" -qscale 1 -vframes 1 -f mjpeg '.$uploads['path'].'/thumb_tmp/watermark_test.jpg');
7723
- kgvid_schedule_cleanup_generated_files('thumbs');
7724
  exec ( $cmd );
 
 
7725
  if ( file_exists($uploads['path'].'/thumb_tmp/watermark_test.jpg') ) {
7726
  $arr['watermark_preview'] = $uploads['url'].'/thumb_tmp/watermark_test.jpg';
7727
  }
@@ -8245,6 +8342,7 @@ function kgvid_clear_completed_queue($type, $scope = 'site') {
8245
  }
8246
  if ( ($type == "manual" && $value['status'] == "queued")
8247
  || ($type == "queued" && $value['status'] == "Encoding Complete")
 
8248
  ) {
8249
  $keep[$video_key] = true;
8250
  }
@@ -8333,9 +8431,12 @@ function kgvid_fix_moov_atom($filepath) {
8333
 
8334
  if ( $options['moov'] == 'qt-faststart' && file_exists($filepath) ) {
8335
  $faststart_tmp_file = str_replace('.mp4', '-faststart.mp4', $filepath);
 
 
8336
  $cmd = escapeshellcmd($options['app_path']."/".$options['moov']." ".$filepath." ".$faststart_tmp_file)." 2>&1";
8337
  $output .= "\n".$cmd."\n";
8338
  exec($cmd, $qtfaststart_output, $returnvalue);
 
8339
  $output .= implode("\n", $qtfaststart_output);
8340
  if ( file_exists($faststart_tmp_file) ) {
8341
  unlink($filepath);
@@ -8344,9 +8445,11 @@ function kgvid_fix_moov_atom($filepath) {
8344
  }//if qt-faststart is selected
8345
 
8346
  if ( $options['moov'] == 'MP4Box' ) {
 
8347
  $cmd = escapeshellcmd($options['app_path']."/".$options['moov']." -inter 500 ".$filepath)." 2>&1";
8348
  $output .= "\n".$cmd."\n";
8349
  exec($cmd, $mp4box_output, $returnvalue);
 
8350
  $output .= implode("\n", $mp4box_output);
8351
  }//if MP4Box is selected
8352
 
3
  Plugin Name: Video Embed & Thumbnail Generator
4
  Plugin URI: http://www.kylegilman.net/2011/01/18/video-embed-thumbnail-generator-wordpress-plugin/
5
  Description: Generates thumbnails, HTML5-compliant videos, and embed codes for locally hosted videos. Requires FFMPEG or LIBAV for encoding.
6
+ Version: 4.6.22
7
  Author: Kyle Gilman
8
  Author URI: http://www.kylegilman.net/
9
  Text Domain: video-embed-thumbnail-generator
60
  $edit_others_capable = kgvid_check_if_capable('edit_others_posts');
61
 
62
  $options = array(
63
+ "version" => '4.6.22',
64
  "embed_method" => "Video.js",
65
  "jw_player_id" => "",
66
  "template" => false,
67
  "template_gentle" => "on",
68
  "replace_format" => "fullres",
 
 
 
 
 
 
 
 
 
69
  "custom_format" => array(
70
  'format' => 'h264',
71
  'width' => '',
189
  "alwaysloadscripts" => false
190
  );
191
 
192
+ $video_formats = kgvid_video_formats();
193
+ foreach ($video_formats as $format => $format_stats ) {
194
+ if (array_key_exists('default_encode', $format_stats)) {
195
+ $options['encode'][$format] = $format_stats['default_encode'];
196
+ }
197
+ else { $options['encode'][$format] = false; }
198
+ }
199
+
200
  return $options;
201
 
202
  }
278
  'play_75' => '0',
279
  'completeviews' => '0',
280
  'pickedformat' => '',
281
+ 'encode' => $options['encode'],
 
 
 
 
 
 
 
 
 
 
282
  'rotate' => '',
283
  'autothumb-error' => '',
284
  'numberofthumbs' => $options['generate_thumbs'],
323
 
324
  }
325
 
326
+ $old_meta_encode_keys = array(
327
+ 'encodefullres',
328
+ 'encode1080',
329
+ 'encode720',
330
+ 'encode480',
331
+ 'encodemobile',
332
+ 'encodewebm',
333
+ 'encodeogg',
334
+ 'encodecustom',
335
+ );
336
+
337
+ $old_meta_exists = false;
338
+
339
+ foreach ($old_meta_encode_keys as $old_key) {
340
+ if ( array_key_exists($old_key, $kgvid_postmeta) ) {
341
+ $format = str_replace('encode', '', $old_key);
342
+ $kgvid_postmeta['encode'][$format] = $kgvid_postmeta[$old_key];
343
+ unset($kgvid_postmeta[$old_key]);
344
+ $old_meta_exists = true;
345
+ }
346
+ }
347
+
348
+ if ( $old_meta_exists ) { kgvid_save_attachment_meta($post_id, $kgvid_postmeta); }
349
+
350
  }
351
 
352
  $kgvid_postmeta = array_merge($meta_key_array, $kgvid_postmeta); //make sure all keys are set
401
 
402
  }
403
 
404
+ function kgvid_video_formats( $return_replace = false, $return_customs = true, $return_dontembeds = true ) {
405
 
406
  $options = kgvid_get_options();
407
 
415
  "extension" => "mp4",
416
  "mime" => "video/mp4",
417
  "suffix" => "-fullres.mp4",
418
+ "vcodec" => "libx264",
419
+ "default_encode" => false
420
  ),
421
  "1080" => array(
422
  "name" => "1080p H.264",
428
  "mime" => "video/mp4",
429
  "suffix" => "-1080.mp4",
430
  "old_suffix" => "-1080.m4v",
431
+ "vcodec" => "libx264",
432
+ "default_encode" => "on"
433
  ),
434
  "720" => array(
435
  "name" => "720p H.264",
441
  "mime" => "video/mp4",
442
  "suffix" => "-720.mp4",
443
  "old_suffix" => "-720.m4v",
444
+ "vcodec" => "libx264",
445
+ "default_encode" => "on"
446
  ),
447
  "480" => array(
448
  "name" => "480p H.264",
454
  "mime" => "video/mp4",
455
  "suffix" => "-480.mp4",
456
  "old_suffix" => "-480.m4v",
457
+ "vcodec" => "libx264",
458
+ "default_encode" => "on"
459
  ),
460
  "mobile" => array(
461
  "name" => "360p H.264",
467
  "suffix" => "-360.mp4",
468
  "mime" => "video/mp4",
469
  "old_suffix" => "-ipod.m4v",
470
+ "vcodec" => "libx264",
471
+ "default_encode" => "on"
472
  ),
473
  "webm" => array(
474
+ "name" => "WEBM VP8",
475
+ "label" => 'WEBM VP8',
476
  "width" => INF,
477
  "height" => INF,
478
  "type" => "webm",
479
  "extension" => "webm",
480
  "mime" => "video/webm",
481
  "suffix" => ".webm",
482
+ "vcodec" => "libvpx",
483
+ "default_encode" => false
484
  ),
485
  "vp9" => array(
486
  "name" => "WEBM VP9",
487
  "label" => 'WEBM VP9',
488
  "width" => INF,
489
  "height" => INF,
490
+ "type" => "vp9",
491
  "extension" => "webm",
492
  "mime" => "video/webm",
493
  "suffix" => "-vp9.webm",
494
+ "vcodec" => "libvpx-vp9",
495
+ "default_encode" => false
496
  ),
497
  "ogg" => array(
498
  "name" => "OGV",
503
  "extension" => "ogv",
504
  "mime" => "video/ogg",
505
  "suffix" => ".ogv",
506
+ "vcodec" => "libtheora",
507
+ "default_encode" => false
508
  )
509
  );
510
 
520
  "extension" => "mp4",
521
  "mime" => "video/mp4",
522
  "suffix" => "-custom.mp4",
523
+ "vcodec" => "libx264",
524
+ "default_encode" => false
525
  ),
526
  "custom_webm" => array(
527
  "name" => __('Custom WEBM', 'video-embed-thumbnail-generator'),
532
  "extension" => "webm",
533
  "mime" => "video/webm",
534
  "suffix" => "-custom.webm",
535
+ "vcodec" => "libvpx",
536
+ "default_encode" => false
537
+ ),
538
+ "custom_vp9" => array(
539
+ "name" => __('Custom VP9 WEBMP', 'video-embed-thumbnail-generator'),
540
+ "label" => __('Custom VP9 WEBM', 'video-embed-thumbnail-generator'),
541
+ "width" => 0,
542
+ "height" => 0,
543
+ "type" => "vp9",
544
+ "extension" => "webm",
545
+ "mime" => "video/webm",
546
+ "suffix" => "-customvp9.webm",
547
+ "vcodec" => "libvpx-vp9",
548
+ "default_encode" => false
549
  ),
550
  "custom_ogg" => array(
551
  "name" => __('Custom OGV', 'video-embed-thumbnail-generator'),
556
  "extension" => "ogv",
557
  "mime" => "video/ogv",
558
  "suffix" => "-custom.ogv",
559
+ "vcodec" => "libtheora",
560
+ "default_encode" => false
561
  )
562
  );
563
  }
580
 
581
  if ( !$return_replace && $options['replace_format'] != 'fullres' ) { unset($video_formats[$options['replace_format']]); }
582
 
583
+ return apply_filters('kgvid_video_formats', $video_formats, $return_replace, $return_customs, $return_dontembeds);
584
 
585
  }
586
 
768
 
769
  }
770
 
771
+ function kgvid_set_locale($filepath) {
772
+
773
+ $old_locale = setlocale(LC_CTYPE, 0);
774
+ $escaped_filepath = escapeshellcmd($filepath);
775
+
776
+ if ($filepath != $escaped_filepath) {
777
+
778
+ $wp_locale = get_locale();
779
+ if ( strlen($wp_locale) == 4 ) {
780
+ $locale_name = $wp_locale.'.UTF-8';
781
+ }
782
+ else {
783
+ $locale_name = "en_US.UTF-8";
784
+ }
785
+
786
+ $new_locale = setlocale(LC_CTYPE, $locale_name);
787
+ if ( !$new_locale ) {
788
+ $new_locale = setlocale(LC_CTYPE, "en_US.UTF-8");
789
+ }
790
+
791
+ }
792
+
793
+ return $old_locale;
794
+
795
+ }
796
+
797
  function kgvid_aac_encoders() {
798
 
799
  $aac_array = array("libfdk_aac", "libfaac", "aac", "libvo_aacenc");
1073
  else {
1074
  $movieurl = strtok($movieurl,'?');
1075
  $sanitized_url['noextension'] = preg_replace("/\\.[^.\\s]{3,4}$/", "", $movieurl);
1076
+ $sanitized_url['basename'] = sanitize_file_name(basename($movieurl));
1077
+ $sanitized_url['basename'] = str_replace('.'.$movie_extension, '', $sanitized_url['basename']);
1078
  }
1079
 
1080
  $sanitized_url['singleurl_id'] = "singleurl_".preg_replace('/[^a-zA-Z0-9]/', '_', $sanitized_url['basename']);
1120
  if (function_exists('escapeshellcmd')) {
1121
  $exec_enabled = true;
1122
  $test_path = rtrim($options['app_path'], '/');
1123
+ $old_locale = kgvid_set_locale(plugin_dir_path(__FILE__).'images/sample-video-h264.mp4'); //fixes UTF-8 encoding problems
1124
  $cmd = escapeshellcmd($test_path.'/'.$options['video_app'].' -i "'.plugin_dir_path(__FILE__).'images/sample-video-h264.mp4" -vframes 1 -f mjpeg '.$uploads['path'].'/ffmpeg_exists_test.jpg').' 2>&1';
1125
  exec ( $cmd, $output, $returnvalue );
1126
+ $restore_locale = setlocale(LC_CTYPE, $old_locale);
1127
  }
1128
  else { $function = "ESCAPESHELLCMD"; }
1129
  }
1133
 
1134
  if ( !file_exists($uploads['path'].'/ffmpeg_exists_test.jpg') ) { //if FFMPEG has not executed successfully
1135
  $test_path = substr($test_path, 0, -strlen($options['video_app'])-1 );
1136
+ $old_locale = kgvid_set_locale(plugin_dir_path(__FILE__).'images/sample-video-h264.mp4'); //fixes UTF-8 encoding problems
1137
  $cmd = escapeshellcmd($test_path.'/'.$options['video_app'].' -i "'.plugin_dir_path(__FILE__).'images/sample-video-h264.mp4" -vframes 1 -f mjpeg '.$uploads['path'].'/ffmpeg_exists_test.jpg');
1138
  exec ( $cmd );
1139
+ $restore_locale = setlocale(LC_CTYPE, $old_locale);
1140
  }
1141
 
1142
  if ( file_exists($uploads['path'].'/ffmpeg_exists_test.jpg') ) { //FFMEG has executed successfully
1383
  $ffmpegPath = $options['app_path']."/".$options['video_app'];
1384
  $movie_info = array();
1385
 
 
 
1386
  if ( strpos($video, 'http://') === 0 ) { //if it's a URL
1387
  $video_id = kgvid_url_to_id($video);
1388
  if ( $video_id ) {
1395
  }
1396
  }
1397
  }
1398
+ $old_locale = kgvid_set_locale($video); //fixes UTF-8 encoding problems
1399
  $command = escapeshellcmd($ffmpegPath . ' -i "' . $video . '"');
1400
  $command = $command.' 2>&1';
1401
  exec ( $command, $output );
1402
+ $restore_locale = setlocale(LC_CTYPE, $old_locale);
1403
  $lastline = end($output);
1404
  $lastline = prev($output)."<br />".$lastline;
1405
  $movie_info['output'] = addslashes($lastline);
1430
  case "-90": $movie_info['rotate'] = 270; break;
1431
  default: $movie_info['rotate'] = ""; break;
1432
  }
1433
+ $old_locale = kgvid_set_locale($video); //fixes UTF-8 encoding problems
1434
  $command = escapeshellcmd($ffmpegPath . ' -i "' . $video . '" -codecs');
1435
  $command = $command.' 2>&1';
1436
  exec ( $command, $output );
1437
+ $restore_locale = setlocale(LC_CTYPE, $old_locale);
1438
  $output = implode("\n", $output);
1439
  $configuration = array();
1440
  $video_lib_array = array('libtheora', 'libvorbis', 'libvpx', 'libvpx-vp9', 'libx264');
1611
  }
1612
  else { $watermark_valign = ""; } //top justified
1613
 
 
1614
  if ( strpos($ffmpeg_watermark['url'], 'http://') === 0 ) {
1615
  $watermark_id = false;
1616
  $watermark_id = kgvid_url_to_id($ffmpeg_watermark['url']);
1661
  $qscale_flag = "qscale";
1662
  }
1663
 
1664
+ $rotate_strings = kgvid_ffmpeg_rotate_strings($rotate, $width, $height);
1665
+ $width = $rotate_strings['width']; //in case rotation requires swapping height and width
1666
+ $height = $rotate_strings['height'];
1667
+
1668
  if ( $options['rate_control'] == "crf" ) {
1669
  $crf_option = $video_formats[$format]['type'].'_CRF';
1670
+ if ( $video_formats[$format]['type'] == 'vp9' ) {
1671
+ $options['vp9_CRF'] = round((-0.000002554 * $width * $height) + 35); //formula to generate close to Google-recommended CRFs https://developers.google.com/media/vp9/settings/vod/
1672
+ }
1673
  $crf_flag = "crf";
1674
  if ( $video_formats[$format]['type'] == 'ogv' ) { $crf_flag = $qscale_flag; } //ogg doesn't do CRF
1675
  $rate_control_flag = " -".$crf_flag." ".$options[$crf_option];
1676
  }
1677
  else {
1678
+ if ( $video_formats[$format]['type'] == 'vp9' ) {
1679
+ $average_bitrate = round(102 + 0.000876 * $width * $height + 1.554*pow(10, -10) * pow($width * $height, 2) );
1680
+ $maxrate = round($average_bitrate * 1.45);
1681
+ $minrate = round($average_bitrate * .5);
1682
+ $rate_control_flag = " -".$video_bitrate_flag." ".$average_bitrate."k -maxrate ".$maxrate."k -minrate ".$minrate."k";
1683
+ }
1684
+ else {
1685
+ $rate_control_flag = " -".$video_bitrate_flag." ".round(floatval($options['bitrate_multiplier'])*$width*$height*30/1024)."k";
1686
+ }
1687
  }
1688
 
 
 
 
 
1689
  $watermark_strings = kgvid_ffmpeg_watermark_strings($options['ffmpeg_watermark'], $movie_info['width'], $rotate_strings['complex']);
1690
 
1691
  if ( $video_formats[$format]['type'] == 'h264' ) {
1722
  }
1723
  else { //if it's not H.264 the settings are basically the same
1724
  $ffmpeg_options = "-acodec libvorbis -".$audio_bitrate_flag." ".$options['audio_bitrate']."k -s ".$width."x".$height." -vcodec ".$video_formats[$format]['vcodec'];
1725
+ if ( $options['rate_control'] == "crf" ) {
1726
+ if ( $video_formats[$format]['type'] == 'webm' ) {
1727
+ $ffmpeg_options .= " -".$video_bitrate_flag." ".round(floatval($options['bitrate_multiplier'])*1.25*$width*$height*30/1024)."k"; //set a max bitrate 25% larger than the ABR. Otherwise libvpx goes way too low.
1728
+ }
1729
+ if ( $video_formats[$format]['type'] == 'vp9' ) {
1730
+ $ffmpeg_options .= " -".$video_bitrate_flag." 0";
1731
+ }
1732
  }
1733
  }
1734
 
2419
  $options = kgvid_get_options();
2420
  $code = "";
2421
  $id_array = array();
2422
+ $video_formats = kgvid_video_formats(false, true, false);
2423
  $compatible = array("flv", "f4v", "mp4", "mov", "m4v", "ogv", "ogg", "webm");
2424
  $h264compatible = array("mp4", "mov", "m4v");
2425
 
3516
 
3517
  if ( get_post_type($post_id) == "attachment" ) {
3518
  $kgvid_postmeta = kgvid_get_attachment_meta($post_id);
3519
+ if ( array_key_exists('encode', $kgvid_postmeta) && array_key_exists($format, $kgvid_postmeta['encode']) ) {
3520
+ $encodeset = $kgvid_postmeta['encode'][$format];
3521
+ }
3522
  else { $encodeset = 'false'; }
3523
  $post = get_post($post_id);
3524
  $current_user = wp_get_current_user();
3529
  }
3530
 
3531
  }
3532
+ if ( $encodeset == "false" && strpos($format, 'custom_') === false ) {
3533
+ if (array_key_exists($format, $options['encode'])) { $encodeset = "on"; }
3534
+ else { $encodeset = false; }
3535
+ }
3536
 
3537
  if ( $encodeset == "on" || $status == "queued" ) { $checked = 'checked'; }
3538
 
3545
 
3546
  if ( !empty($encodevideo_info) ) {
3547
 
3548
+ if ( array_key_exists($format, $encodevideo_info) && $encodevideo_info[$format]['exists'] ) { //if the video file exists
3549
 
3550
  if ( array_key_exists('id', $encodevideo_info[$format]) ) {
3551
  $child_id = $encodevideo_info[$format]['id'];
3625
  $encode_checked = $_POST['encodeformats'];
3626
  $kgvid_postmeta = kgvid_get_attachment_meta($post_id);
3627
  foreach ( $encode_checked as $format => $checked ) {
3628
+ if ( $checked == "true" ) { $kgvid_postmeta['encode'][$format] = 'on'; }
3629
+ else {$kgvid_postmeta['encode'][$format] = 'notchecked'; }
3630
  }
3631
  kgvid_save_attachment_meta($post_id, $kgvid_postmeta);
3632
  }
3711
  unset($video_formats['custom_h264']);
3712
  unset($video_formats['custom_webm']);
3713
  unset($video_formats['custom_ogg']);
3714
+ unset($video_formats['custom_vp9']);
3715
  }
3716
 
3717
  if ( $options['ffmpeg_exists'] == "notinstalled" ) {
3784
  if ( !empty($encodevideo_info) && !$encodevideo_info[$format]['exists']
3785
  && (
3786
  strpos($format, 'custom_') === 0 //skip custom formats that don't exist
3787
+ || ( $format != 'fullres' && !array_key_exists($format, $options['encode']) && $options['hide_video_formats'] )
3788
  )
3789
  ) { continue; }
3790
 
3810
  if ( $meta_array['something_to_encode'] == true ) { $something_to_encode = true; }
3811
  if ( $meta_array['encoding_now'] == true ) { $encoding_now = true; }
3812
 
3813
+ $checkboxes .= "\n\t\t\t".'<li><input class="kgvid_encode_checkbox" type="checkbox" id="attachments-'.$blog_id_text.$post_id.'-kgflashmediaplayer-encode'.$format.'" name="attachments'.$blog_name_text.'['.$post_id.'][kgflashmediaplayer-encode]['.$format.']" '.$meta_array['checked'].' '.$ffmpeg_disabled_text.$meta_array['disabled'].' data-format="'.$format.'"> <label for="attachments-'.$blog_id_text.$post_id.'-kgflashmediaplayer-encode'.$format.'">'.$format_stats['name'].'</label> <span id="attachments-'.$blog_id_text.$post_id.'-kgflashmediaplayer-meta'.$format.'" class="kgvid_format_meta">'.$meta_array['meta'].'</span>';
3814
 
3815
  if ( !$security_disabled && $is_attachment && empty($meta_array['disabled']) && $format != 'fullres' && $page != 'queue' ) { $checkboxes .= "<span id='pick-".$post_id."-".$format."' class='button kgvid_encode_checkbox_button' data-choose='".sprintf( __('Choose %s', 'video-embed-thumbnail-generator'), $format_stats['name'] )."' data-update='".sprintf( __('Set as %s', 'video-embed-thumbnail-generator'), $format_stats['name'] )."' onclick='kgvid_pick_format(this, \"".$post_id."\", \"".esc_attr($format_stats['mime'])."\", \"".$format."\", \"".esc_attr($movieurl)."\", \"".$blog_id."\");'>".__('Choose from Library', 'video-embed-thumbnail-generator')."</span>";
3816
  }
4923
  $items['custom'] = __('Custom', 'video-embed-thumbnail-generator');
4924
 
4925
  echo "<div class='kgvid_video_app_required'>";
4926
+ echo "<input ".checked( array_key_exists('fullres', $options['encode']), true, false )." id='encode_fullres' name='kgvid_video_embed_options[encode][fullres]' type='checkbox' /> <label for='encode_fullres'>".__('Replace original with', 'video-embed-thumbnail-generator');
4927
 
4928
  echo " <select id='replace_format' name='kgvid_video_embed_options[replace_format]' class='affects_ffmpeg' onchange='kgvid_change_replace_format();'>";
4929
  foreach($items as $value=>$name) {
4932
  }
4933
  echo "</select> ";
4934
 
 
4935
  echo "</label> <span class='kgvid_tooltip wp-ui-text-highlight'><span class='kgvid_tooltip_classic'>".__('If you have FFMPEG/LIBAV and the proper libraries installed, you can choose to replace your uploaded video with your preferred format, and also transcode into several additional formats depending on the resolution of your original source. Different browsers have different playback capabilities. Most desktop browsers can play H.264, and all modern mobile devices can play at least 360p H.264. If you create multiple H.264 resolutions, the highest resolution supported by the device will be served up automatically. The plugin will not upconvert your video, so if you upload a 720p video, it will not waste your time creating a 1080p version. There was a time when it seemed like a good idea to provide OGV or WEBM for some desktop browsers, but even Firefox allows H.264 playback on most operating systems now. I no longer recommend encoding OGV or WEBM. WEBM VP9 is a new technology and requires a version of FFMPEG or LIBAV newer than October 2013. Most browsers except Safari currently support it.', 'video-embed-thumbnail-generator')."</span></span><br />";
4936
+
4937
+ if (array_key_exists('fullres', $video_formats) ) {
4938
+ unset($video_formats['fullres']);
4939
+ }
4940
+ if (array_key_exists('custom', $video_formats) ) {
4941
+ unset($video_formats['custom']);
4942
+ }
4943
+
4944
+ foreach ( $video_formats as $format => $format_stats ) {
4945
+ echo "<input ".checked( array_key_exists($format, $options['encode']), true, false )." id='encode_".$format."' name='kgvid_video_embed_options[encode][".$format."]' type='checkbox' /> <label for='encode_".$format."'>".$format_stats['name']."</label><br />";
4946
+ }
4947
+
4948
+ echo "<input ".checked( array_key_exists('custom', $options['encode']), true, false )." id='encode_custom' name='kgvid_video_embed_options[encode][custom]' type='checkbox' /> <label for='encode_custom'>".__('Custom', 'video-embed-thumbnail-generator');
4949
+ $items = array(
4950
+ "H.264" => "h264",
4951
+ "WEBM VP8" => "webm",
4952
+ "WEBM VP9" => "vp9",
4953
+ "OGV" => "ogg"
4954
+ );
4955
  echo " <select id='custom_format_type' name='kgvid_video_embed_options[custom_format][format]' class='affects_ffmpeg'>";
4956
  foreach($items as $name=>$value) {
4957
  $selected = ($options['custom_format']['format']==$value) ? 'selected="selected"' : '';
5128
  $selected = ($options['rate_control']==$value) ? 'selected="selected"' : '';
5129
  echo "<option value='$value' $selected>$name</option>";
5130
  }
5131
+ echo "</select> <span class='kgvid_tooltip wp-ui-text-highlight'><span class='kgvid_tooltip_classic'>".__('Constant Rate Factor (CRF) attempts to maintain a particular quality output for the entire video and only uses bits the encoder determines are necessary. Average Bit Rate is similar to the method used in older versions of this plugin. If CRF is selected, WEBM encoding will also use the ABR setting to set a max bit rate 25% higher than the ABR. Without a max bit rate setting WEBM files are terrible quality. VP9 CRF and bitrates are set using a formula based on resolution that approximates <a href="https://developers.google.com/media/vp9/bitrate-modes/">Google\'s recommended VOD values</a>.', 'video-embed-thumbnail-generator')."</span></span>";
5132
  echo "</div>\n\t";
5133
  }
5134
 
5140
  $selected = ($options['h264_CRF']==$i) ? 'selected="selected"' : '';
5141
  echo "<option value='".$i."' $selected>".$i."</option>";
5142
  }
5143
+ echo "</select> H.264 <span class='kgvid_tooltip wp-ui-text-highlight'><span class='kgvid_tooltip_classic'>".__('Lower values are higher quality. 18 is considered visually lossless. Default is 23.', 'video-embed-thumbnail-generator')."</span></span><br />";
5144
 
5145
  echo "<select id='webm_CRF' name='kgvid_video_embed_options[webm_CRF]' class='affects_ffmpeg'>";
5146
  for ($i = 4; $i <= 63; $i++ ) {
5147
  $selected = ($options['webm_CRF']==$i) ? 'selected="selected"' : '';
5148
  echo "<option value='".$i."' $selected>".$i."</option>";
5149
  }
5150
+ echo "</select> WEBM VP8 <span class='kgvid_tooltip wp-ui-text-highlight'><span class='kgvid_tooltip_classic'>".__('Lower values are higher quality. Default is 10.', 'video-embed-thumbnail-generator')."</span></span><br />\n\t";
5151
 
5152
  echo "<select id='ogv_CRF' name='kgvid_video_embed_options[ogv_CRF]' class='affects_ffmpeg'>";
5153
  for ($i = 1; $i <= 10; $i++ ) {
5527
  );
5528
  }
5529
 
5530
+ if ( version_compare( $options['version'], '4.6.22', '<' ) ) {
5531
+ $options['version'] = '4.6.22';
5532
+ $video_formats = kgvid_video_formats();
5533
+ foreach ($video_formats as $format => $format_stats ) {
5534
+ if ( array_key_exists('encode_'.$format, $options) && $options['encode_'.$format] == 'on' ) {
5535
+ $options['encode'][$format] = $options['encode_'.$format];
5536
+ }
5537
+ }
5538
+ }
5539
+
5540
  if ( $options['version'] != $default_options['version'] ) { $options['version'] = $default_options['version']; }
5541
  if ( $options !== $options_old ) { update_option('kgvid_video_embed_options', $options); }
5542
  }
5582
  }
5583
  else { $input['ffmpeg_exists'] = $options['ffmpeg_exists']; }
5584
 
5585
+ if ( $input['ffmpeg_exists'] == "notinstalled" ) {
5586
+ $input['browser_thumbnails'] = "on"; //in case a user had FFMPEG installed and disabled it, they can't choose to disable browser thumbnails if it's no longer installed
5587
+ $input['auto_encode'] = false;
5588
+ $input['auto_encode_gif'] = false;
5589
+ $input['auto_thumb'] = false;
5590
+ }
5591
 
5592
  if ( $input['ffmpeg_thumb_watermark']['url'] != '' ) { //can't use browser thumbnails with ffmpeg watermark
5593
  $input['browser_thumbnails'] = false;
5627
  }
5628
  if ( $input['custom_format']['format'] == 'h264' ) {
5629
  $input['custom_format']['name'] .= ' H.264';
5630
+ $input['custom_format']['type'] = 'h264';
5631
  $input['custom_format']['extension'] = 'mp4';
5632
  $input['custom_format']['mime'] = 'video/mp4';
5633
  $input['custom_format']['vcodec'] = 'libx264';
5634
  }
5635
  else {
5636
  $input['custom_format']['name'] .= ' '.strtoupper($input['custom_format']['format']);
5637
+ $input['custom_format']['type'] = $video_formats[$input['custom_format']['format']]['type'];
5638
  $input['custom_format']['extension'] = $video_formats[$input['custom_format']['format']]['extension'];
5639
  $input['custom_format']['mime'] = $video_formats[$input['custom_format']['format']]['mime'];
5640
  $input['custom_format']['vcodec'] = $video_formats[$input['custom_format']['format']]['vcodec'];
 
5641
  }
5642
+
 
5643
  $input['custom_format']['suffix'] = '-custom.'.$input['custom_format']['extension'];
5644
 
5645
+ $input['custom_format']['default_encode'] = "on";
5646
+
5647
  } // if the custom format has been set
5648
  else {
5649
 
5729
  || strpos($setting, 'default_capabilities') !== false
5730
  || strpos($setting, 'ffmpeg_watermark') !== false
5731
  || strpos($setting, 'ffmpeg_thumb_watermark') !== false
5732
+ || strpos($setting, 'custom_format') !== false
5733
+ || strpos($setting, 'encode') !== false
5734
+ )
5735
  {
5736
  $validated_options[$setting] = $value;
5737
  }
5842
  foreach ( $thumb_output as $key=>$output ) {
5843
 
5844
  if ( $thumb_output[$key]['lastthumbnumber'] != 'break' ) {
5845
+ if ( $numberofthumbs == 1 ) {
5846
+ $index = false;
5847
+ }
5848
+ else {
5849
+ $index = $key;
5850
+ }
5851
  $thumb_id[$key] = kgvid_save_thumb($post_id, $post->post_title, $thumb_output[$key]['thumb_url'], $index);
5852
  }//end if there wasn't an error
5853
  else {
5890
  if ( substr(basename($filepath, '.'.$extension), -10) == '-noreplace'
5891
  || ( array_key_exists('original_replaced', $kgvid_postmeta) && $kgvid_postmeta['original_replaced'] == $options['replace_format'] )
5892
  ) {
5893
+ $options['encode']['fullres'] = false;
5894
  }
5895
 
5896
  if ( $post->post_mime_type == 'image/gif' ) {
5900
 
5901
  foreach ( $video_formats as $format => $format_stats ) {
5902
 
5903
+ if ( array_key_exists($format, $options['encode']) && $options['encode'][$format] == "on" ) {
5904
  $encode_checked[$format] = "true";
5905
  $something_to_encode = true;
5906
  }
5910
  }
5911
 
5912
  if ( $something_to_encode ) {
5913
+
5914
  $output = kgvid_enqueue_videos($post_id, $movieurl, $encode_checked, $post->post_parent);
5915
  $output = kgvid_encode_videos();
5916
 
6121
  $thumbnail_html = '<div class="kgvid_thumbnail_box kgvid_chosen_thumbnail_box">'.$kgvid_postmeta['autothumb-error'].'</div>';
6122
  }
6123
  elseif ( !empty($thumbnail_url) ) {
6124
+ $thumbnail_html = '<div class="kgvid_thumbnail_box kgvid_chosen_thumbnail_box"><img width="200" src="'.$thumbnail_url.'?'.rand().'"></div>';
6125
  }
6126
 
6127
  $choose_from_video_content = "";
6209
  $form_fields["kgflashmediaplayer-autothumb-error"]["input"] = "hidden";
6210
  $form_fields["kgflashmediaplayer-autothumb-error"]["value"] = $kgvid_postmeta['autothumb-error'];
6211
 
 
6212
  $form_fields["generator"]["label"] = _x("Thumbnails", 'Header for thumbnail section', 'video-embed-thumbnail-generator');
6213
  $form_fields["generator"]["input"] = "html";
6214
  $form_fields["generator"]["html"] = $choose_from_video_content.'
6395
  }
6396
  add_action('pre_get_posts', 'kgvid_hide_video_children');
6397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6398
  function kgvid_decode_base64_png($raw_png, $tmp_posterpath) {
6399
 
6400
  $raw_png = str_replace('data:image/png;base64,', '', $raw_png);
6420
  $total = $_POST['total'];
6421
  $index = $_POST['index']+1;
6422
 
6423
+ $sanitized_url = kgvid_sanitize_url($video_url);
6424
+ $posterfile = $sanitized_url['basename'].'_thumb'.$index;
6425
  if (!file_exists($uploads['path'].'/thumb_tmp')) { mkdir($uploads['path'].'/thumb_tmp'); }
6426
  $tmp_posterpath = $uploads['path'].'/thumb_tmp/'.$posterfile.'.png';
6427
  $thumb_url = $uploads['url'].'/'.$posterfile.'.jpg';
6457
  }
6458
 
6459
  kgvid_schedule_cleanup_generated_files('thumbs');
6460
+
6461
+ echo $thumb_url;
6462
  }
6463
 
6464
  die();
6501
  $tmp_posterpath = $uploads['path'].'/thumb_tmp/'.$posterfile;
6502
  $final_posterpath = $uploads['path'].'/'.$posterfile;
6503
 
6504
+ if ( file_exists($final_posterpath) ) {
6505
+ $old_thumb_id = kgvid_url_to_id($final_posterpath);
6506
+ if ( !empty($old_thumb_id) ) {
6507
+ $existing_posterpath = get_attached_file($old_thumb_id);
6508
+ if ( time() - filemtime($existing_posterpath) > 30 //file was created less than 30 seconds ago
6509
+ || abs( filesize($tmp_posterpath) - filesize($existing_posterpath) ) > 100 //filesize is more than 100 bytes different means it's probably a different image
6510
+ ) {
6511
+ wp_delete_post($old_thumb_id);
6512
+ }
6513
+ else {
6514
+ return $old_thumb_id; //if a new thumbnail was just created with the same name don't make a new one.
6515
+ }
6516
+ }
6517
+ }
6518
+
6519
  $success = false;
6520
  if ( !is_file($final_posterpath) ) { //if the file doesn't already exist
6521
  if ( is_file($tmp_posterpath) ) {
6559
  $filename = preg_replace('/\.[^.]+$/', '', basename($thumb_url));
6560
  if ( $user_ID == 0 ) { $user_ID = $video->post_author; }
6561
 
 
 
 
 
 
 
 
 
 
6562
  $attachment = array(
6563
  'guid' => $thumb_url,
6564
  'post_mime_type' => $wp_filetype['type'],
6631
  $thumbnail_src = wp_get_attachment_image_src($poster_id, 'thumbnail');
6632
  if ( is_array($thumbnail_src) && array_key_exists(0, $thumbnail_src) ) { $thumbnail_size_url = $thumbnail_src[0]; }
6633
  }
6634
+ $response['thumb_url'] = get_post_meta($post_id, "_kgflashmediaplayer-poster", true).'?'.rand();
6635
+ $response['thumbnail_size_url'] = $thumbnail_size_url.'?'.rand();
6636
  $response['thumb_error'] = $kgvid_postmeta['autothumb-error'];
6637
  echo json_encode($response);
6638
  die();
6659
  if( isset($attachment['kgflashmediaplayer-poster']) ) {
6660
 
6661
  $thumb_url = $attachment['kgflashmediaplayer-poster'];
 
6662
 
6663
+ if ( !empty($thumb_url) ) {
6664
  $thumb_id = kgvid_save_thumb($post['ID'], $post['post_title'], $thumb_url);
6665
  if ( $thumb_id ) {
6666
  $thumb_url = wp_get_attachment_url($thumb_id);
6713
 
6714
  $video_formats = kgvid_video_formats(false, false);
6715
  foreach ( $video_formats as $format => $format_stats ) {
6716
+ if( !isset($attachment['kgflashmediaplayer-encode'][$format]) ) {
6717
+ if ( !array_key_exists($format, $options['encode']) ) { $attachment['kgflashmediaplayer-encode'][$format] = "false"; }
6718
+ else { $attachment['kgflashmediaplayer-encode'][$format] = "notchecked"; }
6719
  }
6720
  }
6721
 
7198
  $moviefilepath = get_attached_file($postID);
7199
  if ( !file_exists($moviefilepath) ) {
7200
  $moviefilepath = esc_url_raw(str_replace(" ", "%20", $movieurl));
 
7201
  }
7202
 
7203
  $kgvid_postmeta = kgvid_get_attachment_meta($postID);
7220
  }
7221
  else {
7222
  $moviefilepath = esc_url_raw(str_replace(" ", "%20", $movieurl));
 
7223
  $movie_info = kgvid_get_video_dimensions($moviefilepath);
7224
  }
7225
 
7226
  if ($movie_info['worked'] == true) { //if FFMPEG was able to open the file
7227
 
7228
+ $sanitized_url = kgvid_sanitize_url($movieurl);
7229
+ $thumbnailfilebase = $uploads['url']."/thumb_tmp/".$sanitized_url['basename'];
 
7230
 
7231
  $movie_width = $movie_info['width'];
7232
  $movie_height = $movie_info['height'];
7270
  $movieoffset = "0";
7271
  }
7272
 
7273
+ $thumbnailfilename[$i] = $jpgpath.$sanitized_url['basename']."_thumb".$i.".jpg";
7274
  $thumbnailfilename[$i] = str_replace(" ", "_", $thumbnailfilename[$i]);
7275
 
7276
  if ( !empty($options['htaccess_login']) && strpos($moviefilepath, 'http://') === 0 ) {
7284
 
7285
  $ffmpeg_options = apply_filters( 'kgvid_thumbnail_ffmpeg_options', $ffmpeg_options );
7286
 
7287
+ $tmp_thumbnailurl = $thumbnailfilebase."_thumb".$i.'.jpg';
7288
+ $tmp_thumbnailurl = str_replace(" ", "_", $tmp_thumbnailurl);
7289
+ $final_thumbnailurl = str_replace('/thumb_tmp/', '/', $tmp_thumbnailurl);
7290
 
7291
+ $old_locale = kgvid_set_locale($moviefilepath); //fixes UTF-8 encoding problems
7292
  exec(escapeshellcmd($ffmpegPath." ".$ffmpeg_options).$watermark_strings['filter'].escapeshellcmd(' "'.$thumbnailfilename[$i].'"'));
7293
+ $restore_locale = setlocale(LC_CTYPE, $old_locale);
7294
+
7295
  if ( is_file($thumbnailfilename[$i]) )
7296
  kgvid_schedule_cleanup_generated_files('thumbs');
7297
 
7298
+ $thumbnaildisplaycode = '<div class="kgvid_thumbnail_select" name="attachments['.$postID.'][thumb'.$i.']" id="attachments-'.$postID.'-thumb'.$i.'"><label for="kgflashmedia-'.$postID.'-thumbradio'.$i.'"><img src="'.$tmp_thumbnailurl.'?'.rand().'" width="200" height="'.$thumbnailheight.'" class="kgvid_thumbnail"></label><br /><input type="radio" name="attachments['.$postID.'][thumbradio_'.$postID.']" id="kgflashmedia-'.$postID.'-thumbradio'.$i.'" value="'.$final_thumbnailurl.'" onchange="kgvid_select_thumbnail(this.value, \''.$postID.'\', '.$movieoffset.', jQuery(this).parent().find(\'img\')[0]);"></div>';
7299
 
7300
  $i++;
7301
 
7302
  $arr = array (
7303
+ "thumbnaildisplaycode" => $thumbnaildisplaycode,
7304
+ "movie_width" => $movie_width,
7305
+ "movie_height" => $movie_height,
7306
+ "lastthumbnumber" => $i,
7307
+ "movieoffset" => $movieoffset,
7308
+ "thumb_url" => $final_thumbnailurl,
7309
+ "real_thumb_url" => $tmp_thumbnailurl
7310
  );
7311
 
7312
  return $arr;
7364
  foreach ( $video_formats as $format => $format_stats ) {
7365
  if ( array_key_exists($format, $encode_checked) && $encode_checked[$format] == "true" ) {
7366
  if ( !$encodevideo_info[$format]['exists'] ) {
7367
+ $movie_extension = pathinfo($movieurl, PATHINFO_EXTENSION);
7368
+ if ( $format_stats['type'] == "h264"
7369
+ && $format != "fullres" && $movie_height <= $format_stats['height']
7370
+ && ( $encode_checked['fullres'] == "true"
7371
+ || in_array($movie_extension, $h264extensions)
7372
+ || $movie_height < $format_stats['height']
7373
  )
7374
  ) {
7375
+ $encode_formats[$format]['status'] = "lowres"; //skip if the resolution of an existing video is lower than the HD format
 
 
 
7376
  }
7377
  else {
7378
  $encode_formats[$format]['status'] = "queued";
7379
  $encode_formats[$format]['name'] = $format_stats['name'];
7380
  $encode_list[$format] = $format_stats['name'];
7381
+ if ( isset($kgvid_postmeta) ) { $kgvid_postmeta['encode'][$format] = 'on'; }
7382
  }
7383
  } // if video doesn't already exist
7384
  else { $encode_formats[$format]['status'] = "encoded"; }
7385
  } // if user wants to encode format
7386
  else {
7387
  $encode_formats[$format]['status'] = "notchecked";
7388
+ if ( isset($kgvid_postmeta) ) { $kgvid_postmeta['encode'][$format] = 'notchecked'; }
7389
  }
7390
  }//end loop through video formats
7391
 
7420
  if ( $value['status'] == "queued" && array_key_exists($format, $encode_list) ) {
7421
  unset($encode_list[$format]);
7422
  }
7423
+ elseif (
7424
+ $value['status'] == "queued" &&
7425
+ ( array_key_exists($format, $encode_checked) && $encode_checked[$format] != "true" )
7426
+ ) {
7427
  $queue_entry['encode_formats'][$format]['status'] = 'notchecked';
7428
  $encode_list[$format] = $video_formats[$format]['name'];
7429
  }
7430
+ elseif (
7431
+ $value['status'] == "encoding" ||
7432
+ ( array_key_exists($format, $encode_checked) && $encode_checked[$format] != "true" )
7433
+ ) {
7434
  $queue_entry['encode_formats'][$format] = $entry['encode_formats'][$format];
7435
  } //don't edit queue entry for anything that's currently encoding or not checked
7436
 
7646
  if ( get_post_type($video['attachmentID']) == "attachment" ) { $moviefilepath = get_attached_file($video['attachmentID']); }
7647
  elseif ( empty($moviefilepath) || !file_exists($moviefilepath) ) {
7648
  $moviefilepath = str_replace(" ", "%20", esc_url_raw($video['movieurl']));
 
7649
  }
7650
 
7651
  $movie_info = $video['movie_info'];
7697
  }
7698
  }
7699
 
7700
+ if ( $format_stats['type'] == "webm" || $format_stats['type'] == "ogv" || $format_stats['type'] == "vp9" ) { //if it's not H.264 they both work essentially the same
 
7701
  if ( ! $encodevideo_info[$queued_format]['exists'] || ($encodevideo_info['sameserver'] && filesize($encodevideo_info[$queued_format]['filepath']) < 24576) ) {
7702
  if ( $movie_info['configuration']['libvorbis'] == "true" && $movie_info['configuration'][$video_formats[$queued_format]['vcodec']] == "true" ) {
7703
 
7726
 
7727
  $logfile = $uploads['path'].'/'.str_replace(" ", "_", $encodevideo_info['moviefilebasename']).'_'.$queued_format.'_'.sprintf("%04s",mt_rand(1, 1000)).'_encode.txt';
7728
 
7729
+ $old_locale = kgvid_set_locale($encode_string[1]); //fixes UTF-8 encoding problems
7730
  $cmd = escapeshellcmd($encode_string[1]).$encode_string[2].escapeshellcmd($encode_string[3]);
7731
+
7732
  if ( !empty($cmd) ) { $cmd = $cmd.' > "'.$logfile.'" 2>&1 & echo $!'; }
 
7733
  else {
7734
  $arr = array ( "embed_display"=>"<span class='kgvid_warning'>".__("Error: Command 'escapeshellcmd' is disabled on your server.", 'video-embed-thumbnail-generator')."</span>" );
7735
  return $arr;
7736
  }
7737
  $process = new kgvid_Process($cmd);
7738
+ $restore_locale = setlocale(LC_CTYPE, $old_locale);
7739
 
7740
  sleep(1);
7741
 
7798
  $suffix = $video_formats[$options['sample_format']]['suffix'];
7799
 
7800
  $encode_string = $options['encode_string'];
7801
+
7802
+ $old_locale = kgvid_set_locale($encode_string[1]); //fixes UTF-8 encoding problems
7803
  $cmd = escapeshellcmd($encode_string[1]).$encode_string[2].escapeshellcmd($encode_string[3]);
7804
  exec ( $cmd.' 2>&1', $output );
7805
+ $restore_locale = setlocale(LC_CTYPE, $old_locale);
7806
  $arr['output'] = implode("\n", $output);
7807
 
7808
  if ( file_exists($uploads['path']."/sample-video-h264".$suffix) ) {
7813
 
7814
  if ( !empty($options['ffmpeg_watermark']['url']) ) {
7815
  if (!file_exists($uploads['path'].'/thumb_tmp')) { mkdir($uploads['path'].'/thumb_tmp'); }
7816
+
7817
+ $old_locale = kgvid_set_locale($uploads['path']."/sample-video-h264".$suffix); //fixes UTF-8 encoding problems
7818
  $cmd = escapeshellcmd($options['app_path'].'/'.$options['video_app'].' -y -i "'.$uploads['path']."/sample-video-h264".$suffix.'" -qscale 1 -vframes 1 -f mjpeg '.$uploads['path'].'/thumb_tmp/watermark_test.jpg');
 
7819
  exec ( $cmd );
7820
+ $restore_locale = setlocale(LC_CTYPE, $old_locale);
7821
+ kgvid_schedule_cleanup_generated_files('thumbs');
7822
  if ( file_exists($uploads['path'].'/thumb_tmp/watermark_test.jpg') ) {
7823
  $arr['watermark_preview'] = $uploads['url'].'/thumb_tmp/watermark_test.jpg';
7824
  }
8342
  }
8343
  if ( ($type == "manual" && $value['status'] == "queued")
8344
  || ($type == "queued" && $value['status'] == "Encoding Complete")
8345
+ || ($type == "scheduled" && $value['status'] == "queued")
8346
  ) {
8347
  $keep[$video_key] = true;
8348
  }
8431
 
8432
  if ( $options['moov'] == 'qt-faststart' && file_exists($filepath) ) {
8433
  $faststart_tmp_file = str_replace('.mp4', '-faststart.mp4', $filepath);
8434
+
8435
+ $old_locale = kgvid_set_locale($filepath); //fixes UTF-8 encoding problems
8436
  $cmd = escapeshellcmd($options['app_path']."/".$options['moov']." ".$filepath." ".$faststart_tmp_file)." 2>&1";
8437
  $output .= "\n".$cmd."\n";
8438
  exec($cmd, $qtfaststart_output, $returnvalue);
8439
+ $restore_locale = setlocale(LC_CTYPE, $old_locale);
8440
  $output .= implode("\n", $qtfaststart_output);
8441
  if ( file_exists($faststart_tmp_file) ) {
8442
  unlink($filepath);
8445
  }//if qt-faststart is selected
8446
 
8447
  if ( $options['moov'] == 'MP4Box' ) {
8448
+ $old_locale = kgvid_set_locale($filepath); //fixes UTF-8 encoding problems
8449
  $cmd = escapeshellcmd($options['app_path']."/".$options['moov']." -inter 500 ".$filepath)." 2>&1";
8450
  $output .= "\n".$cmd."\n";
8451
  exec($cmd, $mp4box_output, $returnvalue);
8452
+ $restore_locale = setlocale(LC_CTYPE, $old_locale);
8453
  $output .= implode("\n", $mp4box_output);
8454
  }//if MP4Box is selected
8455