Forums » Tutorial and setups »
Recorded TV Transcoding?
Added by Keegan Neave almost 8 years ago
Howdo,
I've finally taken the plunge and tried TVHeadend again after having a few issues a few years back and I have to say I've been blown away!
I'm running on Ubuntu 16.04 with a build from GitHub so that I can have transcoding running so I can view TV externally via the internet.
I've managed to get transcoding working for live TV by having two users, one I use at home and one I use remotely, which I've applied different settings to.
One user is htsp for use at home and the other is webtv-h264-aac-matroska for using remotely. This works for live TV however it doesn't apply to recorded tv.
Is it possible to transcode recorded TV in the same way while streaming remotely or would I need something like Plex for that functionality?
If anyone could help sanity check my setup I'd appreciate it.
Thanks,
Keegan
Replies (9)
RE: Recorded TV Transcoding? - Added by Joe User almost 8 years ago
RE: Recorded TV Transcoding? - Added by Keegan Neave almost 8 years ago
Apologies, I'd searched but not found anything obvious!
Thanks for the info.
RE: Recorded TV Transcoding? - Added by Keegan Neave almost 8 years ago
I followed that post to here https://tvheadend.org/issues/3943
which led me to Lemka's build;
https://github.com/lekma/tvheadend/tree/codecs
Someone mentioned that it may be possible with this build but I can't get recorded TV transcoded still, anyone had any look with this or am I on the wrong track?
Thanks,
Keegan
RE: Recorded TV Transcoding? - Added by K Shea almost 8 years ago
I am not sure exactly what you want to do, but I guess my question would be whether you have ffmpeg installed, and if so, will it convert a recording to the format you want when used from the command line? If so, then you should be able to use some variation of the technique shown at https://freetoairamerica.wordpress.com/2015/01/07/how-to-play-video-recorded-from-high-bitrate-422-sources-on-low-power-systems/
Although, that won't do the conversion in real time. If you want that, it MAY be possible if you have a VERY fast system, but the problem is that converting video in real time requires a LOT of CPU power. You'd need to do something similar to what's shown at https://freetoairamerica.wordpress.com/2015/09/03/fixing-the-audio-on-live-tv-from-a-certain-network-which-shall-remain-nameless/ but since you're not attempting to do exactly the type of conversion shown there (which you will note only converts the audio stream, and only does a straight copy of the video which require little CPU power), you'd need to modify the call to ffmpeg to do the type of real-time conversion you want. BUT, and this is a big BUT, in most cases ffmpeg is too slow to do any significant real-time conversion of video. Even on a fairly modern desktop system, ffmpeg can take around twice the actual running length of the show or longer to do the conversion, which means that attempting a real time conversion is doomed to fail. This is especially true if you are attempting to compress the video in any way.
EDIT: If you have a good GPU in your system then what I said about ffmpeg being too slow may not apply, provided you set ffmpeg to use the GPU. However this is not exactly a straightforward process because the correct ffmpeg options to enable use of the GPU may vary depending on the exact hardware configuration. But if you set the options correctly, you may be able to achieve real-time video conversion.
Transcoding the recording after it's finished is easier, you can just make the call to ffmpeg from a post recording script - see https://tvheadend.org/projects/tvheadend/wiki/Tvheadend_post_recording_scripts (you invoke these by going to the Recordings tab, then under Digital Video Recorder Profiles you create a new profile with the same settings at the profile you'd normally use, which is probably the default profile, except you place the call to your script in the Post-Processor Command textbox. You then use that modified profile when setting up recordings, under the "DVR Configuration" setting).
Note that if you are trying to create a replacement recording that can be accessed as if it were the original, you can't just delete the original and the copy the replacement in using the same filename, because if the original disappears for even a fraction of a second TVHeadEnd will notice it is gone, and remove it from its index of available recordings. So, you have to "move" the completed converted file over the old one. You could use a script such as this as a post recording script - I'd place it in the TVHeadEnd (hts) user directory and make sure it's owned by the hts user and made executable; you could use use sudo su hts before creating the script, as I will mention again in a minute:
#!/bin/bash # Invoke using path/to/scriptname "%b" # Then $1=%b in this script # Extension of converted file must be same as original file (.ts)! cd /home/hts/recordings cp "$1" /home/hts/recbackups /usr/bin/ionice -c 3 /usr/bin/nice -n 20 /usr/local/bin/ffmpeg -loglevel quiet -i "$1" -c copy "converted-$1" &> /dev/null mv -f "converted-$1" "$1"
Before running it create a directory called /home/hts/recbackups (do this as the hts user, use sudo su hts before creating the directory) so it will have the correct permissions. This will contain the original unconverted recordings and you will probably want to set up a cron job to kill all the recordings in that directory every week or every morning, just not at any time when a conversion might be in progress. Also the ffmpeg options "-c:v copy -c:a copy -c:s copy" are just an example that pretty much do nothing, obviously you would replace these with the ffmpeg options that do the type of conversion you actually want. The path/to/scriptname "%b" is what you'd use as the call to the post recording script in your TVHeadEnd profile (the %b passes the path and filename of the recording). Also, check the path to ffmpeg in the script, it may be different on your system. Run which ffmpeg from a command prompt to find out where it is, and change the path in the script if necessary.
I hope this is at least somewhat helpful. This works in TVHeadEnd 4.0.9, maybe newer versions have a better way to do this but if so I am not aware of it.
RE: Recorded TV Transcoding? - Added by Keegan Neave almost 8 years ago
Hi,
My kit isn't that powerful but I can transcode live tv on the fly, I'll have a look at postprocessing for now though as doing it when needed may be the better option.
Thanks,
Keegan
RE: Recorded TV Transcoding? - Added by Tinho Chan almost 8 years ago
You can define different recording profiles (aka DVR profiles) under configuration. Each recording profile can be assigned a stream profile which you defined the transcoding. Then the recording profiles can be assigned to users. If only one recording profile is assigned to a user, then this will become the default recording for that user. Hope, this helps.
RE: Recorded TV Transcoding? - Added by Keegan Neave almost 8 years ago
Thanks for the tips but I was hoping I could transcode on the fly. For example, programmes are always recorded using PASS but when my user "mobile" wants to watch a recording I would like it to transcode in the same way it transcodes live TV.
It seems for now this isn't possible but may be implemented in the future. Thanks for the answers all.
RE: Recorded TV Transcoding? - Added by Peter Tofte almost 8 years ago
Keegan Neave wrote:
Howdo,
I've finally taken the plunge and tried TVHeadend again after having a few issues a few years back and I have to say I've been blown away!
I'm running on Ubuntu 16.04 with a build from GitHub so that I can have transcoding running so I can view TV externally via the internet.I've managed to get transcoding working for live TV by having two users, one I use at home and one I use remotely, which I've applied different settings to.
One user is htsp for use at home and the other is webtv-h264-aac-matroska for using remotely. This works for live TV however it doesn't apply to recorded tv.Is it possible to transcode recorded TV in the same way while streaming remotely or would I need something like Plex for that functionality?
If anyone could help sanity check my setup I'd appreciate it.
Thanks,
Keegan
Hi Keegan,
Strange, so the Stream Profiles does not apply for recordings...that is strange. In the Android TVHclient app there is some option to set streaming profiles for playing recordings, but it is mentioned as "obsolete" and suggests to use Server profiles - but obviously that is not the case you you cannot specify it on the server.
Sorry for hijacking your thread. But basically you are the first one that I have found that got transcoding live to work. I was hoping you could share some information about how you did it.
What hardware are you using? (Intel Core? Which Generation)
Vaapi, NVCEN or QSV?
Did you install Intel Media SDK (for QSV)?
I would be happy to assist making a guide, I think many could use one.
RE: Recorded TV Transcoding? - Added by Keegan Neave almost 8 years ago
Hi Peter,
All I did was compile from the master branch and I haven't knowingly installed or configured Vaapi, NVCEN or QSV. Sounds like I may have got lucky! I've started playing with Docker though so could always publish my Docker build file, it grabs all the things it needs to build from source, grabs the latest and builds it. I'll write up my notes and post a link to my blog here.
Regarding the hardware, it's actually pretty old kit. It's one of these boards with 4GB RAM, running Ubuntu 16.04 from a USB key:
https://www.asus.com/Motherboards/E35M1I_DELUXE/
It was originally purchased to run a media centre and was able to do bluray playback though. HTOP doesn't show it as working flat out, only around 50%, but I guess it may be using the GPU?
Happy to help in any way I can, just let me know what you need.