Piping mkv file help
Added by Lisa White over 4 years ago
Hello everyone and I hope all is well during this corona pandemic. I have been messing around with tvheadend and was wondering if I can pipe my local movies to play on tvheadend. All of my movie collections are stored on the same linux computer as tvheadend. Is there a way that I can pipe the mkv file to a mux so it will play through tvheaend?
Thanks
Lisa
Replies (27)
RE: Piping mkv file help - Added by Lisa White over 4 years ago
I forgot to add that this is my pipe command (pipe:///usr/bin/ffmpeg -loglevel fatal -i file://home/lisa/movie/friends.mkv -vcodec copy -acodec copy -metadata service_provider=STRING -metadata service_name=STRING -f mpegts -tune zerolatency pipe:1) I get error message of: stdin pipe 52 unexpectedly closed: No data
Any suggestions?
Thanks,
Lisa
RE: Piping mkv file help - Added by Lisa White over 4 years ago
Hi, and thanks for your responses saen acro but I am unclear of your answer. My video files are stored on my server. Would I make a m3u list as used for iptv and direct the pipe line to where the file is stored? Could you help and provide an example? I have been messing around trying to make this work and I keep getting the errors.
Thanks
lisa
RE: Piping mkv file help - Added by saen acro over 4 years ago
make playlist with pipe url to files
then add playlist as auto network
all movies will be as channel's.
RE: Piping mkv file help - Added by Lisa White over 4 years ago
Hi sean acro. Can you check my playlist to see if I am on the right track? My tvheadend is running alongside ubuntu. Thanks You
#EXTM3U
#EXTINF:-1 tvg-ID="" tvg-name="FRIENDS SEASON 10" tvg-logo="file://home/lisa/friends.png" group-title="FRIENDS"
pipe:///usr/bin/ffmpeg -loglevel fatal -i file://home/lisa/FRIENDS-s10.mkv -vcodec copy -acodec copy -metadata service_provider=STRING -metadata service_name=STRING -f mpegts -tune zerolatency pipe:1
RE: Piping mkv file help - Added by Hiro Protagonist over 4 years ago
You can import movies etc into TVH as recordings easily.
Let me know if you want to do this & I'll post a script.
RE: Piping mkv file help - Added by saen acro over 4 years ago
Metadata is to be filled.
service_provider=Lisa's collection FRIENDS service_name=Friends - S10E1
so to see in services relevant information.
Hiro Protagonist wrote:
You can import movies etc into TVH as recordings easily.
Let me know if you want to do this & I'll post a script.
Do it
Or it can be don by UPnP service of your NAS.
RE: Piping mkv file help - Added by Lisa White over 4 years ago
Thanks for the information but I still cannot get this thing going using the pipe command. The idea of copying the movie file into tvheadend sounds interesting. Could it be possible to map the mkv file into the channel line up? This would be a great feature to have because I have the seasons merged together as one and It would be like having a video on demand.
Thanks Guys for the Help!!
Lisa
RE: Piping mkv file help - Added by Hiro Protagonist over 4 years ago
Script to import files as recordings into TVHeadend.
This can be used to import arbitrary files, or to transfer recordings from one TVH to another,
in which case the log file can also be imported by using the -l option. The UUIDs are stripped from
the input logfile.
The -d option will pull just the 'channel', 'start', 'stop', 'subtitle' and 'description' fields from a supplied logfile.
Without -d or -l a default logfile will be generated.
Uses curl and ffprobe.
ffprobe used to determine duration. Could be removed if you wanted to manually input duration.
Looks in LOGPATH for logfiles if the provided file can't be found.
Looks for the title in the input file path [ /path/to/file/name/file.mkv will use "name" as the title.
You may want to change this or add manual input for the title.
One other caution - make sure start & stop times are in the past, otherwise a recording timer may be created.
#!/bin/bash # # Import recordings into TVHeadend # Assumes "Make subdirectories per title" is enabled, - if this is not the # case, the title will have to be extracted from the filename. # # Not tested on files containing spaces, so make sure your filenames # don't have any! # # Change the following as needed for your setup USER=username PASS=secret LOGPATH=~/.hts/tvheadend/dvr/log JSONFILE="/tmp/import.json" INFILE=$1 filetest () { if [ ! -e $1 ] ; then echo "$1 does not exist!" exit 1 fi } logtest () { if [ ! -e $1 ] ; then echo "$1 does not exist!" exit 1 fi } if [ $INFILE != "-h" ] ; then shift filetest $INFILE fi die () { echo "ERROR: Cannot specify both -l and -d: Aborting." >&2 exit 1 } usage () { echo "Usage:" echo " $0 -h Display this help message." echo " $0 file -l logfile|-d descfile" echo " -l /path/to/logfile Import using logfile" echo " -d /path/to/logfile Import using description from logfile" exit 1 } LOGFILE="" DESCFILE="" while getopts ":hl:d:" opt; do case ${opt} in h ) usage ;; l ) [ $DESCFILE ] && die LOGFILE=${OPTARG} ;; d ) [ $LOGFILE ] && die DESCFILE=${OPTARG} ;; : ) echo 'missing argument!' >&2 exit 1 ;; \? ) echo "Invalid Option: -$OPTARG" 1>&2 exit 1 ;; esac done shift $((OPTIND -1)) if [ $LOGFILE ] ; then if [ ! -e $LOGFILE ] ; then LOGFILE=$LOGPATH/$LOGFILE filetest $LOGFILE fi fi if [ $DESCFILE ] ; then if [ ! -e $DESCFILE ] ; then DESCFILE=$LOGPATH/$DESCFILE filetest $DESCFILE fi fi echo $INFILE "Logfile: $LOGFILE Descfile: $DESCFILE" duration () { VALUE=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $1 2> /dev/null | cut -d '.' -f 1) if ! let $VALUE 2>/dev/null then # Duration from ffprobe wasn't valid VALUE=3600 fi echo $VALUE } FILE=$(basename $INFILE) RECPATH=$(dirname $INFILE) START=$(stat --format=%X $INFILE) END=$(stat --format=%Y $INFILE) let DUR=END-START # If duration is too short, probe the file if [ $DUR -lt 1800 ]; then DUR=$(duration $INFILE) END=$START let START=END-DUR fi # Extract title from last level of RECPATH TITLE=$(basename $RECPATH | sed -e 's/-/ /g' -e 's/_/ /g') if [ $LOGFILE ] ; then if [ "$LOGFILE" == "$JSONFILE" ] ; then mv ${LOGFILE} /tmp/import.tmp LOGFILE=/tmp/import.tmp fi echo -n "conf=" > "$JSONFILE" egrep -wv 'config_name|autorec|channel' ${LOGFILE} >> "$JSONFILE" sed -i "s@filename\": .*\"@filename\": \"${INFILE}\"@" "$JSONFILE" sed -i "s/comment\": .*\"/comment\": \"Imported\"/" "$JSONFILE" else if [ "$DESCFILE" ]; then CHANNEL=$(grep -w channelname "$DESCFILE" | cut -d ' ' -f 2 | sed -e "s@\"@@g" -e "s@,@@g" ) START=$(grep -w "start" $DESCFILE | head -1 | cut -d ' ' -f 2 | sed 's/,//') STOP=$(grep -w "stop" $DESCFILE | head -1 | cut -d ' ' -f 2 | sed 's/,//') else CHANNEL="local file" fi cat << EOF > "$JSONFILE" conf={ "enabled": true, "start": $START, "stop": $END, "channelname": "$CHANNEL", "duration" : $DUR, "title": { "eng": "$TITLE" }, EOF if [ "$DESCFILE" ]; then grep -A 2 subtitle $DESCFILE >> "$JSONFILE" grep -A 2 description $DESCFILE >> "$JSONFILE" else cat << EOF >> "$JSONFILE" "subtitle": { "eng": "filename: $FILE" }, "description": { "eng": "" }, EOF fi cat << EOF >> "$JSONFILE" "comment": "added by $(basename $0)", "files": [ { "filename": "$INFILE" } ] } EOF fi echo "Sending create command for \"$TITLE\"" if curl -q --data @"$JSONFILE" "http://$USER:$PASS@localhost:9981/api/dvr/entry/create" ; then echo "Imported \"$TITLE\"" >> /tmp/tvhimport.log fi echo exit 0
RE: Piping mkv file help - Added by Lisa White over 4 years ago
Hello Mr. Hiro and thank you for the creative script. Unfortunately, I am a beginner but a fast learner. I tried to use your file but I cannot get it going and ran out of ideas. This was my error message:
./recording: line 35: [: !=: unary operator expected
Logfile: Descfile:
basename: missing operand
Try 'basename --help' for more information.
dirname: missing operand
Try 'dirname --help' for more information.
stat: missing operand
Try 'stat --help' for more information.
stat: missing operand
Try 'stat --help' for more information.
basename: missing operand
Try 'basename --help' for more information.
Sending create command for ""
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>400 Bad Request</TITLE>
</HEAD><BODY>
<H1>400 Bad Request</H1>
</BODY></HTML>
I am confused on how to use this script. This is what I did to gave me this error:
1. Copied and pasted your script to text and saved it as recording within directory (~home/me)
2. Chmod of file to execute
3. Copied friends s-10.mkv file to same directory as script
4. Using terminal, I executed file (./recording) and received error above
Can you please explain to me what I did wrong and how I should proceed to accomplish these goals on transferring my video file into tvheadend?
Thanks a bunch for all your help,
Lisa
RE: Piping mkv file help - Added by Hiro Protagonist over 4 years ago
Hi,
Thanks for testing my script. One of the things that happens when you write something like this is you tend not to use it incorrectly, & thus don't test the error handling as well as one should.
The script is called tvhimport.sh, but you can call it whatever you like.
At least one argument is required, being the full path to the file being imported, e.g.
tvhimport.sh /full/path/to/file.mkv
If the file is in the directory you're currently in, you can just use the filename without the path.
You would normally first copy or move the file into the pvr directory, this script doesn't copy the file,
it just tells TVH that it exists.
So, if you have Lewis-s01e05.mkv, you'd first put it in an appropriate pvr directory, creating the directory if it doesn't exist. Naturally, you should use the pvr directory appropriate for your system.
The script expects that the directory the file resides in is the name of the program, as it would be for something you've recorded.
mkdir /var/spool/pvr/Lewis/ mv Lewis.mkv /var/spool/pvr/Lewis/
The you'd import it:
tvhimport.sh /var/spool/pvr/Lewis/Lewis-s01e05.mkv
Here's an updated copy with better error handling.
#!/bin/bash # # Import recordings into TVHeadend # Assumes "Make subdirectories per title" is enabled, - if this is not the # case, the title will have to be extracted from the filename. # # Not tested on files containing spaces, so make sure your filenames # don't have any! # # Change the following as needed for your setup USER=admin PASS=admin LOGPATH=~/.hts/tvheadend/dvr/log JSONFILE="/tmp/import.json" INFILE=$1 filetest () { if [ ! -e $1 ] ; then echo "$1 does not exist!" exit 1 fi } logtest () { if [ ! -e $1 ] ; then echo "$1 does not exist!" exit 1 fi } die () { echo "ERROR: Cannot specify both -l and -d: Aborting." >&2 exit 1 } usage () { echo "Usage:" echo " $0 -h Display this help message." echo " $0 /path/to/file -l logfile|-d descfile" echo " -l /path/to/logfile Import using logfile" echo " -d /path/to/logfile Import using description from logfile" exit 1 } if [ $# -lt 1 ];then usage exit 1 fi if [ "$INFILE" != "-h" ] ; then shift filetest $INFILE fi LOGFILE="" DESCFILE="" while getopts ":hl:d:" opt; do case ${opt} in h ) usage ;; l ) [ $DESCFILE ] && die LOGFILE=${OPTARG} ;; d ) [ $LOGFILE ] && die DESCFILE=${OPTARG} ;; : ) echo 'missing argument!' >&2 exit 1 ;; \? ) echo "Invalid Option: -$OPTARG" 1>&2 exit 1 ;; esac done shift $((OPTIND -1)) if [ $LOGFILE ] ; then if [ ! -e $LOGFILE ] ; then LOGFILE=$LOGPATH/$LOGFILE filetest $LOGFILE fi fi if [ $DESCFILE ] ; then if [ ! -e $DESCFILE ] ; then DESCFILE=$LOGPATH/$DESCFILE filetest $DESCFILE fi fi echo $INFILE "Logfile: $LOGFILE Descfile: $DESCFILE" duration () { VALUE=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $1 2> /dev/null | cut -d '.' -f 1) if ! let $VALUE 2>/dev/null then # Duration from ffprobe wasn't valid VALUE=3600 fi echo $VALUE } FILE=$(basename $INFILE) RECPATH=$(dirname $INFILE) START=$(stat --format=%X $INFILE) END=$(stat --format=%Y $INFILE) let DUR=END-START # If duration is too short, probe the file if [ $DUR -lt 1800 ]; then DUR=$(duration $INFILE) END=$START let START=END-DUR fi # Extract title from last level of RECPATH TITLE=$(basename $RECPATH | sed -e 's/-/ /g' -e 's/_/ /g') if [ $LOGFILE ] ; then if [ "$LOGFILE" == "$JSONFILE" ] ; then mv ${LOGFILE} /tmp/import.tmp LOGFILE=/tmp/import.tmp fi echo -n "conf=" > "$JSONFILE" egrep -wv 'config_name|autorec|channel' ${LOGFILE} >> "$JSONFILE" sed -i "s@filename\": .*\"@filename\": \"${INFILE}\"@" "$JSONFILE" sed -i "s/comment\": .*\"/comment\": \"Imported\"/" "$JSONFILE" else if [ "$DESCFILE" ]; then CHANNEL=$(grep -w channelname "$DESCFILE" | cut -d ' ' -f 2 | sed -e "s@\"@@g" -e "s@,@@g" ) START=$(grep -w "start" $DESCFILE | head -1 | cut -d ' ' -f 2 | sed 's/,//') STOP=$(grep -w "stop" $DESCFILE | head -1 | cut -d ' ' -f 2 | sed 's/,//') else CHANNEL="local file" fi cat << EOF > "$JSONFILE" conf={ "enabled": true, "start": $START, "stop": $END, "channelname": "$CHANNEL", "duration" : $DUR, "title": { "eng": "$TITLE" }, EOF if [ "$DESCFILE" ]; then grep -A 2 subtitle $DESCFILE >> "$JSONFILE" grep -A 2 description $DESCFILE >> "$JSONFILE" else cat << EOF >> "$JSONFILE" "subtitle": { "eng": "filename: $FILE" }, "description": { "eng": "" }, EOF fi cat << EOF >> "$JSONFILE" "comment": "added by $(basename $0)", "files": [ { "filename": "$INFILE" } ] } EOF fi echo "Sending create command for \"$TITLE\"" if curl -q --data @"$JSONFILE" "http://$USER:$PASS@localhost:9981/api/dvr/entry/create" ; then echo "Imported \"$TITLE\"" >> /tmp/tvhimport.log fi echo exit 0
RE: Piping mkv file help - Added by Lisa White over 4 years ago
Thanks for your reply. I still cannot get the script going. I am determined and excited but need some more input. I followed the direction and I tried modifying the script by changing the username and password that I assigned to the ip login. My results were the same.
This is what I received when I run the script:
m@m:/home/hts/recordings$ ./tv.sh friends.mkv
friends.mkv Logfile: Descfile:
Sending create command for "."
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>401 Unauthorized</TITLE>
</HEAD><BODY>
<H1>401 Unauthorized</H1>
<P STYLE="text-align: center; margin: 2em"><A HREF="/" STYLE="border: 1px solid; border-radius: 4px; padding: .6em">Default login</A></P><P STYLE="text-align: center; margin: 2em"><A HREF="/login" STYLE="border: 1px solid; border-radius: 4px; padding: .6em">New login</A></P></BODY></HTML>
Can you explain what I am missing to execute the file? This is very interesting and educational for me.
Thanks again,
Lisa
RE: Piping mkv file help - Added by Lisa White over 4 years ago
Thanks for your reply. I still cannot get the script going. I am determined and excited but need some more input. I followed the direction and I tried modifying the script by changing the username and password that I assigned to the ip login. My results were the same.
This is what I received when I run the script:
m@m:/home/hts/recordings$ ./tv.sh friends.mkv
friends.mkv Logfile: Descfile:
Sending create command for "."
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>401 Unauthorized</TITLE>
</HEAD><BODY>
<H1>401 Unauthorized</H1>
<P STYLE="text-align: center; margin: 2em"><A HREF="/" STYLE="border: 1px solid; border-radius: 4px; padding: .6em">Default login</A></P><P STYLE="text-align: center; margin: 2em"><A HREF="/login" STYLE="border: 1px solid; border-radius: 4px; padding: .6em">New login</A></P></BODY></HTML>
Can you explain what I am missing to execute the file? This is very interesting and educational for me.
Thanks again,
Lisa
RE: Piping mkv file help - Added by Ron L over 4 years ago
Hi, haven't really looked at the script to see what it's trying to do. To add a movie file as a channel in TVH I've done this....
Create a new mux and use something like this as the URL....
pipe:///usr/bin/ffmpeg -loglevel fatal -re -i /media/ron/external/Movies/garfield.mp4 -vcodec copy -acodec copy -metadata service_provider=FIFO -metadata service_name=Garfield -f mpegts -tune zerolatency pipe:1
Let the new mux scan and it will create a new service. Map that service to a channel.
RE: Piping mkv file help - Added by Lisa White over 4 years ago
Thank you for that information Ron. I accomplished that method a few days ago and noticed that the pause, fast forward and rewind buttons were missing from the Kodi interface when piped. There is only a play and stop button. When stopped, the video would revert back to the beginning of the movie and there was no way to continue watching where I left off.
Is there a way through the pipe command that I can make all of these feature work as I explained?
Thanks for your help,
Lisa
RE: Piping mkv file help - Added by Ron L over 4 years ago
I believe the nature of pipes would preclude any of that sort of functionality. To have these one would have to have to access the videos through Kodi rather than as a TvHeadend channel.
RE: Piping mkv file help - Added by Hiro Protagonist over 4 years ago
Lisa White wrote:
Thanks for your reply. I still cannot get the script going. I am determined and excited but need some more input. I followed the direction and I tried modifying the script by changing the username and password that I assigned to the ip login. My results were the same.
This is what I received when I run the script:
m@m:/home/hts/recordings$ ./tv.sh friends.mkv
friends.mkv Logfile: Descfile:
Sending create command for "."
As I mentioned, the script uses the directory that the file resides in to figure out the title.
I could change this if you like, but to get this to work, create a directory in your recordings directory called friends, move friends.mkv to there, and then use the directory in the argument to the script:
tv.sh /home/hts/recordings/friends/friends.mkv
However, see below:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>401 Unauthorized</TITLE>
You've either got the user/password wrong, or the user you've selected doesn't have permission to do this - check the permissions for that user via the web interface to TVH.
RE: Piping mkv file help - Added by Lisa White over 4 years ago
Hello Hiro and sorry for the delayed response. I am in the process of updating my system with a new hard drive and a clean install of tvheadend. I ran into 2 snags today and one is with your script. I am the only superuser of my system and I am stilling get the unauthorized error as follows:
me@me:/home/hts/tv/casino$ ./tvimport.sh casino.mkv
casino.mkv Logfile: Descfile:
Sending create command for "."
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>401 Unauthorized</TITLE>
</HEAD><BODY>
<H1>401 Unauthorized</H1>
<P STYLE="text-align: center; margin: 2em"><A HREF="/" STYLE="border: 1px solid; border-radius: 4px; padding: .6em">Default login</A></P><P STYLE="text-align: center; margin: 2em"><A HREF="/login" STYLE="border: 1px solid; border-radius: 4px; padding: .6em">New login</A></P></BODY></HTML>
The import.json file is being sent to the tmp file. This is the text of the file:
conf={
"enabled": true,
"start": 1587228326,
"stop": 1587239026,
"channelname": "local file",
"duration" : 10700,
"title": {
"eng": "."
},
"subtitle": {
"eng": "filename: casino.mkv"
},
"description": {
"eng": ""
},
"comment": "added by tvimport.sh",
"files": [
{
"filename": "casino.mkv"
}
I assume that this is the creation for the log that is needed for the file to be played but it will not import into tvheadend. Something is blocking my access and I cannot figure out why. I changed the superuser password and user name to admin as you have within your posted sample. Changing the login information did not solve my problem and I still getting the 401 unauthorized error.
Just for fun, I tried just using the address: http://admin:admin@localhost:9981 without the script and I could log in fine.
Any Ideas?
Thanks Lisa
RE: Piping mkv file help - Added by Lisa White over 4 years ago
Hiro, I got your script to execute with tvheadend 4.29 vers. It must not work with 4.3 vrs.
The created log displays under the "removed recordings, file missing." I did execute your file like you instructed in the recording directory where the other recording files are. My movie file is not showing up with the other recordings or is it visible. Is the log file supposed to be in that group category and is there other steps that I am missing?
Any suggestions?
RE: Piping mkv file help - Added by Dave Pickles over 4 years ago
Check that "Authentication type" in Configuration -> General -> Base -> HTTP Server Settings is set to "Both plain and digest".
RE: Piping mkv file help - Added by Lisa White over 4 years ago
yes they were checked. The log indicates "unable to stat file". Any other ideas?
Thanks
RE: Piping mkv file help - Added by Hiro Protagonist over 4 years ago
Can you post the command that you're typing in to import the file?
I note from the previous post you made:
"title": { "eng": "." },
Which would indicate that you've not provided the absolute path to the imported file.
As I mentioned in a previous post, your commandline should look like:
tvhimport.sh /home/hts/recordings/friends/friends.mkv
The script was written to fix a specific problem I had, and for more general use, I could add a parameter to explicitly add the title. Nevertheless, you do have to tell TVH exactly where the file is. You must use an absolute path [i.e. with a / at the start] that points to the file you're importing.
RE: Piping mkv file help - Added by Lisa White over 4 years ago
Thank you for all of your help. Adding the title would be appreciated. After reading your last post, I misunderstood the directions. I executed your script and it worked. Thank You! Thank You! and Thank You! The only downside is that the script will not work on tvheadend ver 4.3. I tried multiple times using 2 different computers and I keep getting the 401 unauth error upon execution.
I installed the bionic stable 4.28 version and it executes perfectly.
Now since I got the movie installed, can I copy the file and the log and insert it into the 4.3 tvheadend version? Will it play?
Thank you so much and I would give you a big hug for making my day. I can finally watch my FAVORITE seasons of FRIENDS.
Lisa
RE: Piping mkv file help - Added by Hiro Protagonist over 4 years ago
the script will not work on tvheadend ver 4.3
Where did you get the 4.3 from?
I run it here on 4.3 so it definitely does work, however back in Dec/Jan I was troubleshooting another issue & loaded a 4.3 build from online - couldn't get the API calls this script uses to work on that - I presume because of some build option.
I'm now running a 4.3 I complied myself & it works fine.
Will add the title option when I have a bit of time.
RE: Piping mkv file help - Added by Hiro Protagonist over 4 years ago
Lisa White wrote:
Now since I got the movie installed, can I copy the file and the log and insert it into the 4.3 tvheadend version? Will it play?
I suspect that won't work, but you could try it, however without the API call, TVH won't know the recording is there, so you'd have to restart it.
Probably more practical to get a 4.3 with working APIs.