Help for manipulating the plex-media-server transcode on the raspberry pi

Overview

raspi-plex-transcode

Help for manipulating the plex-media-server transcode on the raspberry pi

Ensure hardware decoding works and your firmware is up to date

As mentioned in this forum post: https://forums.raspberrypi.com/viewtopic.php?t=262558

Hardware decoding of h264 will NOT WORK if the gpu memory is limited. I had added gpu=16 in my config.txt since I run my pi headless and thought it to be a waste of ram. Setting it to gpu=128 (the default) should be fine.

Brought to my attention by "fancybits" in the plex forums it is recommended to update the rpi kernel and firmware by running sudo rpi-update.

https://forums.plex.tv/t/hardware-transcoding-for-raspberry-pi-4-plex-media-server/538779/236

Compiling plex ffmpeg with custom options

Here is what I did to compile the plex-fork of ffmpeg:

cd /home/pi
cat /usr/lib/plexmediaserver/Resources/LICENSE | grep "Plex Transcoder"
# Copy the URL from the grep command and use it for the following wget
wget https://downloads.plex.tv/ffmpeg-source/plex-media-server-ffmpeg-gpl-62cc2bc17d.tar.gz
tar -xvf plex-media-server-ffmpeg-gpl-*.tar.gz
rm plex-media-server-ffmpeg-gpl-*.tar.gz
mv plex-media-server-ffmpeg-gpl-* plex-media-server-ffmpeg
cd plex-media-server-ffmpeg
sudo apt install libass-dev libaom-dev libxvidcore-dev libvorbis-dev libv4l-dev libx265-dev libx264-dev libwebp-dev libspeex-dev librtmp-dev libopus-dev libmp3lame-dev libdav1d-dev libopencore-amrnb-dev libopencore-amrwb-dev libsnappy-dev libsoxr-dev libssh-dev libxml2-dev libomxil-bellagio-dev
# If you want to apply patches or make changes to the ffmpeg source, do it here
./configure --extra-cflags="-I/usr/local/include" --extra-ldflags="-L/usr/local/lib" --extra-libs="-lpthread -lm -latomic" --enable-gmp --enable-gpl --enable-libaom --enable-libass --enable-libdav1d --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libssh --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-mmal --enable-omx --enable-nonfree --enable-version3 --target-os=linux --enable-pthreads --enable-openssl --enable-hardcoded-tables
make -j5
sudo usermod -a -G video plex

Hooking into the plex transcode process

In order to use a different (hardware-)encoder I wrote a small shell script that can be put in place like this:

cd /home/pi/plex-media-server-ffmpeg
wget https://github.com/ForsakenNGS/raspi-plex-transcode/raw/main/ffmpeg-transcode
wget https://github.com/ForsakenNGS/raspi-plex-transcode/raw/main/ffmpeg-transcode.yaml
# Edit the configuration file to your needs
chmod +x ffmpeg-transcode
cd /usr/lib/plexmediaserver/
sudo mv 'Plex Transcoder' 'Plex Transcoder Backup'
sudo ln -s /home/pi/plex-media-server-ffmpeg/ffmpeg-transcode 'Plex Transcoder'

This will replace the output video encoder with the one defined in the configuration. (by default h264_v4l2m2m) Also it increases the buffer size (double of default) and allows to change the segment duration of the chunks that are being rendered.

Configuration

The wrapper ffmpeg-transcode will replace the plex parameters according to the configuration file ffmpeg-transcode.yaml. An example can be found in this repository as instructed to download above. The following options are available:

executable (required)

Defines the ffmpeg executable that is invoked with the altered parameters. The default is /home/pi/plex-media-server-ffmpeg/ffmpeg

profiles (required)

A list of profiles indexed by name that are being used to adjust the plex parameters. Each profile requires an input and output key which defines overrides for the default parameters. An example as included in the default configuration:

'profiles':
  'default':
    'input':
    'output':
      '-codec:0': 'h264_v4l2m2m'
      '-crf:0': '10'
      '-minrate:0': '1M'
      '-maxrate:0': '5M'
      '-bufsize:0': '10M'
      '-seg_duration': '2'
  • Everything in the input section applies to the input stream (everything before the -i filename parameter).
  • Everything in the output section applies to the output stream (everything after the -i filename parameter).
  • Any valid ffmpeg parameter can be used.
  • Repetitions of the same parameter are currently not supported.

