Tagged: , , ,

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1458329

    Hi,
    we have a webpage with 2 self-hosted mp4 videos on it. Each time the page is requested I believe Enfold issues a HEAD request for the .webm and .ogv alternatives. We do not have .webm and .ogv alternatives for the mp4 videos.`
    I see this in the Apache log for every request:

    servers.own.ip - - [24/Jun/2024:15:37:18 +0100] "HEAD /wp-content/uploads/2024/01/Video-4.jpg HTTP/1.1" 404 6076 "-" "-"
    servers.own.ip - - [24/Jun/2024:15:37:18 +0100] "HEAD /wp-content/uploads/2024/01/Video-4.webm HTTP/1.1" 404 6076 "-" "-"
    servers.own.ip - - [24/Jun/2024:15:37:18 +0100] "HEAD /wp-content/uploads/2024/01/Video-4.ogv HTTP/1.1" 404 6108 "-" "-"
    86.x.x.x - - [24/Jun/2024:15:37:15 +0100] "GET /wp-content/uploads/2024/01/Video.mp4 HTTP/1.1" 206 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
    servers.own.ip - - [24/Jun/2024:15:37:18 +0100] "HEAD /wp-content/uploads/2024/01/Video.jpg HTTP/1.1" 404 6108 "-" "-"
    servers.own.ip - - [24/Jun/2024:15:37:18 +0100] "HEAD /wp-content/uploads/2024/01/Video.webm HTTP/1.1" 404 6092 "-" "-"
    servers.own.ip - - [24/Jun/2024:15:37:19 +0100] "HEAD /wp-content/uploads/2024/01/Video.ogv HTTP/1.1" 404 6076 "-" "-"

    So for every valid request Apache has to deal with 4x requests that will do nothing but hurt performance. At times of peak load doing 4x more work than needed is an overhead we can do without. I see a discussion about filtering this here:

    which might be part of a solution but it doesn’t seem that filter has been implemented.

    How can I switch off the extra requests for fallback formats that don’t exist please?
    Thanks.

    #1460293

    Hey akriga,
    Thanks for your patience, I believe that some browsers automatically check for .webm and .ogv alternatives, and this is not added by the theme, I don’t see this error when I check my demo site. You can try uploading the .webm and .ogv alternatives via FTP to your site to satisfy the browser, or you can link to your page so we can see the situation and try to reproduce. I kind of recall a situation like this in the past and as I recall only one browser did this, but I don’t remember which one.

    Best regards,
    Mike

    #1460791

    Hi Mike,
    many thanks for your response, a couple of points:

    1/
    If it were the user’s own browser making these requests then the IP address of each request would not be that of the server. Instead it would be the user’s own IP address. However, the additional HEAD requests we get are coming from the server’s own IP address.

    2/
    Code in enfold/framework/php/function-set-avia-frontend.php loops through an array of types where the types default is:
    function avia_html5_video_embed( $video, $image = '', $types = array( 'webm' => 'type="video/webm"', 'mp4' => 'type="video/mp4"', 'ogv' => 'type="video/ogg"' ),

    If the filter mentioned in the post I linked to was implemented I think we could solve this.
    Best regards,
    akriga

    #1461103

    Hi,
    When I check your page I’m not finding any video .webm and .ogv requests, only mp4, please see the details below.

    Best regards,
    Mike

    #1461186

    Hi Mike,
    thanks for your reply. I agree, yet they they are in the server logs – see my original post. This reinforces my point that these requests are not coming from the browser as it tries to load alternatives.

    #1461406

    Hi,

    Thank you for the update.

    When we add the Video element in the builder, it only render one source for the HTML video element, so by default the server should not trigger requests for other formats. We are not sure how your server handles video requests, but adding fallback video formats in this case will not actually improve performance significantly because the server will still trigger the same HEAD requests for other formats. The only upside is that it will not return a 404 error and will be able to actually fetch the videos.

    This is the html of the video element with an mp4 video, and as you can see, it only has a single source:

    <video class="avia_video av-mediajs-loaded" preload="auto" id="player_3137_736197941_270250769_html5" src="world-video.mp4">
        <source src="world-video.mp4" type="video/mp4">
    </video>
    

    Do you have access to your apache server configuration or the .htaccess file? This might not help at all, but you can set it to prioritize mp4 videos and ignore the other formats. Please edit the .htaccess file and add this code rule.

    # Only serve MP4 files for video requests
    <FilesMatch "\.(mp4)$">
        ForceType application/octet-stream
        Header set Content-Disposition attachment
    </FilesMatch>
    
    # Disable serving other video formats
    <FilesMatch "\.(webm|ogg|mkv|avi)$">
        Order allow,deny
        Deny from all
    </FilesMatch>
    

    Best regards,
    Ismael

    #1461437

    Hi Ismael,
    many thanks for your response.
    I agree, “the server should not should not trigger requests for other formats”. We get 6 requests per second for these other formats from the server and that is the mystery.
    I already have something in htaccess to handle these requests once they’re triggered, but thank you anyway. I would rather they not be triggered in the first place.
    If you have any ideas of how to trace the source of these requests please let me know otherwise we can close this ticket.

    best,
    Akriga

    #1461536

    Hi,
    Thank you for your patience, I have tried to reproduce this error with a self-hosted mp4 on my test site and I checked my Apache log, but unfortunately I only see the .mp4 video file type and the .jpg thumbnail for the .mp4
    I tried to create a function to add to your child theme functions.php to change this anyways, I can’t confirm that it will work for you, but adding it didn’t brake my video element, so please give this a try and see if it helps.

    if (!function_exists('custom_avia_html5_video_embed')) {
        function custom_avia_html5_video_embed( $video, $image = '', $types = array( 'mp4' => 'type="video/mp4"' ), $attributes = array( 'autoplay' => 0, 'loop' => 1, 'preload' => '', 'muted' => '', 'controls' => ''  ) ) {
            $html5_files = array();
            $path = $video;
    
            if( ! empty( $video ) && is_array( $video ) )
            {
                $html5_files = array_filter($video, function($ext) {
                    return $ext === 'mp4';
                }, ARRAY_FILTER_USE_KEY);
                $path = reset( $html5_files );
            }
    
            $path_split = array();
            preg_match( "!^(.+?)(?:\\.([^.]+))?$!", $path, $path_split );
    
            $output = '';
            if( isset( $path_split[1] ) )
            {
                if( ! $image && avia_is_200( $path_split[1] . '.jpg' ) )
                {
                    $image = 'poster="' . $path_split[1] . '.jpg"'; // poster image isn't accepted by the player currently, waiting for bugfix
                }
                else if( $image )
                {
                    $image = 'poster="' . $image . '"';
                }
    
                $autoplay = $attributes['autoplay'] == 1 ? 'autoplay' : '';
    
                if( ! empty( $autoplay ) )
                {
                    $autoplay = apply_filters( 'avf_html5_autoplay_mobile', "{$autoplay} playsinline", $video, $attributes );
                }
    
                $loop = $attributes['loop'] == 1 ? 'loop' : '';
                $muted = $attributes['muted'] == 1 ? 'muted' : '';
                $controls = $attributes['controls'] == 1 ? 'controls' : '';
    
                if( ! empty( $attributes['preload'] ) )
                {
                    $metadata = 'preload="' . $attributes['preload'] . '"';
                }
                else
                {
                    $metadata = $attributes['loop'] == 1 ? 'preload="metadata"' : 'preload="auto"';
                }
    
                $uid = 'player_' . get_the_ID() . '_' . mt_rand() . '_' . mt_rand();
    
                $output .= "<video class='avia_video' {$image} {$autoplay} {$loop} {$metadata} {$muted} {$controls} id='{$uid}'>";
    
                if( empty( $html5_files ) )
                {
                    if( $path_split[2] == 'mp4' || avia_is_200( $path_split[1] . '.mp4' ) )
                    {
                        $output .= '<source src="' . $path_split[1] . '.mp4" type="video/mp4" />';
                    }
                }
                else
                {
                    foreach( $html5_files as $ext => $source )
                    {
                        $html_type = ! empty( $types[ $ext ] ) ? $types[ $ext ] : '';
                        $output .= "<source src='{$source}' {$html_type} />";
                    }
                }
    
                $output .= '</video>';
            }
    
            return $output;
        }
    }
    
    // Remove the original function and replace it with the custom function
    remove_action('avia_html5_video_embed', 'avia_html5_video_embed');
    add_action('avia_html5_video_embed', 'custom_avia_html5_video_embed');
    

    If this doesn’t help try to modify the function-set-avia-frontend.php starting at line 960 to match the above and see if manually changing it helps.
    If it does then great, but the the function-set-avia-frontend.php file can not be overwritten in a child theme so after each update you will need to modify, I’m hoping the above will work for you in your child theme functions.php file.

    Best regards,
    Mike

    #1461615

    Hi Mike,
    thanks so much for spending time on this, I really appreciate it.
    I added the code to our functions.php but determined that it was never called (I added an HTML comment after the source tag).
    Instead the version from the parent theme runs but I’m now pretty sure this is a red-herring for 2 reasons:

    1. If I modify the return from avia_html5_video_embed to return an empty string I still get HEAD requests in the log.
    2. The HEAD requests come in at 45 seconds past the minute which suggest something like wp-cron (we have no Unix cron entry for this).
    This may be beyond scope so feel free to close this ticket if so.

    Thanks again,
    akriga

    #1461643

    Hi,
    Thanks for the feedback, I’m glad you were able to investigate this further, but unfortunately I don’t know what else we can do to help with this, as we can’t reproduce this and from your explanation it sounds like a red-herring, as you say.
    We will go ahead and close this as you pointed out, but feel free to open a new thread if you find new information that will help us reproduce this.
    Thank you for your understanding and using Enfold.

    Best regards,
    Mike

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘HEAD request for .webm and .ogv fallbacks’ is closed to new replies.