Cayars - Setup walk through and some tips and tricks

FullCycle, the scripts will always try to remux the files (video) if it can vs transcode which is much faster as well as copy existing audio tracks while creating a stereo default track. It will also pull out any SRT subtitle files if it can.

So it should work for you.

@cayars said:
FullCycle, the scripts will always try to remux the files (video) if it can vs transcode which is much faster as well as copy existing audio tracks while creating a stereo default track. It will also pull out any SRT subtitle files if it can.

So it should work for you.

Been using “the script” for a while and like the end result. I mostly remux mkv to mp4.
My perfect setup would be for me to search my tv folder for MKV (and avi) files. Drag those to a folder for processing (which I can do now) but when finished the new mp4 goes back to the individual tv folder (and ideally delete or move the original file out of that tv folder).

Maybe the whole process could be run from run2.bat.

run2.bat searches, finds, and remuxes and/or converts every avi or mkv (in my case) my TV shows folder.
And moves the old mkv and avi to the recycle bin

MCE Buddy does that but I like your configuration setup for best plex results.

@cayars said:
I answered this before but don’t see my post anywhere.

If you are creating MKVs then you’re using the script in a way it wasn’t designed to be used. MKV files them selves can’t be web optimized per say as don’t work in the same way as it would in an MP4.

So using MKV they will always be non optimized since that’s the nature of the beast with that container. It’s a storage container but wasn’t designed for streaming. Plex does work arounds with MKV and other file types that aren’t natively streamable.

Cant MKV files be cleaned though using MKVClean?

https://www.matroska.org/downloads/mkclean.html

mkclean is a command line tool to clean and optimize Matroska (.mkv / .mka / .mks / .mk3d) and WebM (.webm / .weba) files that have already been muxed. It reorders the elements with the Cues at the front, so your Matroska files are ready to be streamed efficiently over the web. It also removes elements not found in the Matroska specs and the extra Meta Seek list of Clusters that some program add to their file. It can also optionally remux the Cluster blocks to start each boundary with a keyframe and the matching audio/subtitle blocks for that keyframe.

Hi Carlos,

Firstly let me thank you for putting this fantastic process together, I have only come across this in the last couple of days, and having been a plex user for 8+ years I only wish I had known a lot earlier!

I have your script running and it works very well, but, if I may, I have a couple of questions just to round off my processes [i have searched the thread but could not find any similar questions raised, but I apologize in advance if I’m asking something you’ve already answered].

  1. If I put through, for example, a file with Video:H264 Audio:EAC3 it appears that the script copies the video and converts 2 audio tracks - one AAC and one AC3. Is the audio conversion of EAC3 to AC3 expected? I would have thought it would copy the EAC3 track? or is this part of optomizing for Plex playback? In any event, I added eac3 to the autoProcess.ini file (line 37 : audio-codec = ac3,mp3,dts,dca,aac,eac3) and it seems to have structured it so it copies the eac3 track rather than convert to ac3 (confimed thru Media Info details on the resultant file) - is what I have done correct? is there anything else that I should be doing? if there is any other audio codec that is not currently listed at line 37 is it just a matter of adding it and it will be copied as the second audio track?

  2. When the process finishes converting it deletes the source. Is there a way I can have it move the source to a different folder once it finishes the conversion process rather than delete it? (eg; could we provide for input say (line 26) at “delete_original” = “/path/to/folder” rather than “delete”.?)

Thanks again.

@gandja said:

  1. If I put through, for example, a file with Video:H264 Audio:EAC3 it appears that the script copies the video and converts 2 audio tracks - one AAC and one AC3. Is the audio conversion of EAC3 to AC3 expected? I would have thought it would copy the EAC3 track? or is this part of optomizing for Plex playback? In any event, I added eac3 to the autoProcess.ini file (line 37 : audio-codec = ac3,mp3,dts,dca,aac,eac3) and it seems to have structured it so it copies the eac3 track rather than convert to ac3 (confimed thru Media Info details on the resultant file) - is what I have done correct? is there anything else that I should be doing? if there is any other audio codec that is not currently listed at line 37 is it just a matter of adding it and it will be copied as the second audio track?

That is exactly what you want to do. Could have swore that was already there but I just checked and it isn’t. Hmm.

  1. When the process finishes converting it deletes the source. Is there a way I can have it move the source to a different folder once it finishes the conversion process rather than delete it? (eg; could we provide for input say (line 26) at “delete_original” = “/path/to/folder” rather than “delete”.?)

There isn’t anything built in to do this. However, it appears you’ve sort of figured out how the scripts work at least at a high level. It probably would not be hard to modify the “delete” routine to move the file instead. That’s the nice thing about open source programs!

