Welcome to our forums! Please take a few moments to read through our Community Guidelines (also conveniently linked in the header at the top of each page). There, you'll find guidelines on conduct, tips on getting the help you may be searching for, and more!

FFMPEG Script

stohlestohle Members Posts: 9 ✭✭

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 **/<em>.mov; do ffmpeg -y -i "$f" -c copy -sn "${f%.mov}.mp4"; done
for f in **/</em>.mkv; do ffmpeg -y -i "$f" -c copy -sn "${f%.mkv}.mp4"; done
for f in **/<em>.avi; do ffmpeg -y -i "$f" -c copy -sn "${f%.avi}.mp4"; done
for f in **/</em>.flv; do ffmpeg -y -i "$f" -c copy -sn "${f%.flv}.mp4"; done
for f in **/<em>.FLV; do ffmpeg -y -i "$f" -c copy -sn "${f%.FLV}.mp4"; done
find . -name '</em>.mov' -delete
find . -name '<em>.mkv' -delete
find . -name '</em>.avi' -delete
find . -name '<em>.flv' -delete
find . -name '</em>.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

Tagged:

Best Answer

«1

Answers

  • JasonMeudtJasonMeudt Members, Plex Pass Posts: 217 Plex Pass

    @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...

    https://forums.plex.tv/discussion/comment/1117614/#Comment_1117614

    • Intel Core i7 4790 @ 3.6 Mhz (Plex Server)
    • Netgear R7000 (Tomato by Toastman firmware)
    • 2x Google Chromecast V2 (Media Player)
    • 3x Roku (Media Player)
    • 10 TB of Storage Space
  • MikeG6.5MikeG6.5 Members, Plex Pass Posts: 2,418 Plex Pass

    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... :)

  • stohlestohle Members Posts: 9 ✭✭

    @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!

  • stohlestohle Members Posts: 9 ✭✭

    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)

  • stohlestohle Members Posts: 9 ✭✭

    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.<br /> 64bit Python.

    any fix for this?

  • cayarscayars Members, Plex Pass, Plex Ninja Posts: 3,962 Plex Ninja

    @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.<br /> 64bit Python.

    any fix for this?

    I'm a bit confused. Are you running Debian or Windows?

    9,500 Movies, 380 Shows - 32,860 TV Episodes, 380 Christmas Movies, 400 Documentary, 270 3D Movies, 1300 NFL Games, 1280 Educational Videos, Premium Music: 215,560 Tracks, 715 GB Plex Meta-Data.
    Thread on my setup with some tips and tricks: https://forums.plex.tv/discussion/131308/cayars-setup-walk-through-and-some-tips-and-tricks/p1
  • stohlestohle Members Posts: 9 ✭✭

    @cayars headless Debian to be exact

  • techstacytechstacy Members, Plex Pass Posts: 2 Plex Pass

    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/

  • pigpen1204pigpen1204 Members, Plex Pass Posts: 2 Plex Pass

    @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 :)

  • cayarscayars Members, Plex Pass, Plex Ninja Posts: 3,962 Plex Ninja

    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.

    9,500 Movies, 380 Shows - 32,860 TV Episodes, 380 Christmas Movies, 400 Documentary, 270 3D Movies, 1300 NFL Games, 1280 Educational Videos, Premium Music: 215,560 Tracks, 715 GB Plex Meta-Data.
    Thread on my setup with some tips and tricks: https://forums.plex.tv/discussion/131308/cayars-setup-walk-through-and-some-tips-and-tricks/p1
  • pigpen1204pigpen1204 Members, Plex Pass Posts: 2 Plex Pass
    edited February 1

    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 **** 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!

  • kevindd992002kevindd992002 Members Posts: 125 ✭✭
    edited February 12

    @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.

  • kevindd992002kevindd992002 Members Posts: 125 ✭✭

    @cayars

    Help?

  • cayarscayars Members, Plex Pass, Plex Ninja Posts: 3,962 Plex Ninja

    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.

    9,500 Movies, 380 Shows - 32,860 TV Episodes, 380 Christmas Movies, 400 Documentary, 270 3D Movies, 1300 NFL Games, 1280 Educational Videos, Premium Music: 215,560 Tracks, 715 GB Plex Meta-Data.
    Thread on my setup with some tips and tricks: https://forums.plex.tv/discussion/131308/cayars-setup-walk-through-and-some-tips-and-tricks/p1
  • kushfestkushfest Members, Plex Pass Posts: 14 Plex Pass

    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?

  • cayarscayars Members, Plex Pass, Plex Ninja Posts: 3,962 Plex Ninja

    I was doing some house cleaning. Try FTP again.

    Yes it will run on OS X, Windows and Linux.

    9,500 Movies, 380 Shows - 32,860 TV Episodes, 380 Christmas Movies, 400 Documentary, 270 3D Movies, 1300 NFL Games, 1280 Educational Videos, Premium Music: 215,560 Tracks, 715 GB Plex Meta-Data.
    Thread on my setup with some tips and tricks: https://forums.plex.tv/discussion/131308/cayars-setup-walk-through-and-some-tips-and-tricks/p1
  • kushfestkushfest Members, Plex Pass Posts: 14 Plex Pass

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

  • kevinhundermarkkevinhundermark Members Posts: 1 Plex Pass

    @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.<br /> 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.

  • chillywilly42chillywilly42 Members Posts: 2

    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)?

«1
Sign In or Register to comment.