INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Handsfree .ts to .m4v Video Conversion for TV Recordings with MCAQ and FFMPEG  (Read 2057 times)

imeric

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1476

OBJECTIVE of this post: This is for those who are willing to archive while reducing filesize of Video recordings and/or make it compatible with IOS type devices or else automatically.
- With the settings suggested below you retain most of the Image quality, original AC3 sound + 128 kbps aac and reduce to about 15-40% of the original filesize.
- Compression can be tweaked for lower quality/smaller size or vice versa using ffmpeg or handbrake (CRF value in FFMPEG can be changed to a higher value to reduce filesize).
- I've been struggling with the whole handsfree compression ordeal for quite some time and have always put it aside but finally got something totally handsfree and working exactly how I want it.

-First of all thanks to glynor for MCAutotoQueue.  Without it, this would not be possible if you want to keep all your metadata details intact.  This tool works hand in hand with MC and is simply amazing...Plus it's free! More here: http://yabb.jriver.com/interact/index.php/topic,76147.msg515802.html#msg515802
-And to muzicman0 for helping out with scripts, tips and such... Much appreciated!
-muzicman0 does something similar than what's explained below and more info can be found here: https://yabb.jriver.com/interact/index.php/topic,104321.msg725319.html#msg725319 and here: http://yabb.jriver.com/interact/index.php/topic,76147.msg759655.html#msg759655

Tools I'M using:
- MCAutoqueue.
- ffmpeg compiled with x264 and fdk_aac. If you want decent audio quality at lower bitrates, you need the Fraunhoffer AAC codec.  However it's not gpl compliant so you need to manually compile it.  You can download ffmpeg without compiling it but this will come with a much lower quality aac encoder...The libavcodec sounds bad even at 160kbps.  This was a bit tricky to compile and finding doc on the web is overwhelming...But one compiling script I found just worked perfectly.  Just google media-autobuild_suite-master and follow the batch script!
- For audio I'm converting the main AC3 stream to AAC and copying it untouched in a second stream.  AAC has to be the first track  so that I can watch the file on an IPAD2.  The m4v vs mp4 container allows you to have 2 audio tracks therefore keeping untouched the AC3 from TV recordings and allows compatibility with IOS type devices.
You could make this work with handbrake just change my batch file it should be fairly straight forward.  I didn't use handrake for the exact same reason..Compiling with fdk and didn't want to spend another 10 hours to get this to work (and you need linux)..Newer versions of handbrake don't have it.  However the CLI version 10.3 still has fdk built in if you want to use this instead...

It would be a good idea to get familiar with MCAutoqueue for a bit so you understand what's under the hood.  Especially the MCFileIngester! Great tool for modifying files "outside" of MC but keeping your metadata intact especially the Date Imported field.
Once you've figured out how MCAutoqueue works there are two different approaches that can be taken for the argument styles in MCAQ: The Normal approach or the MC Style approach.  I think the MC style approach allows for more flexibility in filerenaming and such, but in my case, the Normal approach made more sense as I just needed to replace the original .ts file with the new compressed .m4v file without tampering with metadata to create filenames. Also a fail safe when funky characters pop-up in the metadata....

What's needed:
1. Install MCAutoQueue by following instructions here: http://yabb.jriver.com/interact/index.php/topic,76147.msg515802.html#msg515802
2. Create Custom library fields in MC (So at the very minimum read the first post above to get Library fields added in MC to support this.)
3. Build processors for MCAQ (MCAutoqueue) Here is my Script.aqconfig file for MCAQ:
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<AQSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <QueuePlaylistPath>_MCAutoQueue</QueuePlaylistPath>
  <FieldToProcess>NeedsProcessing</FieldToProcess>
  <ProcessorConfigs>
    <ProcessorSetting>
      <Name>shrink2m4v</Name>
      <Command>M:\MCAutoQueue_Worker\shrink2m4v.bat</Command>
      <Argument>[Filename]</Argument>
      <MCStyle>false</MCStyle>
      <UpdateField>true</UpdateField>
      <Timeout>240</Timeout>
    </ProcessorSetting>
    <ProcessorSetting>
      <Name>rename_ts2m4v</Name>
      <Command>C:\Program Files (x86)\MCAutoQueue\Processors\MCFileIngester.exe</Command>
      <Argument>--autorun --autoexit -m:ChangeExtension -x:m4v -t:Replace -s:[Filename]</Argument>
      <MCStyle>false</MCStyle>
      <UpdateField>true</UpdateField>
      <Timeout>5</Timeout>
    </ProcessorSetting>
    <ProcessorSetting>
      <Name>rename_m4vback2ts</Name>
      <Command>C:\Program Files (x86)\MCAutoQueue\Processors\MCFileIngester.exe</Command>
      <Argument>--autorun --autoexit -m:ChangeExtension -x:ts -t:Replace -s:[Filename]</Argument>
      <MCStyle>false</MCStyle>
      <UpdateField>true</UpdateField>
      <Timeout>5</Timeout>
    </ProcessorSetting>
  </ProcessorConfigs>
  <DisableProcessorTimeouts>false</DisableProcessorTimeouts>
  <MinimizeProcessors>false</MinimizeProcessors>
  <MaxQueueProcessingRun>0</MaxQueueProcessingRun>
