@stohle posted a new topic, subject "FFMPEG Script". It read:

   Hi. So i wrote this script to remux all videofiles to .mp4 but i think it looks really bad. It does its job, but can i rewrite it so it runs better?
    
    ` shopt -s globstar`
    
    `for f in **/ _.mov; do ffmpeg -y -i “ f" -c copy -sn "{f%.mov}.mp4”; done_`  
    `for f in **/.mkv; do ffmpeg -y -i “f" -c copy -sn "{f%.mkv}.mp4”; done`  
    `for f in **/ _.avi; do ffmpeg -y -i “ f" -c copy -sn "{f%.avi}.mp4”; done_`  
    `for f in **/.flv; do ffmpeg -y -i “f" -c copy -sn "{f%.flv}.mp4”; done`  
    `for f in **/ _.FLV; do ffmpeg -y -i “ f" -c copy -sn "{f%.FLV}.mp4”; done_`  
    `find . -name '.mov' -delete`  
    `find . -name ‘ _.mkv' -delete_`  
    `find . -name '.avi' -delete`  
    `find . -name ‘ _.flv' -delete_`  
    `find . -name '.FLV' -delete`
    
    now the script makes a duplicate of the videofile. example: remuxing a .mkv to .mp4. both videofiles is in the folder untill the end of the script where it gets deleted. I want ffmpeg to automatically detect the container and codecs. if it needs to remux then it remux, if it needs transcoding then transcode. also want the script to delete the original video file _**before**_ going to the next video file. i do not know how to write like that. i found bits and pieces on the interwebz and just tried out commands.
    
    Thanks

@JasonM replied

    > @stohle said:  
    >  Hi. So i wrote this script to remux all videofiles to .mp4 but i think it looks really bad. It does its job, but can i rewrite it so it runs better?
    
    Simply use Cayars redone scripts…
    
    Plex Forum – 30 Jan 16
    
    ### Cayars - Setup walk through and some tips and tricks
    
    @benamira: First, just want to say this is all @cayars and @MovieFan.Plex work, they were gracious enough to help me out. MP4 Converter Details and How to Install autoProcess.ini you can read more about this here sickbeard_mp4_converter, but...

@MikeG6.5 replied

    The problem with the OP getting to @cayars scripts is he posted that in a Pass only forum and the OP doesn't have a Pass.
    
    @cayars scripts are really cool. They strip out any language you haven't designated (but it has to be in the file to begin with) and makes an MP4, H264 with stereo AAC audio for the first audio track, and if available makes a DTS or AC3 5.1 as well. For every language you designate it to do. It also makes an srt sub title file for the language you designated, too. It deletes the original file, and you can run this without an output directory, so it puts the new file into the same folder as the original. If it's called via a script if can be completely automatic.
    
    Since this is @cayars' scripts, and not mine, I'll let him comment here if he wants to, about how to get to it. I'm not going to send 3 million people to his FTP without him clearing it first…