profile_select

Controls when certain profiles are used. The following child-keys are available:

  • default Defines a default profile which is used if no other rule matches. Example:
'profile_select':
  'default': 'default'
  • by_argument Defines conditions which will trigger a certain profile to be used.
    • argSection One of either input or output. This will decide whether the script will check the given argument for the input or the output stream.
    • argName The name of the argument as supplied by plex. e.g.: -codec:0 will check the video codec, -i will check the input file.
    • type What kind of condition will be checked. Available are:
      • exact Matches if the given value parameter matches the value of the specified argument.
      • regex Matches if the regex supplied within the value parameter matches the value of the specified argument.
      • present Matches if the specified argument is present.
      • missing Matches if the specified argument is missing.
    • ignorecase Currently only used for the regex type. Makes the regular expression case insensitive.
    • value The value used for matching with the exact and regex types.
    • profile The target profile as defined in the profiles section that is used if the condition matches.
    • priority A priority that is used when multiple conditions match. Higher is more important. If omitted the default priority of 0 is used.

Example that will match if the path or filename contain the string anime somewhere:

'profile_select':
  'by_argument':
    -
      'argSection': 'input'
      'argName': '-i'
      'type': 'regex'
      'ignorecase': true
      'value': '.*anime.*'
      'profile': 'anime'
You might also like...
Webcam Indicator is an application to recieve and send messages from your own Webcam Server.
Webcam Indicator is an application to recieve and send messages from your own Webcam Server.

Welcome to Webcam Indicator 👋 Webcam Indicator is an application to recieve and send messages from your own Webcam Server. 🏠 Homepage Prerequisites

Plex-recommender - Get movie recommendations based on your current PleX library

plex-recommender Description: Get movie/tv recommendations based on your current

google-resumable-media Apache-2google-resumable-media (🥉28 · ⭐ 27) - Utilities for Google Media Downloads and Resumable.. Apache-2

google-resumable-media Utilities for Google Media Downloads and Resumable Uploads See the docs for examples and usage. Experimental asyncio Support Wh

Automatically creates genre collections for your Plex media
Automatically creates genre collections for your Plex media

Plex Auto Genres Plex Auto Genres is a simple script that will add genre collection tags to your media making it much easier to search for genre speci

Synchronize a local directory of songs' (MP3, MP4) metadata (genre, ratings) and playlists with a Plex server.

PlexMusicSync Synchronize a local directory of songs' (MP3, MP4) metadata (genre, ratings) and playlists (m3u, m3u8) with a Plex server. The song file

Control-Raspberry-Pi-Robot-using-Hand-Gestures - A 4WD Robot car based on Raspberry Pi that controlled by hand gestures(using openCV and mediapipe)
A pure python media player that can be used in AI media API development.

A pure python media player that can be used in AI media API development.

A web service for scanning media hosted by a Matrix media repository

Matrix Content Scanner A web service for scanning media hosted by a Matrix media repository Installation TODO Development In a virtual environment wit

The DL Streamer Pipeline Zoo is a catalog of optimized media and media analytics pipelines.

The DL Streamer Pipeline Zoo is a catalog of optimized media and media analytics pipelines. It includes tools for downloading pipelines and their dependencies and tools for measuring their performace.

A Celery application to collect data, download media and extract information from social media APIs

Project IBEX A Celery application to collect data, download media and extract information from social media APIs. Requirements You must have a Redis D

Python bindings for the Plex API.

Python-PlexAPI Overview Unofficial Python bindings for the Plex API. Our goal is to match all capabilities of the official Plex Web Client. A few of t

This is the new and improved Plex Automatic Pre-roll script with a GUI
This is the new and improved Plex Automatic Pre-roll script with a GUI

Plex-Automatic-Pre-roll-GUI This is the new and improved Plex Automatic Pre-roll script with a GUI! It should be stable but if you find a bug please l

Discord Rich Presence implementation for Plex.
Discord Rich Presence implementation for Plex.

Perplex Perplex is a Discord Rich Presence implementation for Plex. Features Modern and beautiful Rich Presence for both movies and TV shows The Movie

