Project

General

Profile

Transcoding Streams / Recordings

Added by Jon _ over 7 years ago

Hi

I'm investigating how I can use cheap android devices with Kodi as a frontend for both media and TV / Recordings.

The main problem is that they don't have enough horsepower to do on the fly deinterlacing, and don't have hardware accelerated MP2 - usually just MP4.

Live TV I've created a streaming profile that transcodes on the fly - this works fine.
For recordings, the current versions of TVH won't transcode on playback, only on record.

My concern is that if I'm transcoding on record, I could end up in a situation where 4-5 items are recording at once, and the server CPU runs out of capacity, which I would imagine would end up with frame drops / corruption etc which I really don't want.

Any suggestions? I know I could do post processing of the files once recording has finished, but this would likely cause problems watching items that are currently recording (both from a playback being bad and the file being replaced halfway through playback point of view!)

Cheers

Jon


Replies (10)

RE: Transcoding Streams / Recordings - Added by Robert Cameron over 7 years ago

There are a couple of options. One is to do no transcoding, and choose inexpensive SBCs that have both MPEG-2 and H.264 hardware decoding. All Raspberry Pis include H.264 hardware decoding, and you can purchase a license key to enable hardware decoding of MPEG-2 for £2–3 GBP. Stay away from Amlogic chips, as their MPEG-2 hardware support has known bugs that they refuse to address/fix. AllWinner has their own proprietary VPU that handles hardware decoding, but it's primarily for Android and Linux sources are reverse-engineered and not quite on par with the closed-blob version. (I personally have 5 RPis, a mix of Zero Ws, 2s and a 3, all working well with HD MPEG-2 over 802.11n 2.4GHz.)

Another option is to record with a pass profile, but then run a script on your Tvheadend server that checks for recorded programs, and when it finds them it can convert them from MPEG-2 to H.264. You can even `nice` the script to ensure that it has low priority and doesn't interfere with other tasks/jobs on the server. (You'll also want the script to update the DVR log files to point to the newly transcoded file, otherwise the clients will still be served the unprocessed file.)

A third option (that works nicely with the previous one) is to have a streaming profile for your low-powered clients to transcode the stream on the fly to them. If you are going to be doing on-the-fly transcoding, you are probably better off getting a dedicated GPU for your Tvheadend server. While ffmpeg supports VA-API hardware encoding, Tvheadend cannot use it because of the way that arguments and parameters are passed. (VA-API is used by both Intel and AMD/Radeon graphics.) Your best option is Nvidia, as `nvenc` is supported by ffmpeg and Tvheadend for transcoding. Tvheadend can make use of Intel's QuickSync Video (QSV), but it is quite difficult to get properly set up on Linux as it requires a specific distro and/or kernel version. Personally I am not sure what the status of support for AMD's Video Coding Engine (VCE) is, or what level of VDPAU support is offered for using open source Nvidia drivers. For the most part, 2-4 simultaneous transcodes should be easily within the realm of reality when using hardware accelerated transcoding; if using software only you will probably start to notice slowdowns with as few as 2.

As far as your concern for doing the transcode as a post-process: if you use a separate script to handle your transcoding and Tvheadend's post-processing script functionality, you can let Tvheadend serve the original file to the clients while you are transcoding, and only after it successfully completed would you modify the DVR log to point to the new transcoded file.

RE: Transcoding Streams / Recordings - Added by ullix tv over 7 years ago

I am using this device "Docooler MX9 Pro" (56€ at Amazon https://www.amazon.de/gp/product/B0711V847D/ref=od_aui_detailpages00?ie=UTF8&psc=1 ) as Kodi frontend, and I am quite pleased with the performance. It replaced an FireTV, which bugged me with Amazon's attempt to make installation and use of Kodi so difficult.

The Docooler is connected by ethernet; WLAN in my situation is sometimes too slow. It does hardware accelerate (set within Kodi) on MPEG2 and specs say it does it even for up to 4K video (not tested) with other codecs. I got good performance with mp4 and mkv container. I keep the original mpeg-ts files until played; for storage I compress using handbrake with x264 and mkv container.

The included remote control is sub-par. I use this air mouse https://www.amazon.de/gp/product/B01AK2GV2I/ref=oh_aui_detailpage_o07_s00?ie=UTF8&psc=1 which is not perfect but ok, and even makes the TV remote obsolete.

RE: Transcoding Streams / Recordings - Added by Jon _ over 7 years ago

Hi

I had another rethink about my requirements - ideally I want netflix and prime TV on the unit, which limits the options a bit - I can either wait for the inputstream decoding of either, which I have a feeling will get stamped on when it becomes more well used due to copyright concerns from the publishers, or try and get an android box that supports both natively.. I've ordered a shieldTV to test as it's supposed to be able to cope with the deinterlacing - I'll see how it works out...

Jon

RE: Transcoding Streams / Recordings - Added by Paweł Drobek over 7 years ago

Hi guys

Please can anyone describe how to encode all tv streams no matter how currently encoded to codec which is used in this movie?

http://samplemedia.linaro.org/H264/big_buck_bunny_1080p_H264_AAC_25fps_7200K.MP4

I have compile kodi on cubieboard 2 (allwinner soc hw vdpau enabled by opensource community) but im unable to watch anything because kernel dump

RE: Transcoding Streams / Recordings - Added by saen acro over 7 years ago

how about this put in post-processor command

ffmpeg -i %f -b 1550k -bt 1792k -vcodec libx264 -pass 1 -vpre fastfirstpass -an -threads 2 %b.mp4 && ffmpeg -y -i %f -b 1550k -bt 1792k -vcodec libx264 -pass 2 -vpre hq -acodec libfaac -threads 2 %b.mp4

RE: Transcoding Streams / Recordings - Added by Paweł Drobek over 7 years ago

im noobie with tvheadend, can you describe where should i put this command?

RE: Transcoding Streams / Recordings - Added by saen acro over 7 years ago

Settings > recording
create new profile "transcoding"
fill it as you wish
and use this profile when recording

value -threads 2 can be changed to number of logical treads/cores of your cpu but -1
ex. 8 core cpu use value 8-1 7 to have some response for rest processes, if more recording in same time reduce it
this is post processing script so will start transcode after recording finish

RE: Transcoding Streams / Recordings - Added by Paweł Drobek over 7 years ago

thank you, i will check this option in near future :-) i will give feedback as soon as possible

RE: Transcoding Streams / Recordings - Added by Paweł Drobek over 7 years ago

sorry for another noob question. I guess "settings > recording" is for PVR yes? I would like to transcode stream which i could watch on other machine "on-the-fly" Post processor command will produce file on my storage which i could watch later yes?

RE: Transcoding Streams / Recordings - Added by saen acro over 7 years ago

Next to PVR profiles have "live" stream transcoding options

    (1-10/10)