@cayars replied

    It's fine Mike. Here's a copy of the original post i made in my thread which is in the plex pass part of the site:
    
    Here is a set of scripts that you can use to automate mp4 creation of files.
    
    I'd recommend running your files through FileBot first to rename them correctly before running them through this script. It can pull SRT files so everything ends up with proper names this way.
    
    The only pre-requisite is to have python 2.7.9 installed. Python Release Python 2.7.9 | Python.org
    
    (I'm running 64bit version for windows installed to C:\Python27)
    
    This is a modified version of sickbeard_mp4_automator with modifications by me. I pulled out all the integration features to make setup much easier. I also modified it to produce higher quality MP4 files that will direct play better with Plex.
    
    Download convert.zip from ftp://ayars.tv
    
    username and password are both guest
    
    Unzip to C: drive. You will end up with C:\Convert
    
    There are two directories (can be changed) inside this folder that are used for the media
    
    Process is where you put any files you want to convert
    
    Done is where the files will end up after processing
    
    You can run this multiple ways but the easiest is to use the Run.bat file.
    
    If you edit this file you will notice it's one line that reads: c:\python27\python manual.py -a -i c:\convert\process
    
    If you install python to a different folder then change the python directory at the beginning of this line.
    
    If you want to process files from a different location then c:\convert\process then just change this in the batch file.
    
    If you want to change the final location of where the final files are stored then edit autoProcess.ini file and change the output_directory setting.
    
    That's pretty much it.
    
    Put files in the process directory and run the batch file
    
    What this will do:
    
    It will process each and every file in the “process” directory.
    
    It will remux files that are h.264 and will transcode files that aren't h.264 video
    
    It will pull out any english subtitles and create SRT files from them. If you want to pull out other languages then modify the subtitle-language setting in the ini file. Multiple languages are supported by commas
    
    The completed file will not have subtitles (we pulled them out)
    
    It will clear all tags in the mp4 file so Plex doesn't pick up and use these tags instead of the proper meta-data
    
    It will create an AAC track as the first track upto 256K in size.
    
    It will remove all audio tracks not in english. If you want other languages included modify audio-language setting (ini file) and include any languages you want kept in the MP4 file. Multiple languages are supported by commas
    
    When it transcodes it wil use an h.264 profile of high; a level of 4.0; crf setting of 20. These are basically the same as Handbrake High Profile settings with a bit more refinement for Plex use that allows it to direct play more often.
    
    In all cases the final MP4 file has the MOOV ATOM at the beginning of the file (ie web optimized)
    
    Advanced setting:
    
    You can limit the total bitrate for the video. If for example you use a client that has an upper limit of 12000 KB you can set the option video-bitrate option to something like 11000 which gives you a bit of headroom for a couple of audio tracks.
    
    There is more that can be done with this set of scripts but lets start off with these. 
    
    Let me know what you guys think,
    
    Carlo

So @stohle replied

    @cayars Thank you so much! i did find a website claiming to have your script but didnt trust the site. setting it up now. I am running Debian with Sonarr, Couchpotato, Deluge and SABnzbd. I've set SAB to download to the same folders as Deluge.
    
    Deluge download to incomplete, then moves completed to the folder completed  
    SAB download to the same folder and then moves it to the same folder as Deluge.  
    Sonarr and Couchpotato checks the “completed” folder for content and then move the files to another folder (TV-Series and Movies) which is the folders where Plex picks up content.
    
    my question is; how should I set up this with folders and stuff so the content get remuxed or whatever before they are moved to their respective folders?
    
    Download to “incomplete”, move to “remux” folder, run script, move to “complete” where sonarr and couchpotato handle the moving to their respective folders?
    
    i really need some guidance on this because this is new to me.
    
    thanks for helping me out!

To which @stohle replied

    It says “output_directory” in the autoprocess.ini file. wondering if that means that the converted file is being made in the output directory or somewhere else and then its moved when its 100% finished. dont want couchpotato and sonarr to pick up unfinished files. (sorry for my grammar. its 03:33 here)

Then @stohle said

    **Forget whats above this reply!**
    
    @cayars its up and running now but looks like i have to manually run `python manual.py` and enter the path.
    
    I changed the paths in **run.bat** and the output i get is:
    
    `Manual processor started.  
    64bit Python.`
    
    any fix for this?

Then @cayars said

    > @stohle said:  
    >  **Forget whats above this reply!**
    > 
    > @cayars its up and running now but looks like i have to manually run `python manual.py` and enter the path.
    > 
    > I changed the paths in **run.bat** and the output i get is:
    > 
    > `Manual processor started.  
    >  64bit Python.`
    > 
    > any fix for this?
    
    I'm a bit confused. Are you running Debian or Windows?

After which, @stohle added

    @cayars headless Debian to be exact

@techstacy replied

    Ran into several issues trying to run cayars script in a 32-bit WinXP environment. Here's how I got it to run: http://jdsworld.com/tech-support/ffmpeg-script-remux-video-files-mp4-winxp/

Then @pigpen1204 said

    @cayars Hope all is well! Love your script 
    
    Is there any way to ensure there is only 1 audio stream? English AAC 2 channel 256kbit?
    
    Basically I want to drop extra surround channels and just keep it at 2 channel.
    
    Thanks

@cayars replied

    Would you mind if I ask why you would want to do this? Audio is a very small part of total file size. Next month or next year you might very well wish you had more then 2 channel audio.

@pigpen1204 replied

    Hi @cayers, Thanks for the reply and sorry about the delay on the reply.
    
    I'm just working to converting everything to the most compatible file formats and what not obviously. And it seems that some players default to the 6 channel sound if it exists. When the secondary audio stream is copied is keeps the original codec. Some players (like shitty vizio TVs) will transcode by default due to this.
    
    Also, is there a way to print the FFMpeg command for each file processed (IE in the log or console output c:\convert\ffmpeg %source %args %outputfile).
    
    Love the script anywhich way! I've converted most of my library using it. I'll likely rerun it all if/when you can answer the above question.
    
    Thanks again!

So @kevindd992002 replied

    @cayars
    
    Why is it that sometimes it is very slow to convert a 500MB tv show file but most of the time it's very fast to convert a 1.5GB tv show file? This is on the same computer that's running the conversion.

So @kevindd992002 replied

    @cayars
    
    Help?

So @cayars replied

    Depends on the file. Lots of reasons. For example if the encoding level is 4.0 it might just remux the file while if the encoding level was 5.0 it will transcode it to get the level to what is specified in the ini file. It can use hardware encoding if available for many but not all transcodes.
    
    Then of course you have things like VC-1 encoding which will only do software encoding and can only use 1 core (ffmpeg limitation).
    
    There are many, many reasons. That's why the script is so useful because it looks at the file to begin with to determine what is needed and will perform the “fastest” method.

@kushfest replied

    Thank you, @cayars! The script looks like what I've been hoping to find to automate transcoding new additions to my library. Will this work on an ubuntu setup? If not, any suggestions as to what might?
    
    Also, I couldn't connect to the ftp. It seems to be down. Is there somewhere else I can grab the scripts?

@cayars replied

    I was doing some house cleaning. Try FTP again.
    
    Yes it will run on OS X, Windows and Linux.

Then @kushfest said

    Thank you very much. The FTP worked and I'm downloading now.  
    Looking forward to getting this setup on my server!

To which @kevinhundermark replied

    > @stohle said:  
    >  **Forget whats above this reply!**
    > 
    > @cayars its up and running now but looks like i have to manually run `python manual.py` and enter the path.
    > 
    > I changed the paths in **run.bat** and the output i get is:
    > 
    > `Manual processor started.  
    >  64bit Python.`
    > 
    > any fix for this?
    
    Hi @stohle \- did you figure out what had to be resolved to get past this issue above?  
    I am having the same output logged when i run the script.
    
    I'm running LinuxMint 18.1 and have Python 2.7.12 installed.

To which @chillywilly42 replied

    I have my movies in /Movies folder, each movie in its own folder.  
    can i use the batch file to:  
    read from the /Movies folder  
    output to that same folder for each movie (without manually changing the output location each time)?

Then @chillywilly42 said

    nevermind, i got it.  
    This a great script, thank you very much!

Then @GavCaz37 said

    Hi @cayers thanks again for this wonderful script and all your help troubleshooting!
    
    I have a little issue wherein the processed files end up with more subtitles in them than the originals (and are therefore a bit larger)… I was under the impression that the script would extract any subtitle files and save them as .srt's. It had done that a few times, but now seems to be often including multiple versions in the mp4 (I'm sure due to something in the autoProcess.ini file I tweaked, but I can't seem to figure it out).  
    Here are my current settings:
    
    subtitle-codec = mov_text  
    subtitle-language =eng  
    subtitle-default-language =  
    subtitle-encoding =  
    fullpathguess = True  
    convert-mp4 = True  
    tagfile = True  
    tag-language = en  
    download-artwork = Poster  
    download-subs = False  
    embed-subs = False  
    sub-providers = addic7ed,podnapisi,thesubdb,opensubtitles  
    permissions = 0777  
    post-process = False  
    pix-fmt =  
    aac_adtstoasc = False
    
    Any suggestions?

To which @GavCaz37 replied

    To clarify, what seems to happen in some cases is that a subtitle that consists of either a time stamp or Chapter heading (no dialog that I've seen) is added to the .mp4 during its processing. Here's the .ini settings I'm using:
    
    [MP4]  
    ffmpeg = ffmpeg  
    ffprobe = ffprobe  
    threads = auto  
    output_directory = /media/NASHDD1/CONVERT/done  
    copy_to =  
    move_to =  
    output_extension = mp4  
    output_format = mp4  
    delete_original = True  
    relocate_moov = True  
    video-codec = h264,x264  
    video-bitrate =  
    video-max-width =  
    h264-max-level = 4.0  
    use-qsv-decoder-with-encoder = True  
    ios-audio = False  
    ios-first-track-only = False  
    ios-audio-filter =  
    max-audio-channels = 2  
    audio-codec = aac,mp3,ac3,  
    audio-language = eng  
    audio-default-language = eng  
    audio-channel-bitrate = 256  
    audio-filter =  
    subtitle-codec = srt  
    subtitle-language = eng  
    subtitle-default-language = eng  
    subtitle-encoding =  
    fullpathguess = True  
    convert-mp4 = True  
    tagfile = True  
    tag-language = en  
    download-artwork = Poster  
    download-subs = False  
    embed-subs = False  
    sub-providers = addic7ed,podnapisi,thesubdb,opensubtitles  
    permissions = 0777  
    post-process = False  
    pix-fmt =  
    aac_adtstoasc = False

Then @kevindd992002 said

    @cayars
    
    Do you have any ideas on the latest question above?

So @cayars replied

    I don't see anything wrong. Can you take a look at one of these files with mediainfo both before and after conversion to see what they look like.

Then @SecurityMatters said

    So what exactly is the BEST way to convert MKV to MP4 automatically then? Seen a few different scripters out there, and I am sick of using MKVtoMP4 manually nonstop.
    
    I'm no pro so I don't need the hardest route of coding requirements. I am not an idiot either. I have python installed for PlexPy, have automated scripts for SAB/Sonarr but just sick of all the MKVs creating endless transcoding and converting them 1by1 is just as bad as manually searching and would never end! Thanks in advance

So @danbooth replied

    @cayars I am unable to download the file you reference in this post. When looking at your domain it appears to be resolving your internal network. Is this file posted in another location? Thanks!!!
    
    dig ayars.tv
    
    ; <<>> DiG 9.8.3-P1 <<>> ayars.tv  
    ;; global options: +cmd  
    ;; Got answer:  
    ;; ->>HEADER<<\- opcode: QUERY, status: NOERROR, id: 44029  
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
    
    ;; QUESTION SECTION:  
    ;ayars.tv. IN A
    
    ;; ANSWER SECTION:  
    ayars.tv. 164 IN A +1-281-277-1553
    
    ;; Query time: 4 msec  
    ;; SERVER: {{PHONE+PHONE}})  
    ;; WHEN: Sat Sep 30 15:07:05 2017  
    ;; MSG SIZE rcvd: 42

To which @kevindd992002 replied

    @cayars
    
    Are you still willing to help us here? You don't answer anymore

Then @cayars said

    I don't really read this thread unless it happens to hop anthony87@example.org. if you post in the cayars thread you'll get help from me or from others who use the script.

After which, @cayars added

    > @danbooth said:  
    >  @cayars I am unable to download the file you reference in this post. When looking at your domain it appears to be resolving your internal network. Is this file posted in another location? Thanks!!!
    > 
    > dig ayars.tv
    > 
    > ; <<>> DiG 9.8.3-P1 <<>> ayars.tv  
    >  ;; global options: +cmd  
    >  ;; Got answer:  
    >  ;; ->>HEADER<<\- opcode: QUERY, status: NOERROR, id: 44029  
    >  ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
    > 
    > ;; QUESTION SECTION:  
    >  ;ayars.tv. IN A
    > 
    > ;; ANSWER SECTION:  
    >  ayars.tv. 164 IN A +1-281-277-1553
    > 
    > ;; Query time: 4 msec  
    >  ;; SERVER: {{PHONE+PHONE}})  
    >  ;; WHEN: Sat Sep 30 15:07:05 2017  
    >  ;; MSG SIZE rcvd: 42
    
    It's posted in the cayars forum thread moving forward.

