2015-06-30, 12:47
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)
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
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)
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.
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.