Is there any documentation on the transcoding API. I know that we have the API key and the secret now, I just dont know how to use the API to transcode media. The sample javascript file was not very helpful. Anyone know?
Nope, the javascript is all we have. What you want to do is the following:
[list=1]
[*]Create the streaming URL ("http://localhost:32400/..")
[*]Get the unix time (123456)
[*]Create a string URL@time (http://localhost:32400/...@123456)
[*]create a hmacSha256 hash for the above string, using the private key
[*]bas64 encode the generated hash
[*]add &X-Plex-Access-Key=PUBLIC-KEY to the above URL
[*]add &X-Plex-Access-Time=time to URL
[*]add &X-Plex-Access-Code=base64-Encoded-hash to URL
[/list]
To continue....
What you will get back is a .m3u8 file.
This is an HTTP Live Streaming playlist file. You need to know how to interpret this file as it contains definitions of the parts of the stream you are transcoding. The stream components appear to be MPEG-TS format. (makes sense). So you need to know how feed them to whatever is going to render your stream.
-dave
actually, that's not quite right. The X-Plex-Access-* keys actually go as headers in the HTTP request from step one.
-dave
sample code in C#:
// unix time is the number of milliseconds from 1/1/1970 to now..
DateTime jan1 = new DateTime(1970, 1, 1, 0, 0, 0);
double dTime = (DateTime.Now - jan1).TotalMilliseconds;
// this next url part is contained in the PartKey key in the xml that describes your content
string part = "/library/parts/6031/Back%20Alley%20Uproar.mp4";
// as per the Javascript example, round up the Unix time
string time = Math.Round(dTime / 1000).ToString();
// the basic url WITH the part key is:
string url = "/video/:/transcode/segmented/start.m3u8?identifier=com.plexapp.plugins.library&ratingKey=97007888&offset=0&quality=5&url=http%3A%2F%2Flocalhost%3A32400" + Uri.EscapeDataString(part) + "&3g=0&httpCookies=&userAgent=";
// the message to hash is url + an @ + the rounded time
string msg = url + "@" + time;
string publicKey = "KQMIY6GATPC63AIMC4R2";
byte[] privateKey = Convert.FromBase64String("k3U6GLkZOoNIoSgjDshPErvqMIFdE0xMTx8kgsrhnC0=");
// initialize a new HMACSHA256 class with the private key from Elan
HMACSHA256 hmac = new HMACSHA256(privateKey);
// compute the hash of the message. Note: .net is unicode double byte, so when we get the bytes
// from the message we have to be sure to use UTF8 decoders.
hmac.ComputeHash(UTF8Encoding.UTF8.GetBytes(msg));
//our new super secret token is our new hash converted to a Base64 string
string token = Convert.ToBase64String(hmac.Hash);
// now that we have our information, it's time to make the HTTP request.
// Step 1: create a new web client
System.Net.WebClient wc = new System.Net.WebClient();
// Step 2: add the magic headers with the values we just computed.
wc.Headers.Add("X-Plex-Access-Key", publicKey);
wc.Headers.Add("X-Plex-Access-Time", time);
wc.Headers.Add("X-Plex-Access-Code", token);
// download the http response. (in this case, mediacenter is the Plex host
string s = wc.DownloadString("http://mediacenter:32400" + url);
OK... At this point, the variable s contains the contents of a .m3u8 playlist to use for HTTP Live Streaming.
-dave
Nope, that was changed. You can add them as Headers or URL arguments (which in most cases is easier). URL params are also needed when you want to redirect the streams with AirPlay for example.
thanks for the info guys. What is the best way to play the transcoded file in html5? Are there any plug ins that will play them?
http://www.flowplayer.org
-dave
thanks, Ill give that a try
Unfortunately Flowplayer can't play the streams produced by PMS :(
http://flowplayer.org/forum/6/45644
hmmm... Silverlight, perhaps?
-dave
This article from JW player kinda lays out the issues in streaming media at the moment: article
Does anyone know if the Plex transcode API can do other output formats than the Apple specific m3u8 text format?
Regards,
delley
Silverlight can’t handle these types of streams too
The only method (that I know of) to play those streams is in Safari with the
I’ve been PM’ing with Elan. And he told me that they are messing about with some generic transcoding. He sent me this sample of a transcoding to FLV format (H.264 + AAC).
He also said:
The sample:
<br />
<br />
Dec 20, 2010 00:08:55 [0xb0595000] DEBUG - Request: GET /video/:/transcode/generic.flv?format=flv&videoCodec=libx264&vpre=video-embedded-h264&videoBitrate=5000&audioCodec=libfaac&apre=audio-embedded-aac&audioBitrate=128&size=640x480&fakeContentLength=2000000000&url=http%3A%2F%2F192%2E168%2E1%2E87%3A32400%2Fvideo%2F.......[::ffff:192.168.1.87] (1 live)<br />
Dec 20, 2010 00:08:55 [0xb0595000] DEBUG - * format => flv<br />
Dec 20, 2010 00:08:55 [0xb0595000] DEBUG - * videoCodec => libx264<br />
Dec 20, 2010 00:08:55 [0xb0595000] DEBUG - * vpre => video-embedded-h264<br />
Dec 20, 2010 00:08:55 [0xb0595000] DEBUG - * videoBitrate => 5000<br />
Dec 20, 2010 00:08:55 [0xb0595000] DEBUG - * audioCodec => libfaac<br />
Dec 20, 2010 00:08:55 [0xb0595000] DEBUG - * apre => audio-embedded-aac<br />
Dec 20, 2010 00:08:55 [0xb0595000] DEBUG - * audioBitrate => 128<br />
Dec 20, 2010 00:08:55 [0xb0595000] DEBUG - * size => 640x480<br />
Dec 20, 2010 00:08:55 [0xb0595000] DEBUG - * fakeContentLength => 2000000000<br />
Dec 20, 2010 00:08:55 [0xb0595000] DEBUG - * url => http:....<br />
<br />
Does anyone know if there is a way currently to control how the audio is encoded? Looks like the audio in the TS segments are encoded with MP3, and I would like them to be AAC.
Thanks for the info. Just implemented this and it worked first time (well, first time I realised that this URL produces a stream , not a link to a stream ;-) ). Just need to mess with the various bitrates and sizes now..
has anyone been successful with the generic transcoding API? I can’t seem to get it working correctly… Also I am unsure what players will play it…
Looks like there is an issue with the generic transcoder - it can’t read the preset files for whatever reason:
<br />
$ /Users/dave/Library/"Application Support"/Plex/"Plex Media Server.app"/Contents/Resources/ffmpeg -i http://localhost:32400/library/parts/12298/ben%2E10%2Es02e01%2E-%2Etruth.avi -async 1 -f flv -vcodec libx264 -vpre /Users/dave/Library/"Application Support"/"Plex Media Server"/Plug-ins/System.bundle/Contents/Resources/transcode-presets/video-embedded-h264.ffpreset -b 5000k -acodec libfaac -apre /Users/dave/Library/"Application Support"/"Plex Media Server"/Plug-ins/System.bundle/Contents/Resources/transcode-presets/audio-embedded-aac.ffpreset -s 640x480 -<br />
<br />
FFmpeg version UNKNOWN, Copyright (c) 2000-2011 the FFmpeg developers<br />
built on May 2 2011 14:57:55 with gcc 4.2.1 (Apple Inc. build 5666) (dot 3)<br />
configuration: --enable-encoders --enable-muxers --enable-encoder=libfaac --enable-encoder=libx264 --enable-muxer=mpegts --enable-libx264 --enable-gpl --enable-libfaac --enable-nonfree --extra-ldflags='-Llib/darwin10-x86_64 -arch x86_64 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk -lcurl -lx264 -lass -lfreetype -lfribidi -lfontconfig -liconv -lexpat -lcrypto -lssl' --extra-cflags='-Iinclude/darwin10-x86_64 -arch x86_64 -mdynamic-no-pic -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk' --enable-pthreads --disable-bzlib --arch=i386 --disable-protocol=rtp --enable-muxer=mp4 --enable-avfilter --disable-muxer=image2 --disable-muxer=image2pipe --disable-shared --disable-ffplay --disable-ffserver --enable-libmp3lame --disable-debug --enable-optimizations<br />
libavutil 50. 40. 1 / 50. 40. 1<br />
libavcodec 52.117. 0 / 52.117. 0<br />
libavformat 52.105. 0 / 52.105. 0<br />
libavdevice 52. 4. 0 / 52. 4. 0<br />
libavfilter 1. 77. 1 / 1. 77. 1<br />
libswscale 0. 13. 0 / 0. 13. 0<br />
<br />
Seems stream 0 codec frame rate differs from container frame rate: 23.98 (65535/2733) -> 23.98 (24000/1001)<br />
Input #0, avi, from 'http://localhost:32400/library/parts/12298/ben%2E10%2Es02e01%2E-%2Etruth.avi':<br />
Metadata:<br />
encoder : VirtualDubMod 1.5.4.1 (build 2178/release)<br />
Duration: 00:23:00.72, start: 0.000000, bitrate: 1063 kb/s<br />
Stream #0.0: Video: mpeg4, yuv420p, 624x464 [PAR 1:1 DAR 39:29], 23.98 tbr, 23.98 tbn, 23.98 tbc<br />
Stream #0.1: Audio: mp3, 48000 Hz, stereo, s16, 112 kb/s<br />
File for preset '/Users/dave/Library/Application Support/Plex Media Server/Plug-ins/System.bundle/Contents/Resources/transcode-presets/video-embedded-h264.ffpreset' not found<br />
The file is available (a simple ls -l shows that), so ffmpeg isn't searching for it correctly. However, I can get the preset file to work correctly when using "fpre" - but not through PMS...
<br />
/Users/dave/Library/Application Support/Plex Media Server/Plug-ins/System.bundle/Contents/Resources/transcode-presets/video-embedded-h264.ffpreset<br />
Is this file present? (Obvious question, I know)
Verified I seem to see the same issue locally. No time to look at it right now, though :(
Thanks - didn’t think it would be high on the list.