Recording of IPTV sources with ffmpeg
#1
Hi Forum!

This topic is only indirectly related to the IPTV Simple Client plugin but I thought it might best fit at this place. The plugin does a real good job showing IPTV source but I was missing a function to do occasional recording of IPTV streams listed in the m3u used by the plugin.

I wanted to perform these recordings on a windows machine. But basically this should be possible on any platform where ffmpeg is available.

The easiest way to perform such a recording is to make up a batch file containing the ffmpeg command line and parameters for source length and recording target. Then you will add this batch to the windows tasks to be executed at the correct time.

Here`s an example which can record a http stream when the server has no "special" requirements. (This is one line)
Code:
"(path to ffmpeg)\ffmpeg.exe" -y -i "(iptv url)" -c:v copy -c:a copy -t 00:00:30 "myrecording.ts" >"mylog.log" 2>&1
  • (path to ffmpeg)
    Please fill in the path were you installed ffmpeg.exe
  • (iptv url)
    Please fill in the the url of the desired channel which you want to record
  • -y
    This parameter let's ffmpeg overwrite the target without asking
  • -c:v copy -c:a copy
    These parameters copy an audio and a video channel of the source to the recording
  • -t 00:00:30
    This parameter sets the length of the recording (here: 30 seconds)
  • "myrecording.ts"
    The target of the recording. You can specify a path but I recommend that you use the extension ".ts".
  • >"mylog.log"
    Redirects ffmpegs output to a log file. This is useful for debugging.
  • 2>&1
    Redirects ffmpegs stderr output to the same log file.

For some sources however, you are required to add special headers to the stream requests. In that case you will find a pipe symbol as separator in the URL in the *.m3u. Kodi recognizes these headers and adds them to the request.

ffmpeg also allows the use of headers but (!) you have to include a CRLF in the parameter to let it be properly passed in the request. Adding a CRLF is a bit tedious in windows batch files.

Ok, the next example gets a bit more complicated.

Let`s assume you have the following (non-existing) url in your *.m3u

Code:
http://some.iptvserver.any/subfolder/master.m3u8|X-Forwarded-For=123.45.67.89

This tells kodi to use the url until the pipe symbol "|" and to add the rest to the http request header.

The resulting windows batch-file will look like this:
(the last lines starting from ffmeg.exe are actually a single line)
Code:
setlocal EnableDelayedExpansion
Set LF=^


for /f %%a in ('copy /z "%~f0" nul') do set "CR=%%a"
Set VNAME=myrecording.ts
Set LOGNAME=myrecording.log
Set DURATION=00:03:00
c:\tools\ffmpeg\ffmpeg.exe -y -headers "X-Forwarded-For: 123.45.67.89!CR!!LF!" -user_agent "Mozilla/5.0" -i "http://some.iptvserver.any/subfolder/master.m3u8" -c:v copy -c:a copy -t %DURATION% "%VNAME%" >"%LOGNAME%" 2>&1

I added another parameter to let ffmpeg to the request with a different user agent. If you don't need that then simply remove:
-user_agent "Mozilla/5.0"

Please note that the two empty lines after "Set LF" are important.

This batchfile should be ready to be called in the tasks. You should edit & test it interactively before. Also try out the task with a shorter recording first because there may be side-effects depending on the user-rights of the tasks (i.e. accessing network drives) or firewall software which might prompt you for the right of ffmpeg to access the internet.

If you take a look at the log file you will notice that some iptv sources offer many different streams (different bit rates, encodings ...). ffmpeg tries somehow to automatically select the "best" audio and video streams for recording. But you can also set specific streams to be selected. Search the log file for the text "Stream #". And you will find a listing of all streams and after that some info which were selected by ffmpeg.
If you want for example select the Stream #0:6 for Video and Stream #0:7 for Audio then add the following parameters to the ffmpeg command line: -map 0:6 -map 0:7


Using such batch files is better than nothing. Naturally you can continue from here and code a php script which reads the epg.xml and offers a simple web site to create/manage recording tasks...Extend the IPTV Simple Client plugin to call such a web service... and so on.
Reply
#2
Wow. And this is your first post?

+1
Reply
#3
Thank you!

Would be nice to hear if it is of some use for somebody. Personally, I already use some simple php web service to generate such batch files and the entrie for the task scheduler. If this will eventually get somehow releasable I will post it here.
Reply
#4
I would absolutely love to see this implemented into an extension of the TVGuide addon, where a user could select to either Watch or Record a program
Reply
#5
Rumor has it that someone added recording to a fork of IPTV Simple Client on github, but I don't have a link handy, nor have I tried it.
Reply
#6
(2015-07-23, 02:49)Ned Scott Wrote: Rumor has it that someone added recording to a fork of IPTV Simple Client on github, but I don't have a link handy, nor have I tried it.

I think it's this one
rkubera/pvr.iptvsimple
Reply
#7
I hope they will merge recordings with official one.
Reply
#8
I record IPTV streams like this:

ffmpeg -i \
url-goes-here \
-bsf:a aac_adtstoasc -t duration-in-seconds -c:v copy -c:a copy -loglevel error \
video-$(date +"%H-%M-%m-%d-%y").mp4

I run it on my router and its unbelievably lightweight.

Can someone with a little knowledge of Kodi comment if its possible to make PVR.IPTVsimple just add that line to cron at the appropriate time with the correct duration?

Thanks to all the devs for the hours you spend coding.
Reply
#9
(2015-08-23, 20:06)simphax Wrote:
(2015-07-23, 02:49)Ned Scott Wrote: Rumor has it that someone added recording to a fork of IPTV Simple Client on github, but I don't have a link handy, nor have I tried it.

I think it's this one
rkubera/pvr.iptvsimple

Has someone successfully managed to record something with this fork?

Or is there somewhere a support thread for this?
Reply
#10
(2015-08-23, 20:06)simphax Wrote:
(2015-07-23, 02:49)Ned Scott Wrote: Rumor has it that someone added recording to a fork of IPTV Simple Client on github, but I don't have a link handy, nor have I tried it.

I think it's this one
rkubera/pvr.iptvsimple

Simphax! Can You Share Your PVR Fork From Your Github Page With Us?
I Would Like To Test It But Do Not Know How To Compile! Wink
Reply
#11
I use rtmpdump to record feeds via PseudoTV Lives DVR feature (unpublished). Is there a benefit to using ffmpeg over rtmpdump?
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#12
(2015-12-16, 19:18)Lunatixz Wrote: I use rtmpdump to record feeds via PseudoTV Lives DVR feature (unpublished). Is there a benefit to using ffmpeg over rtmpdump?

Transcoding??
Reply
#13
what about compiling the pvr fork? that records by itself!
https://github.com/simphax/pvr.iptvsimple
Reply
#14
(2015-12-17, 19:08)03stevensmi Wrote: what about compiling the pvr fork? that records by itself!
https://github.com/simphax/pvr.iptvsimple

I'd like to see that!
Reply
#15
This is exactly what I was looking for.

Is there a simple pvr client that handles everything (show pvr list / play recordings / etc.) that I can use to override with my own record / stop recording functionality?
I use ffmpeg to do the recording but currently the recordings are outside of kodi, meaning I have to play them from outside of kodi.
Also, I currently use a key mapping to start and stop the recordings, and I want it to be part of the player skin.

Thanks,
Ofir
Reply

Logout Mark Read Team Forum Stats Members Help
Recording of IPTV sources with ffmpeg0