latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

CloudFront and RTMP Streaming JW

Home Forums Community Forum CloudFront and RTMP Streaming JW

This topic contains 35 replies, has 5 voices. Last updated by  ryan 4 years, 10 months ago.

Topic Author Topic
Posted: Sunday Feb 12th, 2012 at 9:30 pm #4914

Hey guys, I need help trying to understand on how to trigger the JW player to stream content from Cloudfront. My S2/AWS configs are working. I embed this example code into a page and getting this response: “Sorry, you do NOT have access to this file” Here’s the code below, am I missing something?

"arms_11.1.mp4", "rtmp://s11efhi1yjrfux.cloudfront.net" => true, "count_against_user" => true); ?>



   
       jwplayer("jw-container").setup({modes: /* JW Player®. */
       [
           /* First try real-time streaming with Flash® player. */
           {type: "flash", provider: "rtmp", src: "/jwplayer/player.swf",
               config: {streamer: "", file: ""}},
       
           /* Else, try an HTML5 video tag. */
           {type: "html5", provider: "video",
               config: {file: ""}},
       
           /* Else, this is a safe fallback. */
           {type: "download", /* Download the file. */
               config: {file: ""}}
       ],
       /* Set video dimensions. */ width: 480, height: 270
       });
   


   Sorry, you do NOT have access to this file.
  • This topic was modified 4 years, 11 months ago by  luisrosario.
  • This topic was modified 4 years, 11 months ago by  luisrosario.
  • This topic was modified 4 years, 11 months ago by  luisrosario.

List Of Topic Replies

Viewing 25 replies - 1 through 25 (of 35 total)
Author Replies
Author Replies
Posted: Tuesday Feb 14th, 2012 at 6:17 pm #5081
Staff Member

Hi there. Thanks for your inquiry.

It looks like the code sample you posted is missing either PHP tags, or the Shortcode equivalents made possible by s2Member. Have you tried the code samples provided in your Dashboard under: s2Member -> Download Options -> JW Player RTMP Examples?

If problems persist, please be sure that you’re running this code through the HTML tab of your WordPress editor, and that you have a plugin like RAW HTML enabled. If you’re running the version with PHP tags, please be sure that you’re running a PHP execution plugin.

Reference plugins that can assist with this type of integration.
http://wordpress.org/extend/plugins/raw-html/
http://wordpress.org/extend/plugins/exec-php/

Posted: Tuesday Feb 14th, 2012 at 6:55 pm #5092

I jason, I am using the code example from within the dashboard.. the code gets corrupt upon posting into the form on this forum. When I preview post it looks what I have in my html editor, but upon submitting it gets corrupted on here. not sure why… I reposted this issue here’s what I posted:

Hello, I’m hoping someone might be able to help me with this cloudfront config with jwplayer. I’m just not clear what needs to be filled in the JWPlayer RTMP Protocol Example Code.

I have successfully created cloudfront download and streaming distributions: I have a file located in my S3 bucket:

access-s2-member-level0/arms_11.1.mp4

I’m trying to use this url for my file:

http://www.groovetemple.tv/?s2member_file_download=access-s2member-level0/arms_11.1.mp4

What do I insert and where in the below example to get this video properly loaded using RTMP? Really need help with this. I’ve tried looking on the forums and tried different combinations on trying to make this work and I can’t figure it out. When I load the above link into the web browser, it seems to authenticate and loads video via download distribution. Some instances I get access denied or video not found and others I get stream not found. I just need to know what the example code needs to look like with my links… Any help on this would be greatly appreciated.

JW Player® ( RTMP streaming MP4, via s2Member’s Amazon® S3/CloudFront integration )

*Using the code tags corrupts the post so I can’t post the example in this post fyi…

Posted: Tuesday Feb 14th, 2012 at 11:19 pm #5150

Hi Luis.

Could you please try the other URL format that doesn’t use the question mark? Sometimes that causes trouble with the players. [hilite path]WP Admin -> s2Member -> Downloads Options -> Advanced Mod-Rewrite Linkage[/hilite]

I hope it helps. :)

Posted: Friday Feb 17th, 2012 at 2:13 am #5460

That worked. Thanks. One observation.. How does the RTMP seeking work? It seems that I can’t jump ahead while the file is loading.. Thoughts?

Posted: Friday Feb 17th, 2012 at 2:56 am #5467

Great! Thanks for reporting back. :)

I’m not sure about seeking streamed files, since you have only loaded what’s been streamed so far, and I don’t know if the stream can stopped and resumed from another point in the file. I’ll ask Jason about this.

