Apple TV 4K DirectPlay HEVC

apple-tv

#1

Hello

Overview:

Plex Media Server: Version 1.9.6.4429
Plex App (Apple TV 4k): v.1.19 (73565)

Video File Informations:

My tvOS.xml (attachment)

Why is it not possible to Play this Video File via DirectPlay ?

Plex tries to transcode from HEVC to h.264… Lags Lags Lags…


#2

Here the tvOS.xml


#3

First, your file is an MKV. Apple TV only supports MP4. Second, your file has TrueHD audio in it. TrueHD is not a supported format by Apple TV. Finally, the subtitles are PGS. Text only subs are supported.

See this post - https://forums.plex.tv/discussion/comment/1561042/#Comment_1561042

Until Plex adds support for Direct Streaming (which will convert your MKV to MP4 on the fly in the correct streaming format), you have to follow very specific guidelines to get it to Direct Play your media.


#4

Was not aware that Plex didn’t support direct streaming with HEVC to remux a container - is there any reason for that?


#5

Any time media gets re-muxed (repackaged from one format to another) the Plex server has to use a live-streaming protocol to send it to the client – after all the file does not exist in the proper format and the server has to build it on-the-fly, so it can’t just send it to the client like it can with a properly formatted file. The Plex Media Server currently uses the HTTP Live Streaming (HLS) protocol to transport the file as it is built to the client.

Apple does not support HLS for HEVC, only Fragmented MP4, so it means a major re-write for the Plex devs. They are working on it, but we must be patient. In the meantime if you want to use HEVC material with Apple devices the media has to be formatted following very strict guidelines.


#6

@kclimie said:
Apple does not support HLS for HEVC, only Fragmented MP4

Apple does support HEVC on HLS protocol. It’s only the video stream which has to be fMP4 for HEVC. Before iOS11/tvOS11/ macOS10.13, a MPEG2-TS stream was previously carried via HLS for H264 videos.

See here for HLS examples of both MPEG2-TS (H264) and fMP4 (H264 and HEVC) : https://developer.apple.com/streaming/examples/


#7

How can I transcode this Videofile with ffmpeg in the correct “DirectPlay” Format (Without loss Quality)


#8

The best solution is…
Buy this one:

http://www.iflicksapp.com

and after that for the 4k releases use this one (beta):

https://rink.hockeyapp.net/apps/938b05d3c5075d5f6cf6401d287c96bf

It works pefect for me (preset “itunes kompatibel”)


#9

@Mojobaby said:
The best solution is…
Buy this one:

http://www.iflicksapp.com

and after that for the 4k releases use this one (beta):

https://rink.hockeyapp.net/apps/938b05d3c5075d5f6cf6401d287c96bf

It works pefect for me (preset “itunes kompatibel”)

just copy of Subler, but for money…


#10

@marceldev - Just use ffmpeg 3.4 (available here for ubuntu fans) to remux the hevc.mkv to a hevc.mp4 with the necessary hvc1 vtag. Quick FYI, remuxing is so much faster than transcoding, as it only changes the container instead of re-encoding everything.

CLI command is as follows (replace $PATH/$NAME with the appropriate path and filename)

ffmpeg -i "$PATH/$NAME.mkv" -codec copy -vtag hvc1 -map 0:0 -map 0:1 "$PATH/$NAME.mp4"

Source - AppleTV 4k DirectPlays all my remuxed hevc files from headless linux based plex media server. I use a bash script powered by mediainfo/ffmpeg to identify and automatically remux any HEVC mkv file it comes across.


#11

@vdkplexserver Thanks for sharing. Maybe this addresses my frustration with the state of Plex on Apple TV 4K. I’m a big Plex fan but currently moved to Infuse as the go-to media player: no need to update anything to play 4K HDR HEVC content directly…

Do you mind sharing your HEVC detection script? Thanks.


#12

@hanssep Can’t take the credit on that one. I got my inspiration from this script here. One downside is the bash script works well as long as there are no spaces in the filename when I input them from the variables $PATH/$NAME. If someone can help with that… please help! I am new at scripting so feel free to recommend any changes/additions.

ie.
Great.Donuts.S02E05./Great.Donuts.S02E05.mkv - this works
Great Donuts S02E05./Great Donuts S02E05.mkv - this doesn’t work as I can’t get bash to pass the variable of a path/filename with spaces correctly

This script is executed by deluge on the completion of a download.

#!/bin/sh

# Input Parameters
ARG_PATH="$3"
ARG_NAME="$2"
ARG_LABEL="N/A"
CONFIG_OUTPUT="$HOME/Media" # Filebot's final destination for the renamed file

# filebot used to extract any rar
filebot -extract "$ARG_PATH/$ARG_NAME/" --output "$ARG_PATH/$ARG_NAME/"

# Mediainfo needed to check if files are encoded in hevc
test=$(mediainfo "$ARG_PATH/$ARG_NAME.mkv" --Inform="Video;%Format%")
echo " $ARG_NAME is $(mediainfo "$ARG_PATH/$ARG_NAME/$ARG_NAME.mkv" --Inform="Video;%Format%")" >> ~/logs/scripts.log # log if file is recognized as HEVC