Carlo

@spikemixture said:
Been using “the script” for a while and like the end result. I mostly remux mkv to mp4.
My perfect setup would be for me to search my tv folder for MKV (and avi) files. Drag those to a folder for processing (which I can do now) but when finished the new mp4 goes back to the individual tv folder (and ideally delete or move the original file out of that tv folder).

There are some scripts in this thread somewhere that I had previously posted that do exactly this. They query the database, look for all video files not MP4 (easy to modify) and setup a batch file to process just these files.

Carlo

@cayars said:

@spikemixture said:
Been using “the script” for a while and like the end result. I mostly remux mkv to mp4.
My perfect setup would be for me to search my tv folder for MKV (and avi) files. Drag those to a folder for processing (which I can do now) but when finished the new mp4 goes back to the individual tv folder (and ideally delete or move the original file out of that tv folder).

There are some scripts in this thread somewhere that I had previously posted that do exactly this. They query the database, look for all video files not MP4 (easy to modify) and setup a batch file to process just these files.

Carlo

Thanks Carlo,
There are 58 pages in this thread!
Any key words that might be found in a search?

Check out page 21. You will see a couple of scripts you can use. You would need to modify one of them which should be easy. If not just say the word!

Carlo

@cayars said:

@spikemixture said:
Been using “the script” for a while and like the end result. I mostly remux mkv to mp4.
My perfect setup would be for me to search my tv folder for MKV (and avi) files. Drag those to a folder for processing (which I can do now) but when finished the new mp4 goes back to the individual tv folder (and ideally delete or move the original file out of that tv folder).

There are some scripts in this thread somewhere that I had previously posted that do exactly this. They query the database, look for all video files not MP4 (easy to modify) and setup a batch file to process just these files.

Carlo

I seem to recall there are options in Carlo’s scripts to do an “in-place” conversion while keeping the converted file “hidden” from Plex until it’s finished and also allowing for the original MKV (or whatever) to be removed once done.

Alternatively, you could use a script like the one I posted a couple of pages back to “walk” your filesystem, find each file individually that needs to be converted, convert it to a working directory, then have the -script- do the work of moving the converted file into the directory where the original was and then move on to the next file.

I am actually planning to do exactly this with my script because I like the end result of the conversion and am interested in doing this for the bulk of my library.

@cayars said:

@gandja said:

  1. If I put through, for example, a file with Video:H264 Audio:EAC3 it appears that the script copies the video and converts 2 audio tracks - one AAC and one AC3. Is the audio conversion of EAC3 to AC3 expected? I would have thought it would copy the EAC3 track? or is this part of optomizing for Plex playback? In any event, I added eac3 to the autoProcess.ini file (line 37 : audio-codec = ac3,mp3,dts,dca,aac,eac3) and it seems to have structured it so it copies the eac3 track rather than convert to ac3 (confimed thru Media Info details on the resultant file) - is what I have done correct? is there anything else that I should be doing? if there is any other audio codec that is not currently listed at line 37 is it just a matter of adding it and it will be copied as the second audio track?

That is exactly what you want to do. Could have swore that was already there but I just checked and it isn’t. Hmm.

  1. When the process finishes converting it deletes the source. Is there a way I can have it move the source to a different folder once it finishes the conversion process rather than delete it? (eg; could we provide for input say (line 26) at “delete_original” = “/path/to/folder” rather than “delete”.?)

There isn’t anything built in to do this. However, it appears you’ve sort of figured out how the scripts work at least at a high level. It probably would not be hard to modify the “delete” routine to move the file instead. That’s the nice thing about open source programs!

Carlo

Thanks for responding Carlo, I have just been following my nose looking at some of the config files, other than that I have no real idea how the intricacies of your program do their ‘thang’ :blush: .

I’m guessing its somewhere in the ‘converter’ folder in one of the .py files?? or perhaps in the mkvtomp4.py file?? :confused: I’ve read all but couldn’t find anything obvious that pointed to the ‘delete’ routine - but really I’m just throwing darts here!

Could you give me hint where I should look?? Very happy for this old dog to learn something new.

Thanks again.

Graham

@cayars can i use your scripts to convert Sony handycam (AVCHD/m2ts) into MP4? I have had no issues with avi/mkv but was not sure about those files. Would love to convert my home movies into MP4 to prevent transcoding.

@almontef said:
@cayars can i use your scripts to convert Sony handycam (AVCHD/m2ts) into MP4? I have had no issues with avi/mkv but was not sure about those files. Would love to convert my home movies into MP4 to prevent transcoding.