After which, @kevindd992002 added

    > @cayars said:  
    >  I don't really read this thread unless it happens to hop anthony87@example.org. if you post in the cayars thread you'll get help from me or from others who use the script.
    
    I'm sorry, I didn't know there was a cayars thread! I'll look for it and hit you up

After which, @zerolim1t added

    trying to get the script for web optimize but your ftp isn't working. Could I get access to it please

After which, @cayars added

    2 messages above

Then @erthqke said

    Hi cayars, where can I find your thread, so that I may request the proper ftp credentials for convert.zip? Trying to use the proper forum per your request above.

After which, @system added

    


{'source': 'discourse', 'url': 'https://forums.plex.tv/t/ffmpeg-script/144353', 'title': 'FFMPEG Script', 'views': 5675, 'has_accepted_answer': False, 'word_count': 2970, 'like_count': 0, 'reply_count': 1, 'participant_count': 15, 'posts': 36, 'tags': 'other-dev', 'author': '@stohle', 'participants': '@stohle, @JasonM, @MikeG6.5, @cayars, @techstacy, @pigpen1204, @kevindd992002, @kushfest, @kevinhundermark, @chillywilly42, @GavCaz37, @SecurityMatters, @danbooth, @zerolim1t, @erthqke, @system', 'image_url': [None], 'created_at': '2016-05-06T05:53:17.000Z', 'last_posted_at': '2020-01-08T19:57:25.189Z'}