This is the new and improved Plex Automatic Pre-roll script with a GUI
This is the new and improved Plex Automatic Pre-roll script with a GUI

Rollarr This is the new and improved Automatic Pre-roll script with a GUI for Plex now called Rollarr! It should be stable but if you find a bug pleas

PlexAutoSkip - Automatically skip content in Plex

PlexAutoSkip Automatically skip tagged content in Plex A background python scrip

Throttle rTorrent on Plex stream Start/Stop

Dependencies Python 3.6+ Tautulli Script Setup Edit rtorrent_throttle.py and set rTorrent username, password and RPC2 url. Tautulli Setup Commum Scrip

Throttle qBittorrent on Plex stream Start/Stop

Dependencies Python 3.6+ 'qbittorrent-api' Python Library Tautulli Script Setup Edit qbittorrent_throttle.py and set qBittorrent username, password an

This will help to read QR codes using Raspberry Pi and Pi Camera

Raspberry-Pi-Generate-and-Read-QR-code This will help to read QR codes using Raspberry Pi and Pi Camera Install the required libraries first in your T

Management commands to help backup and restore your project database and media files

Django Database Backup This Django application provides management commands to help backup and restore your project database and media files with vari

Comments
  • Improve profile definitions/handling

    Improve profile definitions/handling

    Right now only a single defined profile will be used at the same time, which has quite a few limitations. A few ideas for improving that:

    • Split profiles into input- and output-profiles
    • Add profile-groups and allow multiple profiles to be applied at once. (Only one profile per group)
    enhancement help wanted 
    opened by ForsakenNGS 0
  • Not all dependencies are installed automatically

    Not all dependencies are installed automatically

    Hey there everything went smooth until I tried to run compile.sh where at first during the -configure prompt I got the following error: libvpx enabled but no supported decoders found Doing apt install libvpx-dev fixed it but im getting another error: ERROR: mmal not found Im assuming installing it manually will fix it. Just wanted to point out that these packages are not installed automatically.

    I'll edit this post if I find any more packages that need to manually be installed.

    Edit: Seems raspbian has an apt package that includes ffmpeg with hardware transcoding support, would it be possible to use this instead of compiling ffmpeg again?

    opened by Tooloco 5
  • Problem with h264_v4l2m2m

    Problem with h264_v4l2m2m

    In some cases (mainly observed when streaming to one of my tablets) plex will set the option -segment_format matroska which will cause the encoding to fail if h264_v4l2m2m is used instead of libx264.

    Commandline example:

    ffmpeg -codec:0 hevc -analyzeduration 20000000 -probesize 20000000 -i '/path/to/my/video.mkv' 
      -filter_complex '[0:0]scale=w=1920:h=1080:force_divisible_by=4[0];[0]format=pix_fmts=yuv420p|nv12[1]' -map '[1]' -metadata:s:0 language=jpn 
      -codec:0 h264_v4l2m2m -crf:0 10 -maxrate:0 50M -bufsize:0 10M -r:0 23.809999999999999 -preset:0 veryfast -level:0 4.0 
      -x264opts:0 subme=0:me_range=4:rc_lookahead=10:me=dia:no_chroma_me:8x8dct=0:partitions=none 
      -force_key_frames:0 'expr:gte(t,n_forced*1)' -map 0:1 -metadata:s:1 language=jpn -codec:1 copy -copypriorss:1 0 
      -segment_format matroska -f ssegment -individual_header_trailer 0 -flags +global_header -segment_header_filename header 
      -segment_time 1 -segment_start_number 0 -segment_copyts 1 -segment_time_delta 0.0625 
      -segment_list 'http://127.0.0.1:32400/video/:/transcode/session/somehash-com-plexapp-android/sessionid/manifest?X-Plex-Http-Pipeline=infinite' 
      -segment_list_type csv -segment_list_size 5 -segment_list_separate_stream_times 1 -segment_list_unfinished 1 
      -segment_format_options output_ts_offset=10 -max_delay 5000000 -avoid_negative_ts disabled -map_metadata:g -1 
      -map_metadata:c -1 -map_chapters -1 media-%05d.ts -start_at_zero -copyts -vsync cfr -y -nostats -loglevel_plex error 
      -progressurl http://127.0.0.1:32400/video/:/transcode/session/somehash-com-plexapp-android/sessionid/progress
    

    The output is the following:

    [h264_v4l2m2m @ 0x2344880] Using device /dev/video11
    [h264_v4l2m2m @ 0x2344880] driver 'bcm2835-codec' on card 'bcm2835-codec-encode' in mplane mode
    [h264_v4l2m2m @ 0x2344880] requesting formats: output=YU12 capture=H264
    [h264_v4l2m2m @ 0x2344880] Failed to set gop size: Invalid argument
    [stream_segment,ssegment @ 0x38bf3d0] Opening 'header' for writing
    Output #0, stream_segment,ssegment, to 'media-%05d.ts':
      Metadata:
        encoder         : Lavf58.65.101
        Stream #0:0(jpn): Video: h264, yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 23.81 fps, 1k tbn (default)
        Metadata:
          encoder         : Lavc58.117.101 h264_v4l2m2m
        Stream #0:1(jpn): Audio: aac (LC), 48000 Hz, stereo, fltp (default)
        Metadata:
          _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
          title           : Japanese (FUNIMATION)
          BPS             : 256000
          DURATION        : 00:23:40.117000000
          NUMBER_OF_FRAMES: 66568
          NUMBER_OF_BYTES : 45443755
          _STATISTICS_WRITING_APP: mkvmerge v61.0.0 ('So') 64-bit
          _STATISTICS_WRITING_DATE_UTC: 2021-12-20 12:39:52
    av_interleaved_write_frame(): Invalid data found when processing input
    Error writing trailer of media-%05d.ts: Invalid data found when processing input
    frame=    2 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.00 bitrate=N/A speed=   0x    
    video:0kB audio:16kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
    Conversion failed!
    

    When running the exact same commandline and only swapping out h264_v4l2m2m for libx264 everything works fine.

    bug help wanted 
    opened by ForsakenNGS 4
