Is it possible to do ffmpeg conversion of a stream in real time WITHOUT having to run special TVHeadEnd version or compile it myself?
Added by K Shea almost 10 years ago
To start with let me say that although I have managed to set up a Debian system and install TVHeadEnd (Build: 3.9.1879~g94ff39d~wheezy) from the repository, I am not familiar enough with Linux to be comfortable with compiling things myself - the few times I have attempted that I have always managed to break the system, usually so badly that I had to start over from scratch with a complete reinstall of the OS. So if what I want to do can't be done with a version of TVHeadEnd that can be obtained using apt-get then please just tell me that and I'll forget about it for now.
The issue is that I use a satellite TV card to receive and record certain programs which are saved to the hard drive as .ts files. In a couple of cases I need to post-process those files. With one provider, the issue is that they map their sound channels in a rather non-standard manner, so the sound doesn't play correctly in XBMC, but I can fix that using ffmpeg. In another case, the received signal just contains too much data and XBMC (or I should say the hardware) just can't handle it, so I have to use ffmpeg to slim the file down a bit.
In the first case, it only takes ffmpeg about five minutes to convert a one hour program, so I got to wondering if there is any way that TVHeadEnd can feed the signal received on certain specific channels to ffmpeg in real time, let ffmpeg do the conversion, and then use the processed stream. ffmpeg has no problem reading or creating a .ts file, it's just that I have no idea how you'd do this in real time, for two reasons:
First, I have no idea what the ffmpeg syntax would be to do this type of conversion in real time. In other words, I've only used ffmpeg to convert complete files, and while I have heard it can be used to process live streams, I have no clue as to how that is done.
Second, I have no idea if there is any provision for TVHeadEnd (specifically, a version that can be obtained from one of the repositories) to send the stream to ffmpeg in real time and then utilize the output to either send to a client (as a live stream) or save to a recording, as the case may be.
In other words I am wanting to use ffmpeg as a real-time filter on the received signal, but ONLY on certain specific channels. So my questions are, is that even possible with a standard TVHeadEnd version, and if so, are there any clear and simple instructions anywhere on how to do it?
In case I have not made it clear enough, if the only answer to that starts with the phrase "you need to compile..." then as far as I am concerned the answer is "no", so please just say that (if that's the case) and I'll forget about it and stick with converting the files as a post-process.
Replies (7)
RE: Is it possible to do ffmpeg conversion of a stream in real time WITHOUT having to run special TVHeadEnd version or compile it myself? - Added by wet willy almost 10 years ago
I am interested in doing the same, transcoding "on the fly" but my usage scenario would be that I want to use comskip ( http://forum.kodi.tv/showthread.php?tid=150084 ) in order to replace commercials with something different, or just "blank" it.
To answer your question, if I'm not mistaken I think you get transcoding support in the unstable repository. Then you can create streaming profiles based on video / audio stream or both.
Otherwise you always have the option of post recording processing: https://tvheadend.org/projects/tvheadend/wiki/Tvheadend_post_recording_scripts
RE: Is it possible to do ffmpeg conversion of a stream in real time WITHOUT having to run special TVHeadEnd version or compile it myself? - Added by Prof Yaffle almost 10 years ago
I'm not aware of a way internally to tvheadend to trigger transcoding via an external process - only the internal transcoding support.
I suppose you could have an external process running that looks for a file (i.e. a recording starting) and then starts to transcode it. I can imagine timing would be an issue, though... if it's faster than realtime, you'll have to buffer it in some way as it would run out of source material, and if it's slower than realtime then it'd be unwatchable (if that's the goal). I can image that trying to do comskip on a file that isn't yet complete would have similar challenges.
Let me check to see if anyone can confirm the 'PPA has transcoding enabled' angle. You shouldn't have to compile it yourself... if necessary, I'll build you a couple of debs that definitely have support built-in, and you can try those.
It really is easy to compile your own, though, so I'm happy to talk you through that if you're brave enough to try again.
(Regarding speed of conversion - converting audio is pretty quick, converting video typically isn't unless it's to something low quality, and re-arranging streams or re-packaging them into a different container is as fast as reading in a file from end to end).
RE: Is it possible to do ffmpeg conversion of a stream in real time WITHOUT having to run special TVHeadEnd version or compile it myself? - Added by wet willy almost 10 years ago
Prof Yaffle.
I saw you were active in the comskip thread.
Are you transcoding with comskip on live-tv? Do you know if it is possible?
RE: Is it possible to do ffmpeg conversion of a stream in real time WITHOUT having to run special TVHeadEnd version or compile it myself? - Added by Prof Yaffle almost 10 years ago
I only ever played with comskip for offline processing - and, to be honest, found it too unreliable for all but the most obvious of transitions (e.g. where on-screen DOGs fade out precisely when the adverts begin). If it's something I want to keep for any reason, I run it through avidemux and chop out the adverts by hand - you can always re-encode through Handbrake first if you need to increase the i-frame (i.e. whole frame and thus cut point) frequency.
I don't know if it's possible, to be honest. Firstly, the true live TV is a stream, so I don't know if it's ever stored as a buffered file to which you could point comskip; secondly, I seem to recall that comskip searches the whole file before it starts in anger (I may have imagined that, though), so I don't know what it would do with a recording file that's still of undefined duration; and thirdly, if it did work in real time, what would you insert instead of the adverts...
Transcoding straight live TV works okay if your server is fast enough and/or the target resolution is low enough - there are some quirks on which audio formats are supported, but that's a different debate.
Let me know if you want to try some debs, btw, and I'll email you a link. I'll build a couple of versions as 'unstable' means just that for some folks, so which version works best for you depends on your setup. Just tell me if you need 64 or 32 bit - they'd be Ubuntu debs, but I don't think it really makes any difference.
RE: Is it possible to do ffmpeg conversion of a stream in real time WITHOUT having to run special TVHeadEnd version or compile it myself? - Added by K Shea almost 10 years ago
Prof Yaffle wrote:
I'm not aware of a way internally to tvheadend to trigger transcoding via an external process - only the internal transcoding support.
Thank you for the reply. I don't even know how that works or what it is capable of. Is there any really good documentation on that, or an article explaining it somewhere?
I suppose you could have an external process running that looks for a file (i.e. a recording starting) and then starts to transcode it. I can imagine timing would be an issue, though... if it's faster than realtime, you'll have to buffer it in some way as it would run out of source material, and if it's slower than realtime then it'd be unwatchable (if that's the goal). I can image that trying to do comskip on a file that isn't yet complete would have similar challenges.
Okay. I thought perhaps that ffmpeg could handle streams in real time (as an example of the type of post that leads me to believe it may be possible, see this one posted just today: https://ffmpeg.org/pipermail/ffmpeg-user/2014-December/024563.html - I don't have the slightest clue what he's doing there, but it's stumbling across messages such as that one that led me to think that perhaps ffmpeg could be used in this way, but maybe I'm totally wrong).
Let me check to see if anyone can confirm the 'PPA has transcoding enabled' angle. You shouldn't have to compile it yourself... if necessary, I'll build you a couple of debs that definitely have support built-in, and you can try those.
It really is easy to compile your own, though, so I'm happy to talk you through that if you're brave enough to try again.
Well if this were exclusively my system I might be willing to try that, but in this case that's not exclusively my decision, and because it's already running an unstable version of TVHeadEnd and it's actually working (after something like four months of on and off batting our heads against a brick wall to try and get it to work reliably - I don't mean it took four months with TVHeadEnd, just to get a backend system working in general), now that it's actually working fairly reliably we are very reluctant to even do a normal upgrade on TVHeadEnd until we can figure out a good way to back up this system (can you tell that neither of us are really Linux guys?).
(Regarding speed of conversion - converting audio is pretty quick, converting video typically isn't unless it's to something low quality, and re-arranging streams or re-packaging them into a different container is as fast as reading in a file from end to end).
I realize that, which is why I was only curious whether this could be done when the audio stream rearrangement is necessary. Just so you understand, here is the real problem. The audio is sent in three separate streams that each contain two channels:
Stream 1: Left and Right Front audio
Stream 2: Center and Low frequency audio
Stream 3: Left and Right surround audio
There is also a fourth audio stream that contains alternate language/described video material but I don't need that.
Most of the dialog (speech) is on the center channel and NOT the left or right front channels. I found an article that shows how to get all these streams into a single ac3 stream using ffmpeg, mapping them to the proper channels in 5.1 format. If there is a way to do this in TVHeadEnd without using ffmpeg I would be happy to give it a try, but I don't think there is.
RE: Is it possible to do ffmpeg conversion of a stream in real time WITHOUT having to run special TVHeadEnd version or compile it myself? - Added by Prof Yaffle almost 10 years ago
Thinking about this... yes, it's possible... it's basically what VLC would do if it were acting as a re-broadcasting application. Timing remains an issue, but if you're just re-ordering streams then it should be perfectly possible in realtime.
Sooooo.... I don't know if trying o do it in tvh is the right approach, or whether the transcoding/stream filter functions would do it for you. If you want to try, you'll find some folks on #hts on freenode IRC who are using it. Alternatively, have a look at using VLC as a proxy - it wouldn't be elegant, but it may allow you to at least try what you need without delving into ffmpeg's somewhat arcane and obscure syntax. If it works, you could look to using ffmpeg natively, but VLC may be easier as a proof-of-concept.
EDIT
Re: compiling and installing - take a good backup of your config (use sudo and cp or rsync to keep all the owner/permissions - that way you can restore precisely) and you should be able to up/downgrade with no problems. I'll look to build a couple of debs in the next couple of days and post them here so you can try.
RE: Is it possible to do ffmpeg conversion of a stream in real time WITHOUT having to run special TVHeadEnd version or compile it myself? - Added by Prof Yaffle almost 10 years ago
@K Shea - see this thread: https://tvheadend.org/boards/5/topics/14344. You'll find a couple of deb builds if you want to try something that should have transcoding enabled.