# Plex Transcode API

**URL:** <https://forums.plex.tv/t/plex-transcode-api/7312>\
**Category:** Dev/API Corner\
**Tags:** other-dev\
**Created:** [January 9, 2011, 9:37pm UTC](https://forums.plex.tv/t/plex-transcode-api/7312 "2011-01-09T21:37:16Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![nadocrew](https://avatars.discourse-cdn.com/v4/letter/n/aca169/32.png) [@nadocrew](https://forums.plex.tv/u/nadocrew)\
**Post date:** [January 9, 2011, 9:37pm UTC](https://forums.plex.tv/t/plex-transcode-api/7312/1 "2011-01-09T21:37:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![quiqueck](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/quiqueck/32/800_2.png) [@quiqueck](https://forums.plex.tv/u/quiqueck)\
**Post date:** [January 9, 2011, 11:00pm UTC](https://forums.plex.tv/t/plex-transcode-api/7312/2 "2011-01-09T23:00:40Z")

</div>

> [@](#):
>
> 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]

---

<div class="post-metadata">

**Author:** ![drensin](https://avatars.discourse-cdn.com/v4/letter/d/c4cdca/32.png) [@drensin](https://forums.plex.tv/u/drensin)\
**Post date:** [January 10, 2011, 1:36am UTC](https://forums.plex.tv/t/plex-transcode-api/7312/3 "2011-01-10T01:36:08Z")

</div>

> [@](#):
>
> 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

---

<div class="post-metadata">

**Author:** ![drensin](https://avatars.discourse-cdn.com/v4/letter/d/c4cdca/32.png) [@drensin](https://forums.plex.tv/u/drensin)\
**Post date:** [January 10, 2011, 1:38am UTC](https://forums.plex.tv/t/plex-transcode-api/7312/4 "2011-01-10T01:38:23Z")

</div>

> [@](#):
>
> 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]

  
  
  
actually, that's not quite right. The X-Plex-Access-\* keys actually go as headers in the HTTP request from step one.  
  
-dave

---

<div class="post-metadata">

**Author:** ![drensin](https://avatars.discourse-cdn.com/v4/letter/d/c4cdca/32.png) [@drensin](https://forums.plex.tv/u/drensin)\
**Post date:** [January 10, 2011, 1:47am UTC](https://forums.plex.tv/t/plex-transcode-api/7312/5 "2011-01-10T01:47:40Z")

</div>

> [@](#):
>
> 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?

  
  
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

---

<div class="post-metadata">

**Author:** ![quiqueck](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/quiqueck/32/800_2.png) [@quiqueck](https://forums.plex.tv/u/quiqueck)\
**Post date:** [January 10, 2011, 6:00pm UTC](https://forums.plex.tv/t/plex-transcode-api/7312/6 "2011-01-10T18:00:09Z")

</div>

> [@](#):
>
> actually, that's not quite right. The X-Plex-Access-\* keys actually go as headers in the HTTP request from step one.  
>   
> -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.

---

<div class="post-metadata">

**Author:** ![nadocrew](https://avatars.discourse-cdn.com/v4/letter/n/aca169/32.png) [@nadocrew](https://forums.plex.tv/u/nadocrew)\
**Post date:** [January 10, 2011, 11:17pm UTC](https://forums.plex.tv/t/plex-transcode-api/7312/7 "2011-01-10T23:17:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![drensin](https://avatars.discourse-cdn.com/v4/letter/d/c4cdca/32.png) [@drensin](https://forums.plex.tv/u/drensin)\
**Post date:** [January 14, 2011, 4:54pm UTC](https://forums.plex.tv/t/plex-transcode-api/7312/8 "2011-01-14T16:54:08Z")

</div>

> [@](#):
>
> 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

---

<div class="post-metadata">

**Author:** ![nadocrew](https://avatars.discourse-cdn.com/v4/letter/n/aca169/32.png) [@nadocrew](https://forums.plex.tv/u/nadocrew)\
**Post date:** [January 14, 2011, 8:18pm UTC](https://forums.plex.tv/t/plex-transcode-api/7312/9 "2011-01-14T20:18:52Z")

</div>

thanks, Ill give that a try

---

<div class="post-metadata">

**Author:** ![sander1](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@sander1](https://forums.plex.tv/u/sander1)\
**Post date:** [January 17, 2011, 4:43pm UTC](https://forums.plex.tv/t/plex-transcode-api/7312/10 "2011-01-17T16:43:01Z")

</div>

> [@](#):
>
> http://www.flowplayer.org  
>   
> -dave

  
  
Unfortunately Flowplayer can't play the streams produced by PMS :(  
http://flowplayer.org/forum/6/45644

---

<div class="post-metadata">

**Author:** ![drensin](https://avatars.discourse-cdn.com/v4/letter/d/c4cdca/32.png) [@drensin](https://forums.plex.tv/u/drensin)\
**Post date:** [January 19, 2011, 2:28am UTC](https://forums.plex.tv/t/plex-transcode-api/7312/11 "2011-01-19T02:28:28Z")

</div>

> [@](#):
>
> Unfortunately Flowplayer can't play the streams produced by PMS :(  
> http://flowplayer.org/forum/6/45644

  
  
hmmm... Silverlight, perhaps?  
  
-dave

---

<div class="post-metadata">

**Author:** ![delley](https://avatars.discourse-cdn.com/v4/letter/d/9fc29f/32.png) [@delley](https://forums.plex.tv/u/delley)\
**Post date:** [January 20, 2011, 3:36pm UTC](https://forums.plex.tv/t/plex-transcode-api/7312/12 "2011-01-20T15:36:52Z")

</div>

This article from JW player kinda lays out the issues in streaming media at the moment: [article](http://www.longtailvideo.com/support/blog/11887/html5-video-not-quite-there-yet)  
  
  
  
Does anyone know if the Plex transcode API can do other output formats than the Apple specific m3u8 text format?  
  
  
  
Regards,  
  
  
  
delley

---

<div class="post-metadata">

**Author:** ![sander1](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@sander1](https://forums.plex.tv/u/sander1)\
**Post date:** [January 21, 2011, 12:07am UTC](https://forums.plex.tv/t/plex-transcode-api/7312/13 "2011-01-21T00:07:15Z")

</div>

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 element.  
  
  
  
HTTP Live Streaming  
  
Video codec: H.264  
  
Audio codec: AAC  
  
Container: TS (not MP4) because of the live transcoding (because it’s header-less)

---

<div class="post-metadata">

**Author:** ![delley](https://avatars.discourse-cdn.com/v4/letter/d/9fc29f/32.png) [@delley](https://forums.plex.tv/u/delley)\
**Post date:** [February 4, 2011, 12:32pm UTC](https://forums.plex.tv/t/plex-transcode-api/7312/14 "2011-02-04T12:32:46Z")

</div>

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:

> [@](#):
>
> Go for it, just make sure you note that I said “this area is still in development and subject to change”

  
  
The sample:  

```auto

<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 />

```

---

<div class="post-metadata">

**Author:** ![AeroJack](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@AeroJack](https://forums.plex.tv/u/AeroJack)\
**Post date:** [February 5, 2011, 12:25am UTC](https://forums.plex.tv/t/plex-transcode-api/7312/15 "2011-02-05T00:25:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hippojay](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/hippojay/32/41_2.png) [@hippojay](https://forums.plex.tv/u/hippojay)\
**Post date:** [February 18, 2011, 2:08pm UTC](https://forums.plex.tv/t/plex-transcode-api/7312/16 "2011-02-18T14:08:23Z")

</div>

> [@](#):
>
> 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).

  
  
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..

---

<div class="post-metadata">

**Author:** ![nadocrew](https://avatars.discourse-cdn.com/v4/letter/n/aca169/32.png) [@nadocrew](https://forums.plex.tv/u/nadocrew)\
**Post date:** [May 2, 2011, 3:01am UTC](https://forums.plex.tv/t/plex-transcode-api/7312/17 "2011-05-02T03:01:39Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![hippojay](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/hippojay/32/41_2.png) [@hippojay](https://forums.plex.tv/u/hippojay)\
**Post date:** [May 10, 2011, 11:23am UTC](https://forums.plex.tv/t/plex-transcode-api/7312/18 "2011-05-10T11:23:30Z")

</div>

Looks like there is an issue with the generic transcoder - it can’t read the preset files for whatever reason:

```auto

<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...

---

<div class="post-metadata">

**Author:** ![elan](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/elan/32/5_2.png) [@elan](https://forums.plex.tv/u/elan)\
**Post date:** [May 11, 2011, 7:34am UTC](https://forums.plex.tv/t/plex-transcode-api/7312/19 "2011-05-11T07:34:57Z")

</div>

```auto

<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 :(

---

<div class="post-metadata">

**Author:** ![hippojay](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/hippojay/32/41_2.png) [@hippojay](https://forums.plex.tv/u/hippojay)\
**Post date:** [May 11, 2011, 10:07am UTC](https://forums.plex.tv/t/plex-transcode-api/7312/20 "2011-05-11T10:07:35Z")

</div>

Thanks - didn’t think it would be high on the list.

[Next page](https://forums.plex.tv/t/plex-transcode-api/7312.md?page=2)
