Jump to content
PenkethBoy

Post Processing Script - Working Example - Powershell

Recommended Posts

jasonmcroy

Ha! Now I understand what you're trying to say and I see what I am not doing. I didn't realize that the command you listed above (your first post) is what you would manually put into powershell if you're just doing it manually and not via Emby's post processing function.

 

I did what you said this time and it's processing now. 

 

By the way, how long does it usually take in your experience to process a 1 hour recording? Mine is still processing and it's been almost an hour now.

Share this post


Link to post
Share on other sites
PenkethBoy

Time is relative :)

 

Depends on

 

1. HD vs SD content

2. CPU GHz and number of Threads the CPU has

3. The ffmpeg commands you apply

 

For example - see the txt output for encoding times

- HD content converted on my i7 6700k runs at ~1.85x - so an hour recording would take approx 35 mins

- SD content converted on my i7 6700k runs at ~10x - so an hour recording would take approx 6 mins

 

As the script is an example the ffmpeg commands are simple and should cover most input and cope with most errors inherent in LiveTv streams - its not bomb proof though

 

You could change the ffmpeg commands to do other things - that would shorten the PP encode time - but might affect the quality and file size produced.

 

Thats up to you to research and test.

 

Note - if you run this manuallyfor a second time on the same file - dont run it with an existing PP file in the directory as you will setup a deadlock - delete the existing file first or add "-y" to the ffmpeg commands so it will overwrite the existing file

Edited by PenkethBoy
  • Like 1

Share this post


Link to post
Share on other sites
jasonmcroy

Thanks! I will do some research and testing today. You're comment about not running it with an existing PP file in the directly may have been an issue last time. I ended up killing powershell and ffmpeg because it was taking so long. However, I was also testing on my less powerful PC. It is an i3 cpu and was maxed out at 95-98% the whole time.

 

I have a beefier PC I can test on today that is an 8 core AMD cpu with 16gb ram in it. 

 

I will also do some research on the different ffmpeg commands I can use because I also want to test just doing a simple remux. The HDHomerun Premium channels come in at H.264 so I really only need a simple command for those. It is my OTA channels that come in at mpeg2 that take longer. 

 

Thanks for walking me through this!

Share this post


Link to post
Share on other sites
PenkethBoy

even your H.264 streams from the hdhr - will need re-encoding as the streams are almost always with errors - a simple remux will fail

 

ffmpeg always runs as fast as it can so 99% - normal

 

i3 - will do the PP but not very quickly

 

for ffmpeg - look at the -preset option - veryfast and superfast work well if the file is for viewing once and deleting - medium is very similar to what you have now

 

read this https://trac.ffmpeg.org/wiki/Encode/H.264

Edited by PenkethBoy
  • Like 2

Share this post


Link to post
Share on other sites
jasonmcroy

Thanks!

Share this post


Link to post
Share on other sites
Fratopolis

NOTE - 11/9/2018

 

To be clearer the script above does not do any error checking to see if the ffmpeg process failed to convert the ts file and if you have the -DelFile option enabled it will just delete the ts file.

 

Error checking could be added by the user although from reading a few threads on ffmpeg - getting a valid exit code of 0 (zero) does not always mean the conversion worked! - sigh

 

So use the -DelFile with caution as recorded LiveTV is prone to errors in the ts stream - some of which may cause ffmpeg to abort.

 

did mine in bat file which has a basic error check if ffmpeg remuxed properly. so far it has worked just fine with my HDHR prime and OTA tuners

 

Share this post


Link to post
Share on other sites
Kramerika

I found an issue with this.  If the title of the show has an apostrophe in it, it breaks the script. Both America's Got Talent and Marvel's Agents of Shield fail to execute.  Other shows without apostrophes work just fine.  Here is an example and the error generated.  Is there a work-around for this?

 

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command "& 'D:\Recordings\convert.ps1' -oldVideo 'D:\Recordings\Emby\America's Got Talent (2006)\Season 14\America's Got Talent S14E01 Auditions 1.ts' -InType ts -OutType mkv -DelFile"

 

D:\Recordings\convert.ps1 : A positional parameter cannot be found that accepts argument 's'.
At line:1 char:1
+ & 'D:\Recordings\convert.ps1' -oldVideo 'D:\Recordings\Emby\America's ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: ( :) [convert.ps1], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,convert.ps1
Edited by Kramerika

Share this post


Link to post
Share on other sites
PenkethBoy

enclose the file path in double quotes rather than single quotes

 

i.e.  "D:\Recordings\Emby\America's Got Talent (2006)\Season 14\America's Got Talent S14E01 Auditions 1.ts"

Share this post


Link to post
Share on other sites
Kramerika

Thanks, but unfortunately that did not fix the problem.

 

 

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command "& "D:\Recordings\convert.ps1" -oldVideo "D:\Recordings\Emby\America's Got Talent (2006)\Season 14\America's Got Talent S14E01 Auditions 1.ts" -InType ts -OutType mkv -DelFile"

 

 

