Embedding uploaded web-ready video formats

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
User avatar
MarkDHamill
Registered User
Posts: 4886
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Embedding uploaded web-ready video formats

Post by MarkDHamill »

One of phpBB's little annoyances is that it won't play uploaded web-ready video formats like .mp4 natively in the browser. Instead, you need to have Quicktime installed and integrated into the browser, which lots of people won't bother to do and which adds latency as Quicktime boots up. I've had a new feature request in the bug tracker for years to add this but it's being ignored. Hopefully it will be addressed at some point.

For a client though having this was important, so I thought I'd share my hack. I don't think this can be done as an extension because it requires a new version of attachment.html. You have to overwrite some of the template. Unfortunately, template events won't do the trick. You could create a custom style and inherit your default style and do it that way, but that's pretty advanced. You also have to mess with phpBB's attachment groups.

Web-ready video formats are played natively in the browser without a browser add on or extension and use the HTML 5 <video> tag. The web-ready formats are MP4, WebM and OGG. As with most things, browsers are not entirely consistent and really old non-HTML 5 browsers will ignore the tag. This may be a deal killer if you have to support really old browsers. As a practical matter MP4 is the format that is typically uploaded.

Changes to attachment.html. Find:

Code: Select all

		<!-- IF _file.S_FLASH_FILE -->
after, add:

Code: Select all

			<video controls>
				<source src="{_file.U_VIEW_LINK}" type="video/mp4">
				<source src="{_file.U_VIEW_LINK}" type="video/ogg">
				<source src="{_file.U_VIEW_LINK}" type="video/webm">
				Your browser does not support the video tag.
			</video>
Following it, you can comment out the <object> tag code as follows:

Code: Select all

			<!--object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0" width="{_file.WIDTH}" height="{_file.HEIGHT}">
				<param name="movie" value="{_file.U_VIEW_LINK}" />
				<param name="play" value="true" />
				<param name="loop" value="true" />
				<param name="quality" value="high" />
				<param name="allowScriptAccess" value="never" />
				<param name="allowNetworking" value="internal" />
				<embed src="{_file.U_VIEW_LINK}" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width="{_file.WIDTH}" height="{_file.HEIGHT}" play="true" loop="true" quality="high" allowscriptaccess="never" allownetworking="internal"></embed>
			</object-->
Purge the cache afterward.

Style changes are also needed. The approach used depends on the style and how it is written. Usually you just append this code at the bottom of stylesheet.css. This will shrink the video proportionately to accommodate lots of devices, principally mobile:

Code: Select all

video {
    width: 100%;
    height: auto;
}
Unfortunately, some phpBB configuration is also needed. phpBB treats these video formats as Flash files, so you have to do make some changes. ACP > Posting > Attachments > Manage attachment extensions. By default, only .swf (Shockwave Flash) files are recognized as Flash files. Obviously Flash files are largely obsolete now. Here's what I did:
  • Changed swf extension to Unassigned
  • Added mp4 to Flash group
  • Added m4v to Flash group. This is actually a mp4 format that some phones like an iPhone will use by default, so it's important to allow it.
  • Added webm to Flash group
  • Added ogg to Flash group
You may also have to change the Flash group properties to allow the Flash group to be used in posts and optionally private messages. ACP > Posting > Attachments > Manage attachments groups. Click on the green wheel for Flash files to change the settings for the group if needed.

Of course, if you don't allow attachments at all, this won't work. ACP > Posting > Attachment settings. Make sure the first radio button is checked to allow post attachments, and possibly the second to allow them in private messages.

With quite a bit of testing, I found some mobile browsers problematic. In general where there are issues it is best to use Chrome. Most browsers are fine since HTML 5 is everywhere now. Safari seems the most problematic.

You may need to clear your browser's cache to see the changes.

I think this is it. Obviously, as phpBB gets updated or upgraded, the attachment.html template may get overwritten so these changes may need to be reapplied.

This is a bit hackish, so YMMV. If you have suggestions on how to do this better, please post them.
Need phpBB services or a phpBB consultant? I offer most phpBB services. Getting lost managing phpBB? Buy my book, Mastering phpBB Administration. Covers through phpBB 3.3.7. eBook and paper versions available.
User avatar
Lumpy Burgertushie
Registered User
Posts: 69224
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: Embedding uploaded web-ready video formats

