Project

General

Profile

Post Processing script - need help please

Added by David Baker over 7 years ago

Hello Everyone :)

New user here, just built a TVHE server, and love the way its designed and works. Was using NextPVR, and tried MythTV. But found i like TVHE the most.

Hoping someone can help me with the problem with post processing output files.
Not sure if this will be important to my problem, so ill just point out, I am in Australia, so I'm not using a paid service for the EPG as i can get it free over the air. Although that may change later.

I have TVHE setup to output - pass, so straight to the .ts container.
What i want to do, is use a post processing script that will Trans-code the TVHE output file .ts to Handbrake output .mp4.

Have managed to get this to work, of a sort, by adding this line below into TVHE - post processing field.
/usr/bin/HandBrakeCLI -Z "Android 1080p30" --no-dvdnav -O -s 1 -i "%f" -o /home/capture/MP4/"%b".mp4

It gives me a converted file, although it has the file name, and .ts on the end of the file name, then the file extension. EG news.ts.mp4.
Not exactly what i was wanting, but its the closest Ive managed to get working.

This means i end up with two files, one is the original .ts captured video, and then the Trans-coded .mp4 that i want. I would like to be able to call a script, that will perform the trans-code, and then remove the original file, once the trans-code is comlete. But this is where the problem lays. I cant get a script working.

Ive setup the script to be executable, and allowed all users to have rights. But when ever i try to use the script, I can never get an trans-coded output .mp4 file.

Here below is a copy of my test.sh script file, hoping someone can see what I'm doing wrong, and point me in the right direction.

In the Script, ive tried to keep notes, to help me work this out, and tried to output variable values to an log file, but that does not output anything at all.

Please help,have spend days trying to work this out, and i am failing miserably.

#!/bin/bash ###################################################
  1. Command Pass variables
  2. %f Full path to recording /home/user/Videos/News.ts
  3. %b Basename of recording News.ts
  4. %c Channel name BBC world
  5. %O Owner of this recording user
  6. %C Who created this recording user
  7. %t Program title News
  8. %s Program subtitle Afternoon
  9. %p Program episode S02.E07
  10. %d Program description News and stories…
  11. %e Error message Aborted by user ###################################################
  12. This script's name and location
  13. /home/capture/MP4/test.sh ###################################################
  14. Mark script executable
  15. sudo chmod +x /home/capture/MP4/test.sh ###################################################
  16. Allow all to execute
  17. sudo chmod +777 /home/capture/MP4/test.sh ###################################################
  18. TVHE command string
  19. /home/hts/01-scripts/ts-mp4.sh %f %t ###################################################
  1. Works in TVHE on command line only
  2. /usr/bin/HandBrakeCLI -Z "Android 1080p30" --no-dvdnav -O -s 1 -i "%f" -o /home/capture/MP4/"%b".mp4
  1. Pass variable values to output log file for testing
    Log=/home/capture/MP4/output.log
    echo >> $Log
    echo Full path to recording: %f >> $Log
    echo Basename of recording: %b >> $Log
    echo Channel name: %c >> $Log
    echo Owner of this recording: %O >> $Log
    echo Who created this recording: %C >> $Log
    echo Program title: %t >> $Log
    echo Program subtitle: %s >> $Log
    echo Program Episode: %p >> $Log
    echo Program description: %d >> $Log
    echo Error Message: %e >> $Log
  1. Transcode TVHE output file .ts to Handbrake output .mp4
    /usr/bin/HandBrakeCLI -Z "Android 1080p30" --no-dvdnav -O -s 1 -i "%f" -o /home/capture/MP4/"%b".mp4

#Delete original file after transcoding. - Apply this code once the .ts to mp4 is working from script
#rm -f $1

Copy of script attached.

test.sh (1.86 KB) test.sh Test Script

Replies (2)

RE: Post Processing script - need help please - Added by James Holloway over 7 years ago

Hi David,

don't forget that when your script runs, it will run as the hts user (and not you), so you must make sure that it has write access to your output directory (/home/capture/MP4/). I don't see anything in your notes about this (quickest and dirtiest step to achieving this is make the directory world writable).

Assuming you're executing your file via:

/home/capture/MP4/test.sh %f %b

Then your script will be seeing those arguments in $1 and $2 (not as %f and %b) as you have them currently.

I use Plex to manage all my media and my current setup when recording (similar to you - ts files, usually HD):