D:\Recordings\convert.ps1 : A positional parameter cannot be found that accepts argument 'Got'.
At line:1 char:1
+ & D:\Recordings\convert.ps1 -oldVideo D:\Recordings\Emby\America's Go ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: ( : ) [convert.ps1], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,convert.ps1

Share this post


Link to post
Share on other sites
PenkethBoy

How are you using the script?

 

Are you running from the emby post processing option?

 

or trying to run it directly from a command window? 

 

and if the second are you using a powershell console window?

Share this post


Link to post
Share on other sites
PenkethBoy

If you run the script from within a powershell console window then it works fine

 

i.e.

D:\Recordings\convert.ps1 -oldVideo "D:\Recordings\Emby\America's Got Talent (2006)\Season 14\America's Got Talent S14E01 Auditions 1.ts" -InType ts -OutType mkv -DelFile

Share this post


Link to post
Share on other sites
speechles

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command "& 'D:\Recordings\convert.ps1' -oldVideo 'D:\Recordings\Emby\America''s Got Talent (2006)\Season 14\America''s Got Talent S14E01 Auditions 1.ts' -InType ts -OutType mkv -DelFile"

 

It is the ' in America's causing you headaches. The ''(press ' twice.. not a double quote " single char) is powershell's version of ' within ' '. You just add a ' on the ' in the filename already within ' '.

Edited by speechles

Share this post


Link to post
Share on other sites
Kramerika

I am running it from a command line to test it, but I want to use it in post processing.  That works fine for any other titles.  It's only when there is an apostrophe.

 

Is there a way to automate replacing an apostrophe with a double single quote within the script?  If not, I guess I'm out of luck on any show that includes one in the title.

Share this post


Link to post
Share on other sites
PenkethBoy

the PP option in emby uses the command prompt and is where the issue ls - i.e. you have to escape the single quote to two single quotes - as the command prompt (windows) has an issue with the single quote and does not pass Powershell the full path

 

To overcome this you could use a bat file with code to escape the single quote and then pass it to the PS script which would then work

@[member="Echo"] off
set test=%1
REM adds '' to escape '
set result=%test:'=''%

powershell -command "& 'F:\EmbyPP\EmbyPP.ps1' -oldvideo "'%result%'" -intype mp4 -outtype mkv"

for example - save the above as say pp.bat with the path amended to your copy of the ps1 file

 

and change the emby dvr to look like this

 

5d0172d14e8cf_Annotation.png

  • Like 1

Share this post


Link to post
Share on other sites
Kramerika

I will try the above.  Marvel's Agents of Shield records tomorrow night, so I'll just wait for it to run to test it.  Thanks!

Edited by Kramerika

Share this post


Link to post
Share on other sites
Kramerika

That worked!  Thanks!

Share this post


Link to post
Share on other sites
rbjtech

NOTE - 11/9/2018

 

To be clearer the script above does not do any error checking to see if the ffmpeg process failed to convert the ts file and if you have the -DelFile option enabled it will just delete the ts file.

 

Error checking could be added by the user although from reading a few threads on ffmpeg - getting a valid exit code of 0 (zero) does not always mean the conversion worked! - sigh

 

So use the -DelFile with caution as recorded LiveTV is prone to errors in the ts stream - some of which may cause ffmpeg to abort.

 

Hi - Agree that ffmpeg errorlevel is not reliable - you more than likely know this, but if you dump the output via the report function and then parse for 'failed' to determine if it's safe to delete the source file...

 

ie

 

set ffreport=file=ffreport.log:level=32

ffmpeg.exe -report blah blah

findstr /c:"failed" ffreport.log
if !errorlevel!==0 (
echo Failed
) else (
echo OK
)

Share this post


Link to post
Share on other sites
PenkethBoy

yuk! bat files :)

 

the script is an example and not fully featured thats for people to work out for themselves

 

 

A Hint on how to do it

 

its actually a lot better to check the converted file for errors using ffprobe, capture the output and parse that to see if you have errors/warnings that you can then decide if the ts file can be deleted

Share this post


Link to post
Share on other sites
rbjtech

ffprobe does not integrity check the file - it just reads the metadata - hence it being better to read the source conversion report file - but however you want to do it ..  :)

Share this post


Link to post
Share on other sites
PenkethBoy

you need to look a ffprobe again its doing more than you think

Share this post


Link to post
Share on other sites
revengineer

Is there anyway to do selective processing using an external script? I have some TV programs that will not work with commercial removal so I need to skip this for a few shows and I know which ones they are in advance. I do not think this is possible, but if I overlooked something, please let me know.

Share this post


Link to post
Share on other sites
PenkethBoy

if you know what shows are going to fail - then a blacklist file - would work - that a script process on start up and possibly updates as well - to skip the commercial detection

 

Not that i have seen comskip (assuming you are using that) fail to detect commercials

Share this post


Link to post
Share on other sites
PenkethBoy

This thread will be closed soon as a new tthread will be started soon......

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×
×
  • Create New...