Piwigo / piwigo-videojs

Videojs port for piwigo. Play your videos on your web gallery!
http://piwigo.org/ext/extension_view.php?eid=610
GNU General Public License v3.0
67 stars 46 forks source link

Move poster/thumbnail creation of video files to piwigo cache directory .../_data/i/galleries/... #97

Open jan356 opened 8 years ago

jan356 commented 8 years ago

When creating a poster (i.e. a thumbnail) for a video file, this is done in the directory [original location of the video]/pwg_representative

However, on my system the directory with (original) image and video files is not writable by the webserver (which is running as wwwrun:www), so when this plugin creates a video poster, I get the warning "Warning: mkdir(): Permission denied in /srv/www/htdocs/piwigo/plugins/piwigo-videojs/include/function_sync2.php on line 132".

Can an option be made to create the video poster in the piwigo cache directory .../_data/i/galleries/..., which is writable by the webserver? Thanks.

Example: original file: /data-hdd/images/2016/dirname/videoname.mp4 now, the poster is created in /data-hdd/images/2016/dirname/pwg_representative/videoname.jpg however the directory /data-hdd/images/2016/dirname/ is not writable by the webserver, so an error is generated.

my proposal is to create the poster in /data-hdd/piwigo/_data/i/galleries/2016/dirname/pwg_representative/videoname.jpg which is writable by the webserver.

Xyaren commented 8 years ago

I need this too. My picture folder is used by an DLNA Server too. The created pwg_representative folder is showed on my TV now ...

Idefix1977 commented 6 years ago

me too, pls, pls, pls!

xbgmsharp commented 6 years ago

This is the default behavoir of PWG. I believe the thumbnails should be created in the local pwg_representative directory. https://github.com/xbgmsharp/piwigo-videojs/blob/master/include/function_sync2.php#L126

How do you detect to write to a specific directory. is it a virtual album?

jan356 commented 6 years ago

I don not fully understand your question. Let's try to answer it.

No, I don't use virtual albums in piwigo.

The original file is on read only storage, If I take a jpg file as example /data-hdd/images/2016/dirname/image1.jpg. When I browse the album containing that image, previews will be saved in /data-hdd/piwigo/_data/i/galleries/2016/dirname/image1-xx.jpg, .../image1-sq.jpg etc.

However, when I use your plugin on file /data-hdd/images/2016/dirname/videoname.mp4, the poster is created in /data-hdd/images/2016/dirname/pwg_representative/videoname.jpg, which fails because it is on read only storage.

My proposal is to create the poster in the temporary storage (writable) directory /data-hdd/piwigo/_data/i/galleries/2016/dirname/pwg_representative/videoname.jpg which is writable by the webserver and where also other previews are stored.

Sometimes, when I switch to a different piwigo than the standard one, new previews are also generated in /data-hdd/piwigo/_data/i/galleries/2016. So it looks like that is "standard functionality".

How it relates to your source I don't know (sorry).

Hope this helps. Thanks again.

xbgmsharp commented 6 years ago

In include/function_sync2.php on line 147, can you replace:

https://github.com/xbgmsharp/piwigo-videojs/blob/master/include/function_sync2.php#L147 and https://github.com/xbgmsharp/piwigo-videojs/blob/master/include/function_sync2.php#L238

$output_dir = dirname($row['path']) . '/pwg_representative/';

by:

$output_dir = PWG_DERIVATIVE_DIR . dirname($row['path']) . '/pwg_representative/';

If it is fine for you i will commit the change.

xbgmsharp commented 6 years ago

So i try and even so we can write in the derivative directory (using the modification in the previous post), PWG is looking for the current videos folder as mention in the documentation. https://piwigo.org/doc/doku.php?id=user_documentation:learn:add_picture

screen shot 2018-08-16 at 2 56 40 pm

and you can see it in the code: https://github.com/Piwigo/Piwigo/blob/master/admin/include/functions_upload.inc.php#L551

as a result not sure it is feasible.

jan356 commented 6 years ago

Thanks. I changed include/function_sync2.php as you wrote and then the preview jpg-image is written in the desired place. However, it does not appear in piwigo, as your next comment suggests.

Probably piwigo also needs some modifications? Which means piwigo should search in two places for the preview: (1) where it searchs now to prevent other installations depending on this to break, and (2) in $output_dir = PWG_DERIVATIVE_DIR . dirname($row['path']) . '/pwg_representative/';

Do you think that is feasible?

jflassche commented 5 years ago

For what it's worth, a (very) crude hack. It works but you'll have to resync thumbs using video_js plugin each time you've synched the gallery using piwigo.

