Skip to content

Commit

Permalink
#518 Added some options but not completed
Browse files Browse the repository at this point in the history
  • Loading branch information
kylegilman committed Feb 15, 2023
1 parent f8be363 commit d116ef3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 22 deletions.
14 changes: 11 additions & 3 deletions src/admin/videopack-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ function kgvid_default_options_fn() {
'auto_thumb' => false,
'auto_thumb_number' => 1,
'auto_thumb_position' => 50,
'thumb_significant' => 'on',
'right_click' => 'on',
'resize' => 'on',
'auto_res' => 'automatic',
Expand Down Expand Up @@ -1293,7 +1294,7 @@ function kgvid_video_embed_options_init() {
add_settings_field( 'video_app', esc_html__( 'Application for thumbnails & encoding:', 'video-embed-thumbnail-generator' ), 'kgvid_video_app_callback', 'video_embed_thumbnail_generator_settings', 'kgvid_video_embed_encode_settings', array( 'label_for' => 'video_app' ) );
}

add_settings_field( 'browser_thumbnails', esc_html__( 'Enable in-browser thumbnails:', 'video-embed-thumbnail-generator' ), 'kgvid_browser_thumbnails_callback', 'video_embed_thumbnail_generator_settings', 'kgvid_video_embed_encode_settings', array( 'label_for' => 'browser_thumbnails' ) );
add_settings_field( 'browser_thumbnails', esc_html__( 'Thumbnail options:', 'video-embed-thumbnail-generator' ), 'kgvid_thumbnail_options_callback', 'video_embed_thumbnail_generator_settings', 'kgvid_video_embed_encode_settings', array( 'label_for' => 'browser_thumbnails' ) );
add_settings_field( 'encode_formats', esc_html__( 'Default video encode formats:', 'video-embed-thumbnail-generator' ), 'kgvid_encode_formats_callback', 'video_embed_thumbnail_generator_settings', 'kgvid_video_embed_encode_settings' );
add_settings_field( 'automatic', esc_html__( 'Do automatically on upload:', 'video-embed-thumbnail-generator' ), 'kgvid_automatic_callback', 'video_embed_thumbnail_generator_settings', 'kgvid_video_embed_encode_settings', array( 'label_for' => 'auto_encode' ) );
add_settings_field( 'automatic_encoded', esc_html__( 'Do automatically on completed encoding:', 'video-embed-thumbnail-generator' ), 'kgvid_automatic_completed_callback', 'video_embed_thumbnail_generator_settings', 'kgvid_video_embed_encode_settings', array( 'label_for' => 'auto_publish_post' ) );
Expand Down Expand Up @@ -1780,11 +1781,13 @@ function kgvid_video_app_callback() {
echo "\n\t";
}

function kgvid_browser_thumbnails_callback() {
function kgvid_thumbnail_options_callback() {
$options = kgvid_get_options();
echo "<div class='kgvid_video_app_required'>";
/* translators: %s is the name of the video encoding application (usually FFMPEG). */
echo '<input' . checked( $options['browser_thumbnails'], 'on', false ) . " id='browser_thumbnails' name='kgvid_video_embed_options[browser_thumbnails]' type='checkbox'" . disabled( empty( $options['ffmpeg_thumb_watermark']['url'] ), false, false ) . "/> <label for='browser_thumbnails'>" . sprintf( esc_html__( 'When possible, use the browser\'s built-in video capabilities to make thumbnails instead of %s.', 'video-embed-thumbnail-generator' ), "<strong class='video_app_name'>" . esc_attr( strtoupper( $options['video_app'] ) ) . '</strong>' ) . "</label>\n\t";
echo '<input' . checked( $options['browser_thumbnails'], 'on', false ) . " id='browser_thumbnails' name='kgvid_video_embed_options[browser_thumbnails]' type='checkbox'" . disabled( empty( $options['ffmpeg_thumb_watermark']['url'] ), false, false ) . "/> <label for='browser_thumbnails'>" . sprintf( esc_html__( 'When possible, use the browser\'s built-in video capabilities to make thumbnails instead of %s.', 'video-embed-thumbnail-generator' ), "<strong class='video_app_name'>" . esc_attr( strtoupper( $options['video_app'] ) ) . '</strong>' ) . "</label><br />\n\t";
/* translators: %s is the name of the video encoding application (usually FFMPEG). */
echo '<input' . checked( $options['thumb_significant'], 'on', false ) . " id='thumb_significant' name='kgvid_video_embed_options[thumb_significant]' type='checkbox'" . disabled( empty( $options['browser_thumbnails'] ), false, false ) . "/> <label for='browser_thumbnails'>" . sprintf( esc_html__( 'Use %s filters to find significant thumbnail frames.', 'video-embed-thumbnail-generator' ), "<strong class='video_app_name'>" . esc_attr( strtoupper( $options['video_app'] ) ) . '</strong>' ) . "</label>\n\t";
echo '</div>';
}

Expand Down Expand Up @@ -2661,6 +2664,11 @@ function kgvid_init_plugin() {
}
}

if ( version_compare( $options['version'], '4.8.7', '<' ) ) {
$options['version'] = '4.8.7';
$options['thumb_significant'] = false;
}

if ( $options['version'] != $default_options['version'] ) {
$options['version'] = $default_options['version'];
}
Expand Down
72 changes: 53 additions & 19 deletions src/admin/videopack-ffmpeg.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function kgvid_save_encode_queue( $video_encode_queue ) {
}
}

