Warning: Undefined variable $UploadMaxSize in /home/kongdmdu/pmichaud/pmwiki/local/PITS.php on line 8

Warning: Undefined variable $UploadMaxSize in /home/kongdmdu/pmichaud/pmwiki/local/PITS.php on line 9

Warning: Undefined variable $UploadMaxSize in /home/kongdmdu/pmichaud/pmwiki/local/PITS.php on line 10

Warning: Undefined variable $UploadMaxSize in /home/kongdmdu/pmichaud/pmwiki/local/PITS.php on line 11
01569: Posters for bare URL videos and audios - PITS - PmWiki

01569: Posters for bare URL videos and audios

Summary: Posters for bare URL videos and audios
Created: 2026-09-16 06:52
Status: Open
Category: Cookbook
From: Petko
Assigned:
Priority: 1
Version: 2.7.5
OS:

Description: From gnuzoo, about PmWiki.Media:

I think the code near the bottom of this page fixes this for video. --gnuzoo
How could I do this for audio?
See AudioTest
--gnuzoo


> For locally uploaded files, PmWiki will also search for related pictures 
> and subtitles/captions/chapters, that is the same basename and a different 
> extension, and will include them in the player.
>    Poster (cover) pictures: webp, jpg, jpeg, png 

Poster appears to only work with the "Attach:" and not with
the direct URL. Even when the poster fails the video still works.

My poster filename is Slaughterbots.jpg in the same diretory.

Poster works:

    Attach:Slaughterbots.mp4#x320;class=videoframegraysilver

Poster does not work:

    (:UPL:http://localhost/z/uploads/:)
    {$:UPL}Slaughterbots.mp4#x320;class=videoframegraysilver

--gnuzoo

Indeed, it was already documented earlier but I also clarified this sentence. --Petko

You documented a poster works for media that use the "Attach: link" but did not
mention it does not work for media that use "bare remote URL, without brackets".

> Embedding media players is similar to embedding images in wiki pages, with the
> "Attach: link" or the "bare remote URL, without brackets".

I would like to see the poster implemented/adjusted for media that use "bare remote URL, without brackets" too.

--gnuzoo

Doc updated. --Petko

> This does not apply to URL, Path:, or [[InterMap]], only to %pmhlt%[@Attach: links.@]

Why does this not apply? Cannot the PmWiki program check to see if the file is a mp4 (video)
and if so use the same path as the file to see if there is a filename matching jpg (poster)?
Is it too much to program, or just not programmed yet? Do you have a Media todo list?

--gnuzoo

Attach: links are a core PmWiki function that maps a filesystem path to a URL. It takes a few milliseconds to scan the whole filesystem directory for related files (different media formats, different poster formats, different subtitles/captions/chapters, different languages). The PHP glob() and even file_exists() functions do not work over http: or https:, including InterMap. For your case, there are 2 workarounds: (1) replace http://localhost/z/uploads/ with Attach: as documented, who would have thunk, crazy right?, and (2) ask your favorite LLM how to use ffmpeg to place your poster as the first frame of your video, and reupload that file, no need for a separate poster image. The browser will happily show that frame when the page loads. --Petko

That all makes sense. How about adding a poster to the "hash fragment".

{$:UPL}Slaughterbots.mp4#x320;class=videoframegraysilver;poster="{$:UPL}Slaughterbots.jpg"

--gnuzoo

Such a feature may be better left to be implemented by a recipe, this way we could see how popular it is before increasing the complexity of the core and taking from my limited spare time. --Petko

http and https do allow you to obtain the filename. Strip off the extension and search
in the $UploadDir for a poster match. Perhaps search other 'known' Pmwiki locations.
That would work. Perhaps adding a line in config.php - $PosterDir = "uploads/; videos/;".

--gnuzoo

Since you moved this page from Media-Talk to
PITS, does that mean you plan to implement this?

--gnuzoo


The above code works GREAT for adding a poster to bare url videos that do not have a space in the filename like this:

    http://localhost/z/uploads/Slaughterbots.mp4#x320;class=videoframegraysilver

It does not work for adding a poster to a bare url video which has spaces in the filename.
This will not play the video or poster which is normal:

    {$:UPL}Slaughterbots - if human kill.mp4#x320;class=videoframegraysilver

This plays the video but will not add a poster:

    {$:UPL}[=Slaughterbots - if human kill=].mp4#x320;class=videoframegraysilver

Can someone please help me to fix this so that a filename with spaces can add a poster?

    Video  'Slaughterbots - if human kill.mp4'
    Poster 'Slaughterbots - if human kill.jpg'

--gnuzoo

To restore markup escaped with [=...=], you may call MarkupRestore($path) before or inside the call to parse_url(). --Petko

> MarkupRestore($path)
WOW How can you just know all this stuff!

🦸‍♂️ Super Petko to the rescue again!

I also find that I also need to mod the regex to allow spaces

    && preg_match('/^[A-Za-z0-9._-]+(?:[ A-Za-z0-9._-]*[A-Za-z0-9._-])?$/', $videoBase)) {

--gnuzoo


It would be nice to allow posters/subtitles/other files to search for
to be located in other directories too. Maybe via something like $PmMediaDirs


Here is a Version pmwiki-2.7.5 solution that will take a bare URL video and look
for a matching poster filename in the uploads directory. This does not work for audio.

In PmWiki/media.php comment out 3 line and paste the rest of this code in:

  #elseif ($M['EnableRemoteEmbed']) {
  #  $url = LinkIMap($pagename,$imap,$path,'','','$LinkUrl');
  #}
  elseif ($M['EnableRemoteEmbed']) {
    global $UploadDir, $UploadUrlFmt;

    $url = LinkIMap($pagename, $imap, $path, '', '', '$LinkUrl');
    if ($url && $tag === 'video') {
      $remotePath = parse_url(MarkupRestore($path), PHP_URL_PATH);
      $remoteName = rawurldecode(basename($remotePath ?: ''));

      $videoBase = preg_replace(
        '/\.(?:' . $M['VideoExts'] . ')$/i',
        '',
        $remoteName
      );
      if ($videoBase !== ''
          && preg_match('/^[A-Za-z0-9._-]+(?:[ A-Za-z0-9._-]*[A-Za-z0-9._-])?$/', $videoBase)) {
          #&& preg_match('/^[A-Za-z0-9._-]+$/', $videoBase)) {

        foreach (explode('|', $M['PosterExts']) as $posterExt) {
          $posterExt = trim($posterExt);
          $posterName = "$videoBase.$posterExt";
          $posterPath =
            rtrim($UploadDir, '/\\') . DIRECTORY_SEPARATOR . $posterName;

          if (is_file($posterPath)) {
            $posterUrl = FmtPageName($UploadUrlFmt, $pagename);
            $posterUrl = rtrim($posterUrl, '/') . '/'
              . rawurlencode($posterName);

            $attrs['poster'] = $posterUrl;
            break;
          }
        }
      }
    }
  }

--gnuzoo