1. Make a copy of the audio track in aac format - doing this negates the need for any on the fly transcoding in Plex in the files I've tested when streaming to Android devices. Transcoding still takes place when streaming to other platforms, depending on the content (some works in direct play, some doesn't).
2. Discard audio narration track if present (some of the streams here have audio for visually impaired).
3. Discard subtitles.
4. Wrap up the two remaining audio tracks (1 if the audio is already in aac format) and video track into an MKV.
5. Copy it over to the relevant folder for Plex to see it.
6. Trigger Plex api to update library.

This whole process takes < 1 minute on an older machine per hour of HD content. Plex transcodes the content when it needs to, but I personally prefer doing that on the fly than waiting for the whole thing to be encoded.

I may eventually get around to open sourcing that stuff.

Anyway, as for your issue - I would:

1. put the script in a different folder to wherever you're outputting.
2. go to record something that only has a minute or two left to run, so you're not hanging about forever while you test (or just stop the recording after a minute or two). Monitor the output of /var/log/syslog (I'm assuming you're using Ubuntu) - tail -F /var/log/syslog

You should see something like this:

Mar  1 21:07:39 media-of-jim tvheadend[2319]: dvr: /home/hts/New: Benidorm.ts from adapter: "TurboSight TBS 6909 DVB-S/S2  : DVB-S #0", network: "Freesat", mux: "11097V", provider: "BSkyB", service: "ITV HD" 
Mar  1 21:07:39 media-of-jim tvheadend[2319]: dvr:  #  type              lang  resolution  aspect ratio  sample rate  channels
Mar  1 21:07:39 media-of-jim tvheadend[2319]: dvr:  1  H264                    1920x1080   ?
Mar  1 21:07:39 media-of-jim tvheadend[2319]: dvr:  2  MPEG2AUDIO        nar                             ?            ?
Mar  1 21:07:39 media-of-jim tvheadend[2319]: dvr:  3  DVBSUB            eng
Mar  1 21:07:39 media-of-jim tvheadend[2319]: dvr:  4  TELETEXT
Mar  1 21:07:39 media-of-jim tvheadend[2319]: dvr:  5  AC3               eng                             ?            ?
Mar  1 21:07:39 media-of-jim tvheadend[2319]: dvr:  6  TEXTSUB           eng
Mar  1 21:07:53 media-of-jim tvheadend[2319]: spawn: Executing "/home/liljim/test_process.sh" 
Mar  1 21:07:53 media-of-jim tvheadend[2319]: subscription: 0059: "DVR: New: Benidorm" unsubscribing from "ITV HD" 
Mar  1 21:07:53 media-of-jim tvheadend[2319]: dvr: "New: Benidorm" on "ITV HD": End of program: Aborted by user
Mar  1 21:07:53 media-of-jim tvheadend[2319]: spawn: Encoding '/home/hts/New: Benidorm.ts' to '/home/liljim/testrecordings/New: Benidorm.mp4'
Mar  1 21:07:53 media-of-jim tvheadend[2319]: spawn: [21:07:53] hb_init: starting libhb thread
Mar  1 21:07:53 media-of-jim tvheadend[2319]: spawn: HandBrake 0.10.2 (2016021200) - Linux x86_64 - https://handbrake.fr
[....]
Mar  1 21:07:56 media-of-jim tvheadend[2319]: spawn: Encode done!
Mar  1 21:07:56 media-of-jim tvheadend[2319]: spawn: HandBrake has exited.
Mar  1 21:07:56 media-of-jim tvheadend[2319]: spawn: Encoding: task 1 of 1, 91.36 %
Mar  1 21:07:56 media-of-jim tvheadend[2319]: spawn: DONE Encoding '/home/hts/New: Benidorm.ts' to '/home/liljim/testrecordings/New: Benidorm.mp4'

I've attached a small script I cobbled together to test with based on what you're doing, a screenshot of my post processor commands for this test script, and one of a video streaming from Plex on Android to give you an idea of what that looks like (the play, pause, stop etc obviously disappear after a second or two into play).

Good luck!

RE: Post Processing script - need help please - Added by Addled Badger about 5 years ago

Hi,

Also looking for help with this. I want to copy the recordings to a remote machine for transcoding.

I'm running TVHeadEnd using Docker-compose, with the following post-processing command:
```
/opt/tvheadend/postprocess.sh %f %b
```
This calls the script:
```
#!/bin/bash
scp $1 :/Volumes/Scratch/Pi-Media/$2
```

If I run the script from the terminal it works fine. With logging enabled, TVHeadEnd just 'spawns' the script but nothing happens. I had a couple of test 'echo' commands, which also don't appear in the log.

Any advice much appreciated! Thanks in advance.

    (1-2/2)