Owner
null
Your self hosted Youtube media server

The Tube Archivist Your self hosted Youtube media server Core functionality Subscribe to your favourite Youtube channels Download Videos using yt-dlp

Simon 2.1k Dec 31, 2022
Streams video from raspberry pi to desktop T1 - Recognizes Faces on client T2

VideoStreamingServer Completed: Streams video from raspberry pi to desktop T1 - Recognizes Faces on client T2 In progress: Change the transmission Pro

null 1 Dec 6, 2021
A Python media index

pyvideo https://pyvideo.org is simply an index of Python-related media records. The raw data being used here comes out of the pyvideo/data repo. Befor

pyvideo 235 Dec 24, 2022
Python Script for Streaming YouTube Videos in VLC Media Player.

Short Description Use this Simple Script to stream YouTube Video to VLC

Sijey 6 May 27, 2021
Media player custom component which works with MQTT.

Media player custom component which works with MQTT. I designed this to specifically work with a ESP32 which i used to control a speakercraft amp.

null 2 Feb 10, 2022
720p FPGA Media Player (RISC-V + Motion JPEG + SD + HDMI on an Artix 7)

FPGA Media Player This project is a FPGA based media player which is capable of playing Motion JPEG encoded video over HDMI or VGA on commonly availab

null 179 Dec 2, 2022
Text2Video's purpose is to help people create videos quickly and easily by simply typing out the video’s script and a description of images to include in the video.

Text2Video Text2Video's purpose is to help people create videos quickly and easily by simply typing out the video’s script and a description of images

Josh Chen 19 Nov 22, 2022
This will help you study and avoid moving mouse coz u dont need mouse for watching youtube videos

This will help you study and avoid moving mouse coz u dont need mouse for watching youtube videos. Neither u need it for pdfs just use your keyboard

KorryKatti 5 Jan 7, 2022
Your own movie streaming service. Easy to install, easy to use. Download, manage and watch your favorite movies conveniently from your browser or phone. Install it on your server, access it anywhere and enjoy.

Vigilio Your own movie streaming service. Easy to install, easy to use. Download, manage and watch your favorite movies conveniently from your browser

Tugcan Olgun 141 Jan 6, 2023
Jio TV Server - Watch TV right from your laptop

Jio-PyServer Jio TV - Python Server Watch TV right from your laptop! Requirements: Python 3.X Internet Access A Jio Account Known Issues: Channel Stre

Elvis Tony 11 Apr 5, 2022