Yes should work fine. If you hit any problems just make a post. Scripts or ini might just need a slight tweek depending on file names. But I believe you should be gold.

Carlo

@cayars said:

@almontef said:
@cayars can i use your scripts to convert Sony handycam (AVCHD/m2ts) into MP4? I have had no issues with avi/mkv but was not sure about those files. Would love to convert my home movies into MP4 to prevent transcoding.

Yes should work fine. If you hit any problems just make a post. Scripts or ini might just need a slight tweek depending on file names. But I believe you should be gold.

Carlo

I’ll give it a whirl this weekend and report back if I run into any issues. Thanks much for the feedback.

Hi,
The script is great. Thank you.

I do not know if I am missing something, I am using the attribute “move_to”, but it only moves the video and not the subtitle. Do I need to activate something else to move also the subtitle file? The subtitle file ends in the output_directory and not in the move_to folder.

Thanks!

Yea that’s really a bug. It really hasn’t come up because I don’t advocate using the “move_to” folder options. It’s not the way the script is intended to be used in the way I have it packaged.

I’ll take a look and see what’s involved in fixing it.

Is there a reason moov is relocated after its picked up by radarr or sonarr?
Doing this on a network drive is extremely slow vs than doing it before it is picked up on the local SSD.

Or is this an issue with my setup and is not setup to do so?

Answered: https://github.com/mdhiggins/sickbeard_mp4_automator/issues/777?_pjax=%23js-repo-pjax-container

I do not do this on purpose in my scripts. Writing the atom up front while faster (on network drives) will create files that are fragmented and can cause Plex grief in apps such as Android.

So I purposely create the file, then rewrite it moving the moov atom to the front and get files without this fragmenting issue.

What I suggest is moving the file to the working directory first and then running the scripts. Just for the record, I’m always interested in producing the best files regardless of time.

Carlo

@cayars said:
Writing the atom up front while faster (on network drives) will create files that are fragmented

Now when you say that are you talking about disk fragmenting? Or another form of weird fragmentation I am not aware of?

Im curious if I would be affected by that being that all my nas drives are formatted in EXT4?

But the local machine doing all the downloading and processing before handing off the files to the nas is formatted in NTFS.

Thanks for the info and assistance.

Can this Script be converted to HEVC h265/x265 ?
I just built a Threadripper 1950x system with 16 cores/32 threads and would love to use this new system to crush the time it takes to trans-code all my movies/Tv shows to x265. To get smaller file size and gain back a lot of storage.

Updated My Post. kind of answered it myself. Not sure it it is correct. But it works

OK. so i was able to compile a FFMPEG version with libFDK_aac and change a few settings in the autoProcess.ini to accomplish h265/x265, It works very well in Manual mode by running the run.bat file.

autoProcess.ini changes:
[MP4]
ffmpeg = ffmpeg.exe
ffprobe = ffprobe.exe
threads = auto
output_directory = E:\Convert\done
copy_to =
move_to = E:\Newsgroups\Completed\Done
output_extension = mp4
output_format = mp4
delete_original = True
relocate_moov = True
video-codec = h265,x265
video-bitrate = 8
video-max-width =
h265-max-level = 4.1
use-qsv-decoder-with-encoder = True
ios-audio = True
ios-first-track-only = False
ios-audio-filter = dynaudnorm
max-audio-channels =
audio-codec = ac3,mp3,dts,dca,aac
audio-language = eng
audio-default-language = eng
audio-channel-bitrate = 256
audio-filter =
subtitle-codec = srt
subtitle-language = eng
subtitle-default-language =
subtitle-encoding =
fullpathguess = True
convert-mp4 = True
tagfile = True
tag-language = en
download-artwork = Poster
download-subs = True
embed-subs = False
sub-providers = addic7ed,podnapisi,thesubdb,opensubtitles
permissions = 0777
post-process = False
pix-fmt =
aac_adtstoasc = True
postopts =-preset,faster
preopts =
video-crf = 23

Only thing now is what is the best way to automate this with SabNZBd. i tried using the autosabnzbd.py but it did nothing. Am i to always use the run.bat to get these resultz?

@cayars said:

@don.alcombright said:
@cayars , what is your best recommendation for generating a list of file locations (for files needed to be be converted)?

My original thought was the get the list of file paths of these files and then run it via a batch command 1 at a time so I could do lets say 50 a day or so and actually monitor the outcome easily, aka if audio messes up or i lose something i didn’t mean too etc etc. But I can’t seem to find a way to get the full list of files exported to a list, or better yet a full list of files that should be converted to a list.