Post by Lumpy Burgertushie »

actually you can just create a bbcode to do it.
see here for example of it working: https://phpbbusers.com/viewtopic.php?f=6&t=37
bbcode: [vids]{URL}[/vids]

html replacement:

Code: Select all

<video  width="100%" max-width="640px" controls>
  <source src="{URL}" type="video/mp4">
	<source src="{URL}" type="video/ogg">
	<source src="{URL}" type="video/webm">
</video>
  Your browser does not support the video tag.
</video>
Premium phpBB 3.3 Styles by PlanetStyles.net

I am pleased to announce that I have completed the first item on my bucket list. I have the bucket.
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Embedding uploaded web-ready video formats

Post by david63 »

MarkDHamill wrote: Thu Jan 03, 2019 12:42 am As with most things, browsers are not entirely consistent and really old non-HTML 5 browsers will ignore the tag. This may be a deal killer if you have to support really old browsers
That should not be a problem as phpBB does not support "old" browsers.
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
User avatar
MarkDHamill
Registered User
Posts: 4886
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: Embedding uploaded web-ready video formats

Post by MarkDHamill »

Lumpy Burgertushie wrote: Thu Jan 03, 2019 4:40 am actually you can just create a bbcode to do it.
see here for example of it working: https://phpbbusers.com/viewtopic.php?f=6&t=37
bbcode: [vids]{URL}[/vids]

html replacement:

Code: Select all

<video  width="100%" max-width="640px" controls>
  <source src="{URL}" type="video/mp4">
	<source src="{URL}" type="video/ogg">
	<source src="{URL}" type="video/webm">
</video>
  Your browser does not support the video tag.
</video>
I don't think this approach works for uploaded videos. It is nice to have a way for these to play natively if they exist on other servers and this approach should work fine for that.

My approach was to use the existing Flash attachments group. I suppose I could create a different kind of group and use that. This might let is work through an extension and using some template events.
Need phpBB services or a phpBB consultant? I offer most phpBB services. Getting lost managing phpBB? Buy my book, Mastering phpBB Administration. Covers through phpBB 3.3.7. eBook and paper versions available.
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 5885
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: Embedding uploaded web-ready video formats

Post by thecoalman »

There is pull request for audio here: https://github.com/phpbb/phpbb/pull/5446

MarkDHamill wrote: Thu Jan 03, 2019 12:42 am
Following it, you can comment out the <object> tag code as follows:
Quick tip, you can comment out code in templates using this.

Code: Select all

		<!-- IF 0  -->Constant Text - Removed because of Blah, blah, blah
		//Template code to comment out.
		<!-- ENDIF -->

This become quite useful for upgrades in the future because you know it was removed and why. This also prevents it from showing up in parsed page. "Constant text" is something I use for every modification I make whether it's templates, PHP or whatever.This allows you to easily identify your mods and find them.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
AmigoJack
Registered User
Posts: 6113
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Embedding uploaded web-ready video formats

Post by AmigoJack »

MarkDHamill wrote: Thu Jan 03, 2019 1:19 pmI don't think this approach works for uploaded videos
Because?
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
MarkDHamill
Registered User
Posts: 4886
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: Embedding uploaded web-ready video formats

Post by MarkDHamill »

AmigoJack wrote: Fri Jan 04, 2019 8:45 am
MarkDHamill wrote: Thu Jan 03, 2019 1:19 pmI don't think this approach works for uploaded videos
Because?
Because uploaded videos are uploaded on the attachments tab and the attachments logic is responsible for marking up the image for display, either as an attachment or inline.
Need phpBB services or a phpBB consultant? I offer most phpBB services. Getting lost managing phpBB? Buy my book, Mastering phpBB Administration. Covers through phpBB 3.3.7. eBook and paper versions available.
User avatar
AmigoJack
Registered User
Posts: 6113
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Embedding uploaded web-ready video formats

Post by AmigoJack »

MarkDHamill wrote: Fri Jan 04, 2019 1:49 pmuploaded videos are uploaded on the attachments tab
All uploads are attachments.
MarkDHamill wrote: Fri Jan 04, 2019 1:49 pmthe attachments logic is responsible for marking up the image for display, either as an attachment or inline
But that has nothing to do with non-pictures, such as videos. Is there actually a reconstructable example where you have issues with uploading video files or is this only your assumption?