if [ "$test" = "HEVC" ]   # If the media file is x265 (HEVC)

then
# Run ffmpeg version 3.4 to remux only files detected as HEVC to the AppleTV required hvc1 rather than unsupported hev1
ffmpeg -i "$ARG_PATH/$ARG_NAME/$ARG_NAME.mkv" -codec copy -vtag hvc1 -map 0:0 -map 0:1 "$ARG_PATH/$ARG_NAME/$ARG_NAME.mp4"

# If it is HEVC also run this Filebot AMC script (ignore moving/renaming only *.mkv and ignore extract as files are already extracted above)
filebot -script fn:amc --output "$CONFIG_OUTPUT" --def ignore="[.](mkv)$" --def skipExtract=y --action duplicate --conflict skip -non-strict --log-file ~/amc.log --def unsorted=y music=y artwork=y excludeList=".excludes" ut_dir="$ARG_PATH" ut_kind="multi" ut_title="$ARG_NAME" ut_label="$ARG_LABEL" plex="" #enter your plex ip address and token to notify it to update

else

# If not is HEVC run this Filebot AMC script
filebot -script fn:amc --output "$CONFIG_OUTPUT" --def ignore="[.](mp4)$" --def skipExtract=y --action duplicate --conflict skip -non-strict --log-file ~/logs/amc.log --def unsorted=y music=y artwork=y excludeList=".excludes" ut_dir="$ARG_PATH" ut_kind="multi" ut_title="$ARG_NAME" ut_label="$ARG_LABEL" plex=""
fi

#13

@vdkplexserver said:
@marceldev - Just use ffmpeg 3.4 (available here for ubuntu fans) to remux the hevc.mkv to a hevc.mp4 with the necessary hvc1 vtag. Quick FYI, remuxing is so much faster than transcoding, as it only changes the container instead of re-encoding everything.

CLI command is as follows (replace $PATH/$NAME with the appropriate path and filename)

ffmpeg -i "$PATH/$NAME.mkv" -codec copy -vtag hvc1 -map 0:0 -map 0:1 "$PATH/$NAME.mp4"

Source - AppleTV 4k DirectPlays all my remuxed hevc files from headless linux based plex media server. I use a bash script powered by mediainfo/ffmpeg to identify and automatically remux any HEVC mkv file it comes across.

thanks a lot :wink:

Do you mind sharing your tvOS.xml with us ?


#14

I just use the standard tvOS.xml that came with the latest Plex Media Server.

