Allow sync without transcoding

ANOTHER +1

I have a pi 2 plex server and an iphone - the transcoding is failing for some reason when the file can play natively. This is the perfect storm of high impact but low effort.

I took out a plex pass so I could sync to my phone, I won’t be renewing given this stupid limitation.

True, just bought the pass and already regret it. Should have googled first

If you think a video should be able to be synced with a transcode, please post the XML from PMS so we can investigate. PMS should not transcode if it really is compatible with the client. Please also say which client you are syncing to and what sync setting you are using. If there is a specific bug, I will see about getting it fixed, but if the video really isn’t compatible and you want to force it, that’s another story.

You can actually sync without transcoding. You only need to not select any subtitles. If you do that, it will download only, not transcoding. With subtitles it still needs to transcode because of the subtitles. This looks like it is a bug to me. Maybe we could just download the subtitle file and the movie apart from each other, instead of transcoding it into one file.

I have been going back to this having previously given up on it as Plex appeared to want to transcode everything even though if I downloaded the file onto the device it would play fine. Recently I noticed however there is now an “Original” option for videos so I thought I would try again.

A little experimentation showed some videos now download while others need transcoding even through they play fine when copied via other means and stream fine to the device using Plex. The two test devices I am using are a Sony Xperia Z1 Compact and Kindle Fire HD (2012).

What I am seeing is if the video is “Web Optimized” then it syncs fine. If it is not “Web Optimized” then Plex seems to feel that the video needs “Web Optimizing” for some completely unknown reason. That I could live with as it is very quick and required very little CPU. I could also use ffmpeg or similar to web optimize all the videos fairly quickly.

However what I have also found is that some videos (basically anything I have encoded with Handbrake) have “Anamorphic 1” in the video properties and this seems to trigger a full transcode. What I see in the Plex server log is the following

May 18, 2016 16:15:26 [0x7f69953ff700] DEBUG - MDE: E01 - The Railway: no remuxable profile found, so video stream will be transcoded

I notice that the Windows Phone.xml profile has a TranscodeTargetProfile section

<TranscodeTargetProfiles>
  <VideoTranscodeTarget protocol="*" context="all">
    <VideoCodec name="*">
      <Limitations>
        <NotMatch name="video.headerStripping" value="1" isRequired="false" />
        <Match name="video.headerCompression" value="" isRequired="false" />
        <UpperBound name="video.bitDepth" value="8" isRequired="false" />
        <NotMatch name="video.anamorphic" value="1" isRequired="false" />
        <NotMatch name="video.hasScalingMatrix" value="1" isRequired="false" />
      </Limitations>
    </VideoCodec>
  </VideoTranscodeTarget>
</TranscodeTargetProfiles>

I am guessing here that the absence of such a section in the Android profile means that it uses a set of defaults which require anamorphic videos to be transcoded? I am tempted to just add a such a section to the Android.xml profile but the complete lack of documentation on this makes me hesitant to do so, and I really don’t want to bust the server as my nephew’s and nieces will get very upset.

I will note first I am running latest version of the server on CentOS7 and the latest version of the clients and have an active PlexPass.

I can confirm after some extensive testing that if the video file is not “web optimized” then Plex will insist on “web optimizing” it before syncing on my Xperia Z1 Compact and Kindle Fire HD tablet. This I regard as a bug, there is no need for a synced video file to be “web optimized”. I have confirmed that by transferring the “synced” file off the device using USB and analysing it on my laptop.

Given that this feature is to allow seeking in streaming files it is in my view irrelevant in synced file as once a file is synced it becomes local. However as this is a high speed process that does not consume much CPU and I can “fix” it by web optimizing my videos I can live with it if necessary.

I can also confirm that any video listed as Anamorphic is transcoded before being synchronized. I can confirm that the videos play back fine locally on the Kindle Fire and Z1 Compact.

I tried adding the following to he Android.xml profile and restarting the server but it didn’t seem to make any difference.

<TranscodeTargetProfiles>
  <VideoTranscodeTarget protocol="http" context="streaming">
    <VideoCodec name="*">
      <Limitations>
        <UpperBound name="video.width" value="1920" />
        <UpperBound name="video.height" value="1080" />
        <NotMatch name="video.anamorphic" value="1" isRequired="false" />
        <NotMatch name="part.optimizedForStreaming" value="1" isRequired="false" />
        <NotMatch name="video.hasScalingMatrix" value="1" isRequired="false" />
        <UpperBound name="video.bitDepth" value="8" isRequired="false" />
      </Limitations>
    </VideoCodec>
  </VideoTranscodeTarget>