Please don't full quote me again - it's obvious to whom you reply to.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
MarkDHamill
Registered User
Posts: 4886
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: Embedding uploaded web-ready video formats

Post by MarkDHamill »

A BBCode that embeds the <video> tag will work but you must supply a src and type attribute, as you showed in your reply.

phpBB stores all uploads in a munged file name in the files folder. To render embedded attached content, phpBB turns it into a URL like this:

./download/file.php?id=37&view=1

so effectively you need to know the attach_id in the phpbb_attachments table to set the src attribute.

Most uploaders don't know this process, don't care and won't know what an attach_id is.

If the video is not embedded, there is no BBCode to markup in the posting window. If it is embedded you get BBCode like:

Code: Select all

[attachment=0]pumpkin_orig_compressed.mp4[/attachment]
This leaves it to attachment.html to generate the HTML to render the video. The template only gives you four choices for embedding: thumbnail, image, file or flash. So since you want to embed a video, you must use flash. And if you use flash, it will embed with the <object> tag which will kick off Quicktime, which is probably not installed as a browser add in. So this template must be changed to use the <video> tag instead.

I hope this is clear.
Need phpBB services or a phpBB consultant? I offer most phpBB services. Getting lost managing phpBB? Buy my book, Mastering phpBB Administration. Covers through phpBB 3.3.7. eBook and paper versions available.
User avatar
MarkDHamill
Registered User
Posts: 4886
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: Embedding uploaded web-ready video formats

Post by MarkDHamill »

A correction. attachment.html will try to start Flash if you try to attach video content with a file extension in the phpBB Flash attachment group. By default, only .swf (Shockwave Flash) files are in this group. Flash is the only video format that phpBB attachments can handle that by default that can be embedded on a page. phpBB will expect the Flash plugin to be integrated into your browser and if not there the browser will usually ask you to install it.

Due to security issues, you don't see Flash much anymore serving multimedia content. The HTML 5 <video> tag was pretty much created to get around Flash's issues. Quicktime doesn't get started at all.

If you upload a .mpg video, it will not be displayed inline because by default it is in the downloadable files group, so you get a link to download the video. You actually have to add web ready formats like .mp4 to this group if you want them to be downloaded. What typically happens if you click on the download link, at least for .mpg files, is that after downloading the video, Quicktime will start up on Apple devices and MediaPlayer on Windows devices. It will be played outside of the browser. You have to wait for the video to be downloaded and the video player to start. This latency deters people from watching the video.

So basically phpBB's approach with attached video files is to force you to download videos if it's not a Flash formatted video.

My approach is to put these formats in the Flash group, take Flash out of the Flash group and change the logic in attachment.html so it uses the <video> tag.
Need phpBB services or a phpBB consultant? I offer most phpBB services. Getting lost managing phpBB? Buy my book, Mastering phpBB Administration. Covers through phpBB 3.3.7. eBook and paper versions available.
User avatar
AmigoJack
Registered User
Posts: 6113
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Embedding uploaded web-ready video formats

Post by AmigoJack »

Ah, now I understand what's the problem and why you did all that. I have nearly no experience with attachments and wasn't aware of that different groups render the attachments in a different manner to such an extent. Yes, now it's clear.

Only thing left to say is: the video element is by default open to every format - that's also the reason why you can provide multiple sources, so the internet browser can choose the one it supports. After all the internet browser should be user friendly enough to at least offer to download any of the source, so a user is able to use a software of his choice for playback. That being said I would move all video/container formats from the "download" group into "video".
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
MarkDHamill
Registered User
Posts: 4886
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: Embedding uploaded web-ready video formats

Post by MarkDHamill »

Thanks for the additional information. The W3C specification supports only three "web ready" video format. There are a number of variants of MP4, like M4V that seem to work. And some browsers don't seem to fully adhere to the specification.
Need phpBB services or a phpBB consultant? I offer most phpBB services. Getting lost managing phpBB? Buy my book, Mastering phpBB Administration. Covers through phpBB 3.3.7. eBook and paper versions available.
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 5885
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: Embedding uploaded web-ready video formats

Post by thecoalman »

The method outlined in the OP will not work across all browsers because phpBB is not serving the file with the correct mime type.

See this for reference and a solution: viewtopic.php?f=461&t=2383226
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
Post Reply

Return to “phpBB Custom Coding”