BrianDMG / conv2mp4

This Powershell script will recursively search through a user-defined file path and convert all videos of user-specified file types to MP4 with H264 video and AAC audio using ffmpeg. The purpose of this script is to reduce transcoding CPU load on a media server like Plex or Emby and increase video compatibility across platforms.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Keep folder structure when saving to a new location?

SpaceFanatic opened this issue · comments

Would it be possible to save the folder structure of the files being converted (ie TV Show/Season/Filename) and create those folders in the new location so that everything stays organized? Also possibly delete the old folder and all the contents?

I host my server on a Pi but convert all the files on my PC with a much better cpu. I currently store files that need converting on my PC then save to a folder on the Pi for the converted files. The garbage system is great but it leaves behind a bunch of empty folders on the PC that I have to manually delete so I know what has already been converted and what hasn't.

commented

I can definitely add an empty folder delete into garbage collection in the next release.

For the folder structure request, I assume you're using $outPath? If so, I can look in to the effort required to add that feature.

Great thanks, and yes I'm using out path
I don't have any experience with powershell but I know a bit about coding so I might tinker with it a bit too and see if I can come up with anything.

commented

Alright, I'll look in to it. If you come up with something before I do, feel free to submit a pull request and I'll merge it in.

The logic I had in mind was to compare the filename listed in $mediaPath to the full path name listed in the start of the printout after "there are n files in the queue".

Obviously the full path will be $mediaPath + the subfolders + the old file. I'm not sure if you could then subtract the $mediaPath portion of it to get the subfolder structure and then just add that same structure to the $outPath. ($outpath + subfolders + converted file)

Not sure if Powershell would automatically generate those subfolders if they didn't already exist in the new location or not and how easy it would be to isolate the subfolders from the rest of the pathname.

commented

Good work, just merged your pull request.

The only thing I noticed was if no absolute path is provided in $outPath in the config file (e.g. if you just use "testout" without anything else, intending the testout directory to be created in the same directory as the script) it will append the entire path to the subfolders.

In my test, I created a copy of the script in c:\users\user\desktop\convtest. $outPath was simply "testout" in the cfg file, making $outPath c:\users\user\desktop\convtest\testout. When the script ran, it created the subfolders "users\user\desktop\convtest\testout\othersubfolders" in the $outPath directory.

Using an absolute path produces the desired result of a direct copy of the directory tree within $outPath.

Good to know, hadn't thought to test it that way because I always save to a different drive.

Glad you got it to work as intended, it was an interesting challenge trying to accomplish a task I knew should easy in a coding language I had never used before.

commented

Honestly in a "production" usage of this script, I would've supplied an absolute path, but I was just trying to stage a testing environment quickly, so I did what was quickest. I just threw $PSScriptRoot in front of the directory names for the 2nd test and it worked fine. I haven't tested it yet, but something as simple as "." might even do the trick.

It's good to know there are other people with a similar outlook out there - I actually learned PowerShell from the process of writing this script (had no prior knowledge of it). I'm a Linux guy at heart, and I'm much more comfortable in BASH, but wanted to harness my gaming PC's (which runs on Windows) unused CPU cycles to convert videos so my Plex server wouldn't have to shoulder that load, hence PowerShell. If you're trying to automate anything with Windows these days, it's really the only sane choice. I kinda like it, to be honest (especially how permissive it is with white space) - it's a nice change of pace from "the usual".