function kgvid_process_thumb( $input, $output, $ffmpeg_path = false, $seek = '0', $rotate_array = array(), $watermark_strings = array() ) {
function kgvid_process_thumb( $input, $output, $ffmpeg_path = false, $seek = '0', $rotate_array = array(), $watermark_strings = array(), $total = 1 ) {

$options = kgvid_get_options();
if ( empty( $options ) ) {
Expand All @@ -47,31 +47,64 @@ function kgvid_process_thumb( $input, $output, $ffmpeg_path = false, $seek = '0'
$ffmpeg_path = $ffmpeg_path . '/' . $options['video_app'];
}

$before_thumb_options = array(
$ffmpeg_path,
'-y',
'-ss',
$seek,
'-i',
$input,
);
if ( $options['thumb_significant'] === false ) {
$before_thumb_options = array(
$ffmpeg_path,
'-y',
'-ss',
$seek,
'-i',
$input,
);

if ( ! empty( $watermark_strings['input'] ) ) {
$before_thumb_options[] = '-i';
$before_thumb_options[] = $watermark_strings['input'];
}
$thumb_options = array(
'-vf',
'scale=iw*sar:ih',
'-qscale',
'1',
'-vframes',
'1',
);

$thumb_options = array(
'-vf',
'scale=iw*sar:ih',
} else {
$before_thumb_options = array(
$ffmpeg_path,
'-y',
'-i',
$input,
);
if ( $total > 1 ) {
$thumb_options = array(
'-vf',
'select=gt(scene\,0.4),scale=iw*sar:ih',
'-vframes',
$total,
'-vsync',
'vfr',
);
} else {
$thumb_options = array(
'-vf',
'thumbnail,scale=iw*sar:ih',
'-vframes',
'1',
);
}
}
$all_thumb_options = array(
'-qscale',
'1',
'-vframes',
'1',
'-f',
'mjpeg',
);

$thumb_options = array_merge( $thumb_options, $all_thumb_options );

if ( ! empty( $watermark_strings['input'] ) ) {
$before_thumb_options[] = '-i';
$before_thumb_options[] = $watermark_strings['input'];
}

if ( ! empty( $rotate_array ) ) {
$thumb_options = array_merge( $thumb_options, $rotate_array );
}
Expand Down Expand Up @@ -2174,7 +2207,8 @@ function kgvid_make_thumbs( $post_id, $movieurl, $numberofthumbs, $i, $iincrease
$movieoffset = '0';
}

$thumbnailfilename[ $i ] = str_replace( ' ', '_', $sanitized_url['basename'] . '_thumb' . $i . '.jpg' );
//$thumbnailfilename[ $i ] = str_replace( ' ', '_', $sanitized_url['basename'] . '_thumb' . $i . '.jpg' );
$thumbnailfilename[ $i ] = str_replace( ' ', '_', $sanitized_url['basename'] . '_thumb%d.jpg' );
$thumbnailfilename[ $i ] = $jpgpath . $thumbnailfilename[ $i ];

if ( ! empty( $options['htaccess_login'] ) && strpos( $moviefilepath, 'http://' ) === 0 ) {
Expand Down

0 comments on commit d116ef3

Please sign in to comment.