Posted: Saturday Feb 18th, 2012 at 1:34 pm #5597
Staff Member

A new video tutorial for s2Member has just been released, which covers s2Member’s integration with Amazon S3/CloudFront/JW Player, including a brief tutorial on RTMP streaming.

VIDEO: http://www.s2member.com/videos/BD496E5F2CCAB12A/

Regarding “seek” capabilities in JW Player:
(click here for further details please)

Posted: Monday Feb 20th, 2012 at 12:07 am #5673
ryan
Username: ryanm

Hi,

In the dark here… literally.

@Jason that is a great video that you put together and just in time; thanks. However, I’m having a bit of an issue; after following along with you I end up with just a black box where the video should be. I have tested multiple browsers and the all produce the same result — except for Firefox it produces a white/blank area.

I have tested the URL, http://site.com/?s2member_file_download=example-file.zip, and I’m able to download the file. I have checked the source code and I was able to download the file using (the HTML5) URL.

Any thoughts on what I might be doning wrong?

Cheers,
Ryan

Posted: Monday Feb 20th, 2012 at 12:31 pm #5700

Hey Ryan, the tutorial works if you follow it to the tee. The confusing part is how to build the url for rtmp streaming. The only thing you need to enter in the example code is the absolute file path to the file in your s3 bucket. As an example, below is an sample of a test I’m doing, locate this piece of code in the example code provided by s2member, as you can see all I’ve done is inserted where it says (“file_download” => “file”, …. the absolute path to my file. In this example I have a file in an access-s2member-level0 subdirectory which gives access to level0. if you don’t have your file in a s2 member subdirectory or any subdirectory for that matter, then the only thing you need to enter is the file name.. that’s it. nothing more, provided that you have configured cloudfront correctly. and after installing the raw html plugin as suggested in the tutorial, my example worked. make sure you re-paste the example code into the page/post and after you have installed the plugin, insert the path to the file as it exists in your bucket and it should work.

$cfg = array (“file_download” => “access-s2member-level0/arms_11.1.mp4”, “url_to_storage_source” => true, “count_against_user” => true, “check_user” => true); ?>

The streaming works beautifully and if you are on a mobile device it falls back to html video tag which then gets distributed by your file download distribution on cloudfront.

Posted: Monday Feb 20th, 2012 at 5:17 pm #5734

Hey there Jason, am I correct in recognizing if we look at page source, one can copy the download link distribution and download the file? So logged in user if they have access to a specific video, all they have to do is look at page source to download the file?? Can you confirm if this is the case? Thank you.

-Luis

Posted: Monday Feb 20th, 2012 at 8:34 pm #5770
ryan
Username: ryanm

Hi luisrosario,

Thank you very much for your response. I see now where the confusion is — I’m sure it all made sense in my head at the time I wrote my post.

I think I followed it exactly, in fact I did just as Jason did and uploaded “video.mp4” to my S3 bucket. Then I copied the code from the JWplayer example and pasted it into a new post.

What I wanted to convey with my example was that the URL

http://site.com/?s2member_file_download=video.mp4

worked and I was able to download the file. I was also able to use the HTML5 URL from the source and download the file using that.

To answer your question to Jason; it does work. This is why Jason suggested that if you wanted something more secure you could remove the HTML5 and download options from the example code. (RTMP doesn’t allow the user to “download” the file just “stream” it.)

I’m sure I “fat-fingered” something and I’m sure it will look beautiful… once I figure out what I have done wrong. :)

Thanks again!

Cheers,
Ryan

Posted: Monday Feb 20th, 2012 at 10:08 pm #5784

Hey Ryan, I’m sure you’ll get what you need. I’m aware of removing the html5 will render the video to go with a rtmp stream. What I’m hoping for is to extend this so I can protect html url so it can’t be downloaded but still viewed on mobile devices. I’m currently using s3flowshield to protect my video files with s2member on top for extra security. It only works with s3 storage. With s3flowshield the url to the file is encrypted and expires where I have the option to set the time to expire i.e. 10min. So you can’t copy and past the download url into the browser and download. The main limitation is it doesn’t have cloudfront support and is why it makes sense for us to use s2member for this functionality. @Jason , is there a way to do this with s2member? I want to be able to allow for the html fallback for video playback on mobile devices but don’t want the download url to be exposed. Any thoughts?

Posted: Monday Feb 20th, 2012 at 11:14 pm #5808
ryan
Username: ryanm