</AQSettings>
4. A batch file:
   a. It renames .ts to .m4v for the compressed output file name.
   b. It runs ffmpeg to generate the output m4v file
   c. It updates MC's library and sidecar file to point to the new compressed file by running MCFileIngester

Here is the shrink2m4v.bat file used
Code: [Select]
@echo off
rem Rename .ts to .m4v
set str=%1
set str=%str:.ts=.m4v%
rem Run ffmpeg
"M:\MCAutoQueue_Worker\ffmpeg.exe" -analyzeduration 100M -probesize 100M -y -i %1 -vf yadif=0:-1:0 -map 0:v -c:v libx264 -preset slower -crf 20 -profile:v high -level 4.1 -map 0:a:0 -ac 2 -c:a:0 libfdk_aac -b:a 128k -map 0:a:0 -c:a:1 copy %str%
rem pause for a few seconds.
ping 127.0.0.1
rem FileIngester to point to the new compressed .m4v version in MC's library and "eventually.." delete original .ts file
"C:\Program Files (x86)\MCAutoQueue\Processors\MCFileIngester.exe" --autorun --autoexit -m:ChangeExtension -x:m4v -t:Replace -s:%1
rem pause for a few seconds...
ping 127.0.0.1
rem All done!

5. Create or add auto-rules in my TV recording subscriptions for this whole process to be handsfree. (See pic 2)
6. Set-up a scheduler task to run MCAQ along with the batch file everynight.  You could do this either under Services in MC or in Windows.  I used Task Sceduler in Windows as I wasn't sure if MC would wake the PC up for this task...
Notes:
I'm still in testing mode with all of this which is why the original file doesn't get deleted yet in the batch file and processors aren't minimized.
Once I feel 100% sure about this setup I will add it in the .bat file.
For Comskip I'm running Dirmon2 as a service and works great so I could include Comskip above but wouldn't get .srt and .edl generated before the task runs over noght.  Besides, it's working great so I leave it the way it is.

Voila!! Have Fun!
Logged

CountryBumkin

  • Citizen of the Universe
  • *****
  • Posts: 3352
Re: Handsfree Compression for TV Recordings with MCAQ and FFMPEG (BETA)
« Reply #1 on: March 17, 2017, 11:47:24 am »

Sorry. So what is this for?
Is to reduce a TV recording's file size for storage purposes? If yes, how much space is saved? If no, please provide an introduction to what you are doing (sharing with us).
Logged

imeric

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1476
Re: Handsfree Compression for TV Recordings with MCAQ and FFMPEG (BETA)
« Reply #2 on: March 17, 2017, 11:57:25 am »

Sorry. So what is this for?
Is to reduce a TV recording's file size for storage purposes? If yes, how much space is saved? If no, please provide an introduction to what you are doing (sharing with us).
Objective added to main post.  I thought the title was self explanatory..Maybe not..Thx
EDIT: I also renamed the title.
Logged

muzicman0

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1239

imeric - Glad you got it working, I love the fact that I can automate all of this stuff now.  I went from manually doing everything to automatically compressing (and manually moving the files) to now having EVERYTHING automated.  Love it!

CountryBumpkin - without using ComSkip, I go from 4-8GB per file to 500-600MB per file.  So roughly 10% the file size.  In my case though, I am compressing at 854x480 resolution.  But even on my 4k TV, the video quality is acceptable.  Don't get me wrong, it's not as good as the original, but not bad either.

I will also say that FFMPEG has an audio copy function as well, so you can always re-encode the video while maintaining the original audio if you want.  Not sure how much that would increase the file size.

I have mine set up so that nothing happens until I watch an episode.  So I watch it originally in full HD.  Once I watch it, then automatically that night it will compress and move to my archive drive.  I don't do this for all shows, just the shows that I really like and think I may watch again someday, or may want to watch with my kids someday.

It also is great if I am going on a trip, and want to stream something from my plex server to the hotel where I am staying.
Logged
Pages: [1]   Go Up