</TranscodeTargetProfiles>

Anyway basically I need syncing to not transcode if anamorphic is 1, and ideally ignore web optimized status as well. How does one go about that? It has been a major let down for the last year that the sync feature has always required everything to be transcoded despite the fact the files all play on the devices I am using as is.

So as it stands anything I have downloaded from iPlayer or YouTube can be synced, and all my DVD’s encoded via Handbrake cannot without transcoding :frowning:

Thanks for the info, I’ll look into those findings. When you copied the files to your services, what video player did you use for playback. This makes a big difference.

Ok more random poking about this evening after my nephew and nieces have gone to bed and if I delete the following line from the Android.xml I can sync without transcoding on the proviso that the video is web optimized.

<NotMatch name="video.anamorphic" value="1" isRequired="false" />`

If the video is no web optimized then Plex is insisting on web optimizing it first. However as I said I can live with that as I can just figure out what videos need “web optimizing” and do it all up front. I guess there are advantages to have a video web optimized in the first place so probably worth doing anyway.

Does a synced anamorphic video play back at the right aspect ratio in the Plex app?

To answer both questions I have in the past used a mixture of the built in Amazon video player called Personal Videos but as this switched at some point to showing just thumbnails of the videos which makes it difficult to know what you where playing back I switched to using ES File Explorer which shows file names as well. On the phone I can’t remember what I have used in the past as to be fair I very rarely use the phone for watching videos. I was just using it as another test point. I have just randomly downloaded VLC onto the Kindle Fire and it worked correctly too.

I would of course note that I have hundreds of videos that are marked as anamorphic streamed to Kindle Fire tablets (a mix of models) all the time in Plex and they have always displayed correctly. Consequently it would be bizarre if the synced versions did not display correctly. The only time things have gone astray with the anamorphic stuff is when I was first encoding some recorded TV in avidemux and it was not picking it up correctly from the MPEG2 transport stream and it was therefore wrong in the encoded MP4 and hence displayed all wrong. I noticed it instantly so I expect I would notice issues around this straight away in the future.

The videos I am using for testing the anamorphic works when synced where actually encoded from DVD (Game of Thrones season 1 PAL version) long before I ever had a Plex server for playback on my Kindle Fire HD (2012). They have always played back fine on my Kindle Fire which I believe is an Ice Cream Sandwich derivative of Android.

I have just noticed that I have version 4.24.2.563 of the app on my Kindle Fire but when I check in the store thats version 4.25.2.588 showing as incompatible with my device and requiring Android 4.1 as a minimum. Really what’s in 4.1 that is not in 4.0 that Plex needs?. As I recall 4.1 was almost all performance and stability enhancements. Good job my nephews and nieces are all on the new Fire 7 tablet I guess. Better back the APK up for the future just in case.

Anyway I have sync’ed a number of videos down to my Kindle Fire HD and my Z1 Compact and they all play back with the correct aspect ratio as far as I can tell, and it’s definitely using the local version of the file, because dstat on the server is telling me network usage is under 10 KB/s when they are playing back. They are not obviously wrong, and as I said previously I am sure I would spot that in an instant.

I have however noticed that the app when set to “local and synced content” is displaying all the TV shows on the server when there is a data connection to the server (WiFi or mobile) and only shows the actual synced content when I put it airplane mode. Looks to be a bug if you ask me. It also keeps throwing up error messages about being unable to contact the server and the older version of the app on my Kindle won’t display anything for local and synced content without a data connection.

Thanks @buzzme and @MovieFan.Plex for your hard work and insight. I confirm that commenting out the “video.anamorphic” NotMatch element in Android.xml and having Web Optimized m4v files will sync without transcoding.

When using Handbrake to convert new files, select the “Web optimized” check box when converting.

For existing files, read on.
Disclaimer; not responsible for messed up libraries

My Setup: Plex is on a headless Ubuntu server using mapped drives on a Synology NAS for the library. I use the same mapped drives on a Windows box to manage the library.

Use a static build of ffmpeg from https://ffmpeg.zeranoe.com/builds/, I’m using the 64-bit FFmpeg Build Version: git-64fe1ee (2016-05-20), to web optimize existing m4v files without affecting quality by copying the audio and video.

Such as: ffmpeg -i "input.m4v" -movflags faststart -acodec copy -vcodec copy "output.m4v"

Here’s a little batch script that will walk through the folder structure, rename the current m4v to orig, then web optimize and produce a new m4v as the same input filename:
for /R %%a in (*.m4v) do ( ren "%%a" "%%~na.orig" ffmpeg -i "%%~pa%%~na.orig" -movflags faststart -acodec copy -vcodec copy "%%~pa%%~na.m4v" ) pause

When done and satisfied with the new files, you clean up the orig files.

Also, convert mkv to m4v, retain the same quality, and web optimize:
for /R %%a in (*.mkv) do ( ffmpeg -i "%%a" -metadata title="%%~na" -movflags faststart -vcodec copy -acodec copy "%%~pa%%~na.m4v" ) pause

I’m not sure why I have the -metadata title in there, it may not be necessary, but it works.
Note: I’ve had some mkv files that would not convert; they produce a very small m4v file or none at all.

I’ve only converted a few movies and tv shows retaining the originals just in case as I’m not 100% certain the above commands are a Good Thing. Didn’t do much searching but there’s probably a nice UI wrapper around ffmpeg that can do the web optimization without a transcode.

Used this site for ffpeg web optimize reference: http://rigor.com/blog/2016/01/optimizing-mp4-video-for-fast-streaming

I am using qtfaststart (my server is a headless CentOS7 box with 8TB of local disk) because it has the advantage of not producing a duplicate copy

github.com/danielgtaylor/qtfaststart

You can then just do a whole library with a single command like the one below and a good deal of waiting. I recommend on a Linux server running it inside a screen rackaid.com/blog/linux-screen-tutorial-and-how-to/ that way you can detach from the session and reattach later to check if it has completed.

find /home/shared/Movies -name *.mp4 -exec qtfaststart '{}' \;

One thing to bear in mind is that Plex seems to balloon it’s storage under /var as it rescans everything. Something I forgot about and I ran my server out of space on /var. Only to get a phone call early in the morning to tell my the Plex was down and my nephew was wanting to watch Topsy and Tim.

I have also been running a fine tooth comb through my libraries before I enable sync for the family. Turns out I have a handful of movies with somehow ended up with only ac3 5.1 surround sound tracks, which is another block on transcode free sync.

Lets hope that I am not going to have to hand edit android.xml every new version of the server. I guess the other option would be to write custom profiles for the specific android devices that use my server but I am not sure how one goes about that.

Grrrrrrrrrrrrrrr

Found another problem in this. If the video has a second audio track that is AC3, then the video gets queued for conversion. So I see this in the logs

May 24, 2016 21:34:31 [0x7f5effff1700] DEBUG - We're going to try to auto-select an audio stream for account 4381710.
May 24, 2016 21:34:31 [0x7f5effff1700] DEBUG - Selecting best audio stream for part ID 4575 (autoselect: 1 language: en)
May 24, 2016 21:34:31 [0x7f5effff1700] DEBUG - We're going to try to auto-select a subtitle.
May 24, 2016 21:34:31 [0x7f5effff1700] DEBUG - Audio Stream: 10407, Subtitle Stream: -1

Looks like it is trying to pick the best audio stream, which is AC3 5.1. Then a bit later it says

May 24, 2016 21:34:31 [0x7f5f14ecb700] DEBUG - [Now] User is XXXXXXX (ID: XXXXXX)
May 24, 2016 21:34:31 [0x7f5f14ecb700] DEBUG - [Now] Device is Android (My D5503).
May 24, 2016 21:34:31 [0x7f5f14ecb700] DEBUG - [Now] Profile is Android

It’s worked out my device is an Android one, then a little bit later

May 24, 2016 21:34:37 [0x7f5f013ff700] DEBUG - We're going to try to auto-select an audio stream for account XXXXXX.
May 24, 2016 21:34:37 [0x7f5f013ff700] DEBUG - Selecting best audio stream for part ID 4575 (autoselect: 1 language: en)
May 24, 2016 21:34:37 [0x7f5f013ff700] DEBUG - We're going to try to auto-select a subtitle.
May 24, 2016 21:34:37 [0x7f5f013ff700] DEBUG - Audio Stream: 10407, Subtitle Stream: -1
May 24, 2016 21:34:37 [0x7f5f013ff700] DEBUG - MDE: analyzing media item 4405
May 24, 2016 21:34:37 [0x7f5f013ff700] DEBUG - MDE: Frozen Fever (2015): no direct play video profile exists for http/mp4/h264/ac3
May 24, 2016 21:34:37 [0x7f5f013ff700] DEBUG - MDE: Frozen Fever (2015): selected media 0 / 4405

So it would appear that the server picks the best audio stream in the file for synchronization, then finds the device does not support it so tries to transcode it. Fortunately the transcode engine is smart enough to notice that an AAC stereo track actually exists in the file and just remuxes the file minus the AC3 5.1 track.

However this is then spewing files under /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Cache/Transcode which is likely to run the server out of space as /var is only 32GB in size.

Really, I mean REALLY which numpty thought that was a good approach???

This all needs reworking so that the profile of the device is taken into account when selecting an audio stream, and if you notice it has a supported audio stream especially if it is the first audio stream just copy the dam video file to the device.

It’s not like I have done something stupid and had the first audio track as AC3 and the second as AAC. No sir I have double checked and every last single video file on my server has a stereo AAC track first and if it existed on the original source a AC3 5.1 track second. Actually not strictly true there are some foreign language films with original soundtrack and a voice dubbed soundtrack second. Further some have AAC and AC3 5.1 of both, though you can literally count these on your hands.

I guess a workaround for now would be to put a symlink from /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Cache/Transcode to the main file system that has a lot more allocated space. But that is a nasty nasty hack and does not get around the fact that their is far more I/O going on in the server than is remotely necessary.

You make a good point. Let me bring this up with the devs. In the meantime, can you provide the xml for that video, just to make sure there isn’t something else causing the remux.

Here is the XML for the file. I was going to do a test where by I used ffmpeg to remux the file without the AC3 5.1 surround sound track and replace the existing version with that to see what would happen. However today for reasons I don’t understand the Plex app on my phone is crashing whenever I try and play back synced content. That includes both anamorphic and standard 1:1 pixel ratio video files. Oh joy of joy after I complete the week long journey of web optimizing everything in my library it now starts acting up like this :frowning: Was working fine yesterday.

As a general note I would say that the Plex devs are way to eager to drop down to transcoding stuff at the first hint of trouble. It’s kind of acceptable for live playback but for synchronization it is just the pits. I guess if you are only syncing one or two videos to a device then it’s not too bad. However if you are synchronizing whole seasons of TV shows at once then even with a high end server it is going to be way slower than just downloading, and unless you have a fetish with Apple devices (which servers you right in my view) then honking big local storage via the magic of 128GB and up microSD cards makes the idea of transcoding for space laughable.

So imagine my sister is going away on holiday and wants to sync some content to my nieces tablet to keep her occupied in car, at the airport etc. Currently she is into Topsy and Tim, so that’s 71 episodes at around 11 minutes each. Even if I could transcode 10 times faster than realtime (which is unlikely unless you have some honking GPU accelerated transcoding beast) it would still take around 90 minutes to transcode that lot, which is more time that it would take to just download even from a remote server via a VDSL2 connection. If you are connected via WiFi to the Plex server it is much worse.

<MediaContainer size="1" allowSync="1" identifier="com.plexapp.plugins.library" librarySectionID="1" librarySectionTitle="Movies" librarySectionUUID="21186756-9f44-4518-808f-48e2ea367b0a" mediaTagPrefix="/system/bundle/media/flags/" mediaTagVersion="1461360469">
<Video ratingKey="4683" key="/library/metadata/4683" guid="com.plexapp.agents.imdb://tt4007502?lang=en" librarySectionID="1" studio="Walt Disney Pictures" type="movie" title="Frozen Fever" contentRating="gb/U" summary="On Anna's birthday, Elsa and Kristoff are determined to give her the best celebration ever, but Elsa's icy powers may put more than just the party at risk." rating="7.1" year="2015" thumb="/library/metadata/4683/thumb/1464226283" art="/library/metadata/4683/art/1464226283" duration="457600" originallyAvailableAt="2015-03-27" addedAt="1451036388" updatedAt="1464226283" chapterSource="media">
<Media videoResolution="480" id="4405" duration="457600" bitrate="1868" width="720" height="456" aspectRatio="2.20" audioChannels="6" audioCodec="ac3" videoCodec="h264" container="mp4" videoFrameRate="PAL" optimizedForStreaming="1" has64bitOffsets="0" videoProfile="high">
<Part accessible="1" exists="1" id="4575" key="/library/parts/4575/file.mp4" duration="457600" file="/home/shared/Movies/Frozen Fever (2015).mp4" size="106822430" container="mp4" has64bitOffsets="0" optimizedForStreaming="1" videoProfile="high">
<Stream id="10406" streamType="1" default="1" codec="h264" index="0" bitrate="1316" anamorphic="1" bitDepth="8" cabac="1" chromaSubsampling="4:2:0" codecID="avc1" colorRange="tv" colorSpace="smpte170m" duration="457600" frameRate="25.000" frameRateMode="cfr" hasScalingMatrix="0" height="456" level="41" pixelAspectRatio="64:45" pixelFormat="yuv420p" profile="high" refFrames="4" scanType="progressive" streamIdentifier="1" width="720"/>
<Stream id="10407" streamType="2" selected="1" default="1" codec="aac" index="1" channels="2" bitrate="159" language="English" languageCode="eng" audioChannelLayout="stereo" bitrateMode="cbr" codecID="40" duration="457579" profile="lc" samplingRate="48000" streamIdentifier="2"/>
<Stream id="10408" streamType="2" default="1" codec="ac3" index="2" channels="6" bitrate="384" language="English" languageCode="eng" audioChannelLayout="5.1(side)" bitDepth="16" bitrateMode="cbr" codecID="ac-3" dialogNorm="-27" duration="457600" samplingRate="48000" streamIdentifier="3"/>
</Part>
</Media>
<Genre id="57" tag="Family" count="102"/>
<Genre id="34" tag="Adventure" count="118"/>
<Genre id="55" tag="Animation" count="76"/>
<Director id="382" tag="Chris Buck" count="2"/>
<Director id="383" tag="Jennifer Lee" count="2"/>
<Producer id="444" tag="Peter Del Vecho" count="2"/>
<Country id="9" tag="USA" count="382"/>
<Role id="385" tag="Kristen Bell" count="3" role="Anna (voice)"/>
<Role id="386" tag="Idina Menzel" count="2" role="Elsa (voice)"/>
<Role id="387" tag="Jonathan Groff" count="2" role="Kristoff (voice)"/>
<Role id="388" tag="Josh Gad" count="3" role="Olaf (voice)"/>
<Role id="392" tag="Chris Williams" count="2" role="Oaken (voice)"/>
<Role id="410" tag="Paul Briggs" count="2" role="Marshmallow (voice)"/>
<Extras size="0"></Extras>
</Video>
</MediaContainer>

@anon18523487 said:
You make a good point. Let me bring this up with the devs. In the meantime, can you provide the xml for that video, just to make sure there isn’t something else causing the remux.
I just confirmed with the devs that currently, the way sync works, only 1 video and 1 audio track can be in the file. So if you have a file with multiple audio tracks, even if the first is direct playable, it has to be remuxed. The devs are working on Sync v2 which will allow greater flexibility. I don’t have a timeframe on when it will be available, but work is actively being done on it.

Well at least that explains what I can only describe politely as stupid behaviour.

Do we have updates on the anamorphic issue. I can see a bunch of posts in various places (plex and none plex) from IanDBird on this issue. This one sort of explains perhaps why the playing works but sync wants the transcode.

You have to read that in combination with the following and read between the lines (it’s times like this I hate closed source software and I can’t just read the source)

Assuming the two are the same person, the IanDBird is a Plex dev, and the first post is talking about Plex. At this point I have to say why on earth does the Android app not just get the aspect ratio information for the video from the server when syncing a video and then store it locally for playback offline? Ok it’s a bit of a hack but it is infinitely preferable to transcoding every anamorphic video you wish to sync. Which for material sourced from DVD is basically everything.

If the github profile is accurate I could drive over to Edinburgh and demonstrate this to him in person given I am only 30 miles away :slight_smile:

Thanks for the pointer to qtfaststart @buzzme ; that tool rocks the casbah much easier and faster than doing an ffmpeg video and audio copy.

I’ll be replacing 50 movies with a web optimized counterpart, refreshing the library, and syncing some to to verify direct copy and not a transcode.

All appear to have one non-AC3 5.1 stereo surround track.

Will report findings later.

Update;
A few of the movies were directly available for download but most had to go through a quick [~5 min] audio conversion. Of the six movies I watched travelling from OGG to DTW all were awesome video and excellent audio. I can live with this.

FWIW I went back to the batch scripts on a home PC against the mounted NAS drives as the qtfaststart needed /tmp monitoring. This way I can pull out a set of movies and convert/check before doing the replacement.

Yeap I noticed that /tmp and /var/tmp can get filled up with temporary video files that are not deleted. However this only occured for me if the owner of the file is different from the user running qtfaststart. As I have used the owner of the file to indicate where the video came from (aka mine, sisters, brothers or mothers DVD collection) that was a very nasty surprise first time around.

Once I recovered from my server not working, I just su’ed from root through to their accounts on the server and added a -uid option to the find command so it only converted files for that user. As I had in the order of 4,000 video files to “optimize” (boxed sets really blows the number of video files up, especially kids TV shows) anything other than qtfaststart was going to be a nightmare.