Another “data point;” if I try to viewing the post via the “Preview Changes” button within the edit window nothing is displayed, not even the black “place holder.” However, if I “View” the page the “place holder” is displayed.

I am guessing this points to an issue with the “compiling” the code on the page. To confirm I have “Raw HTML” installed and all four of the check boxes are selected. I also have “Exec-PHP” installed; I have “Execute PHP code in text widgets” selected, and have “Disable the visual editor when writing” selected.

Cheers,
Ryan

Posted: Monday Feb 20th, 2012 at 11:28 pm #5812
ryan
Username: ryanm

One step forward… two steps back.

I found that I had the JWPlayer for WordPress plug-in installed (something I was previously playing around with — before S2M). I uninstalled that, deleted the jwplayer dir in the root of my WP dir, recreated the jwplayer dir and and (re)uploaded the files again.

Now I get… nothing. :( Something I noted before pulling the JWP plugin was that if I removed the flash option in the code I was show an HTML5 player.

Ryan

Posted: Monday Feb 20th, 2012 at 11:34 pm #5814
ryan
Username: ryanm

OK… I think I have resolved the issue.

JWPlayer doesn’t necessarily go in the root of your WP directory, at least not if you just copy the example code. The example code references the root of web directory (i.e. “/jwplayer/jwplayer.js”). So, the issue was PEBKAC all along!

ryan

Posted: Thursday Feb 23rd, 2012 at 3:38 pm #6162
Raam Dev
Username: Raam
Staff Member

Ryan,

Thank you for the update. I can see how the code example might be confusing and I will recommend making that clearer.

luisrosario,

The URLs that are visible with the HTML5 option will still be restricted to logged in users and whatever options you have configured for file downloads will still apply. However, it’s not possible to prevent a user from downloading the video if they have access to it and it’s loaded with the HTML5 player.

Posted: Thursday Feb 23rd, 2012 at 7:11 pm #6218

Hey Raam, thanks for the reply. So correct me if I’m wrong, if my site is streaming site only and I don’t want to allow people to download a video, just watch it, s2member will allow them to download the file? Even if I set restrictions on the file downloads, users will at least need access for 1 download to even see the video, otherwise it won’t load in the player and they would get redirected to the downloads exceed page? is that right? So then I would have to allow access to let them see it, but expose the url in page source where people could copy the link at download. If it set 0 downloads in the download restrictions settings, then users will not be able to see html fallback on mobile devices.. is that right?

Posted: Thursday Feb 23rd, 2012 at 11:47 pm #6230
ryan
Username: ryanm

Raam,

I think it was really a operator error.

I thought that I read in some of the s2m documentation that the S3 URI could be set up to have a TTL. Did I misread that? Although the HTML5 URI would still give a member access to download the file it would only be “good” for a fixed amount of time. This would also address another possible issue: once a member has the URI, even for RTMP, they can reference that externally (i.e. on their own site). Or does this would have to be regulated with S3. Is that something that can be done on S3?

Cheers,
Ryan

Posted: Friday Feb 24th, 2012 at 6:14 pm #6348

Right, files served from Amazon via s2Member’s download protection, will have a very short time limit and won’t work after that. So, even if the URL gets shared, it would have expired.

Luis, does that solve your problem?

Posted: Saturday Feb 25th, 2012 at 1:18 pm #6412
ryan
Username: ryanm

Hi Cristián,

Thank you for the follow up. Could you help refresh my memory and tell me where this section is in the documentation?

Cheers,
Ryan

Posted: Saturday Feb 25th, 2012 at 2:11 pm #6415
ryan
Username: ryanm

Jason spoke (in his tutorial video) about wrapping the JW code into a plugin. Has anyone whipped one of these up?

Posted: Monday Feb 27th, 2012 at 4:47 pm #6554
Raam Dev
Username: Raam
Staff Member

Ryan,

You can find s2Member documentation for downloads and Amazon S3 in Dashboard -› s2Member® -› Download Options.

This line from Dashboard -› s2Member® -› Download Options -› Advanced Download Restrictions may be of particular interest to you:

Each Key it produces ( at the time it is produced ), will be valid for the current day, and only for a specific IP address and User-Agent string; as detected by s2Member.

Posted: Monday Feb 27th, 2012 at 7:30 pm #6601
Staff Member

Thanks for the follow-ups.

Let me start here please…

@luisrosario

Hey there Jason, am I correct in recognizing if we look at page source, one can copy the download link distribution and download the file? So logged in user if they have access to a specific video, all they have to do is look at page source to download the file?? Can you confirm if this is the case? Thank you.

Right. Exposing the HTML5 video tag option, or direct download option; as fallbacks, makes the MP4 URL available. So you’d want to remove those additional fallbacks if you’re concerned about this (i.e. if you only want to allow true RTMP streaming). RTMP streaming is the most secure option, and should work fine for most visitors.

This is a usability vs. security issue. If you want to maximize usability, allow the fallback options. If you’re more concerned about security, you’ll need to require Users/Members to have Flash®, so they can view the RTMP stream; but NOT allow them to access the MP4 file directly (i.e. remove the direct MP4 fallbacks).

In addition to NOT making the MP4 URLs available, you might also want to disable any type of direct downloading of these files through other means (i.e. to prevent a logged in Member from typing a URL directly to the file download). By default, all files are available to Users/Members who pass your Basic Download Restrictions. Your S3 Bucket is a drop-in replacement for the normal /s2member-files/ directory, so the ability to download files through a direct link remains possible.

For example, even if you don’t make the MP4 URL available in your JW Player code, I could still type a URL like this one. If I’m logged into your site, and I pass your Basic Download Restrictions, I can download the MP4.

http://example.com/?s2member_file_download=video.mp4

Here is one way to prevent this from occurring.
Don’t set any Basic Download Restrictions for s2Member, causing your installation of s2Member to NOT allow any direct downloads at all. Instead, you’ll need to take further control over the way File Downloads are handled, through Advanced Download Restrictions, with File Download Keys (i.e. only you, as the site owner, will decide when/where File Downloads are going to be allowed). If you go this route, you’d need to issue a File Download Key when generating your RTMP streamer with s2Member.

For example… file_download_key => true
Reference docs on: s2member_file_download_url()

<div id="jw-container">JW Player® appears here.</div>
<script type="text/javascript" src="/jwplayer/jwplayer.js"></script>

<?php if(is_user_logged_in() && current_user_can("access_s2member_level1"))
	{
		/* A direct URL to the RTMP source; issuing a File Download Key to the current visitor in real-time. */
		$cfg = array ("file_download" => "video.mp4", "file_download_key" => true, "url_to_storage_source" => true);
		
		/* API Function `s2member_file_download_url()`.
			See docs here: http://www.s2member.com/codex/stable/s2member/api_functions/package-functions/#src_doc_s2member_file_download_url() */
		$mp4 = s2member_file_download_url ($cfg, "get-streamer-array");
		?>

		<script type="text/javascript">
			jwplayer("jw-container").setup({modes: /* JW Player®. */
			[
				/* Only allow real-time streaming with Flash® player. */
				{type: "flash", provider: "rtmp", src: "/jwplayer/player.swf",
				config: {streamer: "<?php echo $mp4&#91;"streamer"&#93;; ?>", file: "<?php echo $mp4&#91;"file"&#93;; ?>"}}
			],
			/* Set video dimensions. */ width: 480, height: 270
			});
		</script>

<?php } else /* Access is denied by site owner. */ { ?>
	Sorry, you do NOT have access to this file.
<?php } ?>
  • This reply was modified 4 years, 10 months ago by  Jason (Lead Developer). Reason: Made code sample clearer
  • This reply was modified 4 years, 10 months ago by  Jason (Lead Developer). Reason: Made code sample clearer
  • This reply was modified 4 years, 10 months ago by  Jason (Lead Developer). Reason: Updated to "file_download_key" => true
Posted: Monday Feb 27th, 2012 at 8:07 pm #6608
Staff Member

Regarding TTLs. This is documented in your Dashboard for Amazon S3 under: Dashboard -› s2Member® -› Download Options -› Amazon® S3/CDN Storage, but I don’t think we’ve added this to the Dashboard documentation for CloudFront yet. Actually, it’s a very rare occasion where these need to be altered.

These Filters are mentioned in the s2Member Codex, but I’ll go ahead and provide some examples below.
http://www.s2member.com/codex/stable/s2member/files/package-filters/

If you’re running Amazon S3 only, without CloudFront.
Create this directory and file to increase or decrease the TTL.
( these are MUST USE plugins, see: http://codex.wordpress.org/Must_Use_Plugins )
/wp-content/mu-plugins/s2-hacks.php

<?php
add_filter("ws_plugin__s2member_amazon_s3_file_expires_time", "my_s3_file_expires_time");
function my_s3_file_expires_time($default = "30 seconds")
/* Anything compatible with PHP's strtotime() function.
	30 seconds is the default, and that's more than enough time
	for someone to connect to the file in your Amazon S3 Bucket
	(i.e. you want this to be a very low value). */
{ return /* You might say... */ "2 hours"; }
?>

If you’re running Amazon S3 *with* CloudFront tied in also.
Create this directory and file to increase or decrease the TTL.
( these are MUST USE plugins, see: http://codex.wordpress.org/Must_Use_Plugins )
/wp-content/mu-plugins/s2-hacks.php

<?php
add_filter("ws_plugin__s2member_amazon_cf_file_expires_time", "my_cf_file_expires_time");
function my_cf_file_expires_time($default = "24 hours")
/* Anything compatible with PHP's strtotime() function.
	24 hours is the default. Here we need to allow a little more time,
	in case streaming playback is seeked, or paused and then resumed. Again, it's very
	rare that you'd need to change this default value. I recommend 24 hours. */
{ return /* You might say... */ "2 days"; }
?>
  • This reply was modified 4 years, 10 months ago by  Jason (Lead Developer). Reason: Made code sample clearer
Posted: Tuesday Feb 28th, 2012 at 8:00 pm #6693

Tried your example for file_download_key => true and getting a stream not found. I have a working example of the standard config of jw and html fallback, this new example having trouble with @Jason … Also, I had a question. Is there a way to force a s3 download link not cloudfront into the html fallback? So basically if a mobile device is loading html fallback, instead of the video coming form cloudfront, it’s delivered from s3 storage utilizing the default 30 second expiration to prevent link sharing. Is that possible? Creating a hybrid of s3 and cloudfront dynamically generating the urls for each case in the jwplayer…

-Luis

Posted: Wednesday Feb 29th, 2012 at 12:39 am #6720
ryan
Username: ryanm

Hi guys,

Thank you for all of the follow ups. I will likely need to implement the isolation that Jason outlined above, but right now I’m focused on making the insertion of videos (with S3/CloudFront) a bit more user-friendly.

Below is my first attempt at a shortcode function that take the perimeters of video file, width, height, and title and builds the code block. Alas, I’m having a bit of an issue with the retuned PHP — the PHP sections are not being processed as PHP. Any thoughts on what I have done wrong and what I could do differently?

add_shortcode('fdnVideo_embed', function ($atts){
	$atts = shortcode_atts(
		array(
			'src' 	=>	'',
			'width' =>	'600',
			'height'=>	'338',
			'title' =>	''
	), $atts);
	

	return '
		<div id="jw-container">JW Player® appears here.</div>
		<script type="text/javascript" src="/jwplayer/jwplayer.js"></script>

		<?php 
			/* A direct URL to the RTMP source; counting the file against the current User in real-time. */
			$cfg = array ("file_download" => "'. $atts['src'] .'", "url_to_storage_source" => true, "count_against_user" => true); 
		?>

		<?php 
			/* API Function `s2member_file_download_url()` returns false if access is denied to the current User. */
			if (($mp4 = s2member_file_download_url ($cfg, "get-streamer-array"))) { 
		?>

		    <script type="text/javascript">
        		jwplayer("jw-container").setup({modes: /* JW Player®. */
        		[
            		/* First try real-time streaming with Flash® player. */
		            {type: "flash", provider: "rtmp", src: "/jwplayer/player.swf",
						config: {streamer: "<?php echo $mp4["streamer"]; ?>", file: "<?php echo $mp4["file"]; ?>"}},
        
		        /* Else, try an HTML5 video tag. */
		            {type: "html5", provider: "video",
        		        config: {file: "<?php echo $mp4["url"]; ?>"}},
        
            		/* Else, this is a safe fallback. */
		            {type: "download", /* Download the file. */
		                config: {file: "<?php echo $mp4["url"]; ?>"}}
				],
        		/* Set video dimensions. */ 
        		width: '. $atts['width'] .', height: '. $atts['height'] .'
        		});
   			</script>

		<?php } else /* Access is denied to the current User. */ { ?>
		Sorry, you do NOT have access to this file.
		<?php }?>
		';
     	 
});

Next I’d like to include perimeters to include HTML5 and DL option with in the shortcode, should one want to make those available on-the-fly.

Cheers,
Ryan

P.S. This code takes advantage of the PHP 5.3’s anonymous functions; so it will only work (as is) on systems running PHP 5.3.

  • This reply was modified 4 years, 10 months ago by  ryan.
Viewing 25 replies - 1 through 25 (of 35 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.