In .../plugins/piwigo-js/include/function_sync2.php. Replace $output_dir = dirname($row['path']) . '/pwg_representative/'; with $output_dir = PWG_DERIVATIVE_DIR . dirname($row['path']) . '/';

In .../include/derivate.inc.php find the function build. Replace if ($url_style == 2) { ... } with

if ($url_style == 2)
    {
        if (strpos($loc, "pwg_representative") != false)
        {
                $replace = array(
                        "-xs" => "",
                        "-2s" => "",
                        "-th" => "",
                        "-cu_e250" => "",
                        "pwg_representative" => ""
                );
                $rel_url = "_data/i/" . strtr($loc, $replace);
        }
        else
        {
                $rel_url = 'i';
                if ($conf['php_extension_in_urls']) $rel_url .= '.php';
                if ($conf['question_mark_in_urls']) $rel_url .= '?';
                $rel_url .= '/'.$loc;
        }

    }
    else
    {
      $rel_url = $rel_path;
    }
k4vej commented 5 years ago

Thumbnails were being generated but Piwigo galleries were showing them as missing, they were looking for files with a suffix of: -cu_s9999x200

So change the line 150: https://github.com/xbgmsharp/piwigo-videojs/blob/master/include/function_sync2.php#L150 $out = $output_dir.$file_wo_ext['filename'].'-cu_s9999x200'.'.'.$sync_options['output'];

willemjaap commented 4 years ago

I've been trying to solve this in a structural way, but did not succeed. The directoryname "pwg_representative" is hardcoded in a number of files. As a first step to solve at least the visibility of the pwg_representative directory I've changed this in ".pwg_representative" throughout the code. This seems to work. A better solution would be to make it a $conf variable. Problem is that after each update and for each plugin you install you have to do this again.

Catfriend1 commented 4 years ago

Please make a conf variable for this

corsac-s commented 2 years ago

Hi, is this still on the radar? I've just updated to Piwigo 13 and I seem to still have the issue that thumbnails won't be generated because my photos folder is readonly for the web server.

rajagidh commented 1 year ago

Hi - could someone please help with my issue: https://piwigo.org/forum/viewtopic.php?id=32431 . In summary my Piwigo set up cannot seem to get the thumbnails for video albums. It's very frustrating. Any help will be appreciated!

RenaeMacLeod commented 1 year ago

Same here WRT read only access to pictures. I tried generating the files with the same name and putting them in 'pwg_representative' sub directory, then using the standard Piwigo sync to add them. Also tried JPG and PNG extensions.

Catfriend1 commented 5 months ago

Same here WRT read only access to pictures. It's related to the zfs mounted fs.

Catfriend1 commented 5 months ago

I've found a workaround for readOnly album folder structures from www-data user's perspective. Running this daily cron script here to create the "pwg_representative" subfolders for every album which contains *.mp4 files and allowing write access ONLY to those directories.

In /etc/cron.daily/piwigo-set-acl

#!/bin/bash
#####################
# FUNCTIONS START   #
#####################
function create_pwg_representative() {
    local dir="$1"
    #
    for subdir in "${dir}"/*; do
        #
        # Skip files.
        if [ ! -d "${subdir}" ]; then
            continue
        fi
        #
        # Subfolder already exists?
        if (echo "${subdir}" | grep -q "pwg_representative$" ); then
            continue
        fi
        #
        # Check if dir contains at least one .mp4 file.
        if ls "${subdir}"/*.mp4 &>/dev/null; then
            if [ ! -d "${subdir}/pwg_representative" ]; then
                mkdir "${subdir}/pwg_representative"
                echo "[INFO] Created: ${subdir}/pwg_representative"
            fi
            #
            # This compensates the change from the above setfacl command.
            setfacl -Rm u:www-data:rwX,d:u:www-data:rwX "${subdir}/pwg_representative/"
        fi
        #
        create_pwg_representative "${subdir}"
    done
}
#####################
# FUNCTIONS END     #
#####################
#
#
create_pwg_representative "/datavol/piwigo-pictures"
corsac-s commented 5 months ago

Thanks for the script, unfortunately it won't really help for read-only storage (Piwigo won't be able to generate the representatives). It'd be best to move the representatives elsewhere, for example in the _data folder.

mfauvain commented 2 months ago

Hello, any luck with this? Generating thumbnails/posters in the picture directory is clearly not desirable. Following comments above, I manage to get the plugin to generate posters in the _data/i directory, but it seems piwigo is not able to see them.