<?xml version="1.0" encoding="utf-8"?>
<Client name="tvOS">
  <!-- Author: Plex Inc. -->
  <!-- This profile is used by A8-based tvOS devices -->
  <Settings>
    <Setting name="DirectPlayStreamSelection" value="true" />
    <Setting name="StreamUnselectedIncompatibleAudioStreams" value="true" />
  </Settings>
  <TranscodeTargets>
    <VideoProfile protocol="hls" container="mpegts" codec="h264" audioCodec="aac,eac3,ac3,mp3" context="streaming" />
    <MusicProfile container="mp3" codec="mp3" />
    <PhotoProfile container="jpeg" />
    <SubtitleProfile protocol="hls" container="webvtt" subtitleCodec="webvtt"/>
  </TranscodeTargets>
  <DirectPlayProfiles>
    <VideoProfile container="mp4" codec="h264,mpeg4" audioCodec="aac,ac3,eac3" subtitleCodec="mov_text,tx3g,ttxt,text" />
    <!-- Since tvOS may have issues direct playing mov/*/eac3 it has its own profile  -->
    <VideoProfile container="mov" codec="h264,mpeg4" audioCodec="aac,ac3" subtitleCodec="mov_text,tx3g,ttxt,text" />
    <!-- Allow Direct Play of HLS content  -->
    <VideoProfile protocol="hls" container="mpegts" codec="h264" audioCodec="aac" />
    <MusicProfile container="mp3" codec="mp3" />
    <MusicProfile container="mp4" codec="aac" />
    <PhotoProfile container="jpeg" />
  </DirectPlayProfiles>
  <CodecProfiles>
    <VideoCodec name="h264">
      <Limitations>
        <UpperBound name="video.width" value="1920" isRequired="true" />
        <UpperBound name="video.height" value="1080" isRequired="true" />
        <UpperBound name="video.bitDepth" value="8" />
      </Limitations>
    </VideoCodec>
    <VideoAudioCodec name="aac">
      <Limitations>
        <UpperBound name="audio.channels" value="2" />
      </Limitations>
    </VideoAudioCodec>
  </CodecProfiles>
</Client>

#15

@marceldev

I use a bash script powered by mediainfo/ffmpeg to identify and automatically remux any HEVC mkv file it comes across.
can you share your script?


#16

@b2un0 said:
@marceldev

I use a bash script powered by mediainfo/ffmpeg to identify and automatically remux any HEVC mkv file it comes across.
can you share your script?

The Bash Script is coded by: @vdkplexserver. He posted it already here.


#17

Find solution how to optimize remux size. MacX videoconverter has profile for ATV 4k. It’s allow to decrease size from 56Gb to 13Gb.


#18

I’ve using the command to make my film play direct but it is now playing in black and white. on my Apple TV 4K

ffmpeg -i "$PATH/$NAME.mkv" -codec copy -vtag hvc1 -map 0:0 -map 0:1 "$PATH/$NAME.mp4"


#19

@vdkplexserver If you quote and use {} around your variables, bash will be happy when expanding them…

[root@plex ~]# XXX='/mnt/storage/plex/movies/American Assassin (2017)/American Assassin (2017) 2160p.mp4'
[root@plex ~]# ls -l $XXX
ls: cannot access /mnt/storage/plex/movies/American: No such file or directory
ls: cannot access Assassin: No such file or directory
ls: cannot access (2017)/American: No such file or directory
ls: cannot access Assassin: No such file or directory
ls: cannot access (2017): No such file or directory
ls: cannot access 2160p.mp4: No such file or directory
[root@plex ~]# ls -l "${XXX}"
-rw-r--r--. 1 nobody nobody 19258671148 Jan  2 21:53 /mnt/storage/plex/movies/American Assassin (2017)/American Assassin (2017) 2160p.mp4

This is your script with the variables enclosed in curly braces and the if statement syntax fixed for bash interpreter. I have not tested as I don’t use filebot, or even have it installed. I did however validate the ffmpeg command does work perfectly.

#!/bin/sh

# Input Parameters
ARG_PATH="$3"
ARG_NAME="$2"
ARG_LABEL="N/A"
CONFIG_OUTPUT="${HOME}/Media" # Filebot's final destination for the renamed file

# filebot used to extract any rar
filebot -extract "${ARG_PATH}/${ARG_NAME}/" --output "${ARG_PATH}/${ARG_NAME}/"

# Mediainfo needed to check if files are encoded in hevc
test=$(mediainfo "${ARG_PATH}/${ARG_NAME}.mkv" --Inform="Video;%Format%")
echo " ${ARG_NAME} is $(mediainfo "${ARG_PATH}/${ARG_NAME}/${ARG_NAME}.mkv" --Inform="Video;%Format%")" >> ~/logs/scripts.log # log if file is recognized as HEVC

if [[ "${test}" == "HEVC" ]]   # If the media file is x265 (HEVC)
then
  # Run ffmpeg version 3.4 to remux only files detected as HEVC to the AppleTV required hvc1 rather than unsupported hev1
  ffmpeg -i "${ARG_PATH}/${ARG_NAME}/${ARG_NAME}.mkv" -codec copy -vtag hvc1 -map 0:0 -map 0:1 "${ARG_PATH}/${ARG_NAME}/${ARG_NAME}.mp4"

  # If it is HEVC also run this Filebot AMC script (ignore moving/renaming only *.mkv and ignore extract as files are already extracted above)
  filebot -script fn:amc --output "${CONFIG_OUTPUT}" --def ignore="[.](mkv)$" --def skipExtract=y --action duplicate --conflict skip -non-strict --log-file ~/amc.log --def unsorted=y music=y artwork=y excludeList=".excludes" ut_dir="${ARG_PATH}" ut_kind="multi" ut_title="${ARG_NAME}" ut_label="${ARG_LABEL}" plex="" #enter your plex ip address and token to notify it to update
else
  # If not is HEVC run this Filebot AMC script
  filebot -script fn:amc --output "${CONFIG_OUTPUT}" --def ignore="[.](mp4)$" --def skipExtract=y --action duplicate --conflict skip -non-strict --log-file ~/logs/amc.log --def unsorted=y music=y artwork=y excludeList=".excludes" ut_dir="${ARG_PATH}" ut_kind="multi" ut_title="${ARG_NAME}" ut_label="${ARG_LABEL}" plex=""
fi

#20

@vdkplexserver said:
@marceldev - Just use ffmpeg 3.4 (available here for ubuntu fans) to remux the hevc.mkv to a hevc.mp4 with the necessary hvc1 vtag. Quick FYI, remuxing is so much faster than transcoding, as it only changes the container instead of re-encoding everything.

CLI command is as follows (replace $PATH/$NAME with the appropriate path and filename)

ffmpeg -i "$PATH/$NAME.mkv" -codec copy -vtag hvc1 -map 0:0 -map 0:1 "$PATH/$NAME.mp4"

Source - AppleTV 4k DirectPlays all my remuxed hevc files from headless linux based plex media server. I use a bash script powered by mediainfo/ffmpeg to identify and automatically remux any HEVC mkv file it comes across.

This helped a lot! Thank you! Question, if i want to include a subtitle stream what would I have to add? From what I read the subtitles have to be in a certain format or else plex will start to transcode.