something like this so I can monitor it in the bat file (and comment out the ones I want to do that day:

c:\python27\python manual.py -a -i “\hades\movies\3 Days to Kill (2014)” >> D:\Convert\log.txt
c:\python27\python manual.py -a -i “\hades\movies\8 Mile (2002)” > D:\Convert\log.txt
c:\python27\python manual.py -a -i “\hades\movies\8MM (1999)” > D:\Convert\log.txt

OK. first and for most I want you to shut down Plex and copy the plex database out to a new location to play with as a test. Re-Start plex again. This is just for safety and always a good idea to do when testing anything new.

Download and install SQLite3 binaries onto your plex server from here: SQLite Download Page
You will want SQLite3 and all the files below in the same directory.

What’s sharing from here on out is for Windows since it uses batch files but would be super easy to change for Linux. The important part is to get the idea how to do it.

create a new text file called transcode.txt and put the following in it:
.open ‘C:\PlexData\Plex Media Server\Plug-in Support\Databases\com.plexapp.plugins.library.db’
.output Transcode.bat
SELECT ‘c:\python27\Python C:\convert\manual.py -a -i "’ || file || ‘"’ FROM media_parts join media_items
on media_parts.media_item_id=media_items.id
where container=‘mp4’ and optimized_for_streaming <> 1
order by file;

In the above file change the first line to point to your copy of the database. After you are sure all is working correctly you can change this to point back to your real version.

Now all you have to do is run:
sqlite3 < transcode.txt

You can put that in a batch file if you want.

When you run that it fires up SQLite and uses the contents of the text file to tell it what database to use. It tells it to pipe the output out to transcode.bat (so you can run it when done). It also contains the SQL code used to run against the database.

You can adjust as needed (or I’ll help) to match your system and needs. The output as it stands will generate something like the following in the batch file:
c:\python27\Python C:\convert\manual.py -a -i “F:\TV Shows\Ongoing\Top Shot (2010)\Season 0\Top Shot - S00E01 - Additional Footage.MP4”
c:\python27\Python C:\convert\manual.py -a -i “F:\TV Shows\Ongoing\Top Shot (2010)\Season 0\Top Shot - S00E02 - Contestant Bios.MP4”
c:\python27\Python C:\convert\manual.py -a -i “F:\TV Shows\Ongoing\Top Shot (2010)\Season 0\Top Shot - S00E03 - Elimination Interviews.MP4”

Hope this helps!

Carlo

PS this one particular one above looks ONLY for MP4 files that aren’t “web optimized” (proper moov atom at start of file).

This would be the first iteration you would want to run. After this you can adjust it to look at things like ref frames, 10 bit color, no AAC as first track, or other types other than MP4.

Of course once you take care or your existing MP4s you can just run the normal conversion scripts against your library to take care of AVIs, MPG, MKV, etc.

I’ll help with the different iterations you will need but want to start you off with an EASY SQL to get your “feet wet”.

Is there a way to Have this script search for anything that is not MP4 and than convert accordingly? The issues i have is that sometimes i have to restart the server or have to close the conversion script and when i restart it it want to convert everything all over again.

My File structure:
Move and TV show Directory that contains all Plex content with a mix of file extensions
 ie
 mp4, avi, mkv.
X:/TV Shows
X:/Movies

I run the manual.py on the need directory. Lets say x: v shows and it starts from the first file and works it way down, but if it stops for any reason when i restart it will start all over even if the file is mp4.

FFMPEG settings with in autoprocess.ini
[MP4]
ffmpeg = ffmpeg.exe
ffprobe = ffprobe.exe
threads = auto
output_directory = E:\Newsgroups\Completed\DONE
copy_to =
move_to =
output_extension = mp4
output_format = mp4
delete_original = True
relocate_moov = True
video-codec = h265,x265
video-bitrate = 8
video-max-width =
h265-max-level = 4.1
use-qsv-decoder-with-encoder = True
ios-audio = True
ios-first-track-only = False
ios-audio-filter = dynaudnorm
max-audio-channels =
audio-codec = ac3,mp3,dts,dca,aac
audio-language = eng
audio-default-language = eng
audio-channel-bitrate = 256
audio-filter =
subtitle-codec = srt
subtitle-language = eng
subtitle-default-language =
subtitle-encoding =
fullpathguess = True
convert-mp4 = False
tagfile = False
tag-language = en
download-artwork = Poster
download-subs = True
embed-subs = False
sub-providers = addic7ed,podnapisi,thesubdb,opensubtitles
permissions = 0777
post-process = False
pix-fmt =
aac_adtstoasc = True
postopts =-preset,veryfast
preopts =
video-crf = 23