none
Using FFMpeg commands to run a recursive input location and mirror the output location RRS feed

  • Question

  • Note: If this is the wrong forum, I apologize. I wasnt 100% sure where this should be asked.   

    Command line modules in use: FFMPeg (http://ffmpeg.tv/) - remuxes media files from one container type to another. 

    I am currently in the process of remuxing my video files to MP4 for use on my devices which do not support MKV format. Using the commands that are suggested by my Media Server interface (found at https://support.plex.tv/articles/201097958-remuxing-files-to-mkv/) allows me to specify the source file path and the destination file path. 

    My current file paths look as follows: 
    %userprofiles%\Documents\Plex\MKV\TV Shows\Show Name\Season ##\Show name - S##E## - Episode Name.mkv
    %userprofiles%\Documents\Plex\MP4\TV Shows\Show Name\Season ##\Show name - S##E## - Episode Name.mp4
    %userprofiles%\Documents\Plex\MKV\Movies\Movie Name (Year)\Movie Name.mkv
    %userprofiles%\Documents\Plex\MP4\Movies\Movie Name (Year)\Movie Name.mp4
    %userprofiles%\Documents\Plex\MKV\Movies\Movie Name (Year)\Extras\Title.mkv
    %userprofiles%\Documents\Plex\MP4\Movies\Movie Name (Year)\Extras\Title.mp4

    I am currently using the cd command to navigate to the directory where mkv files are located and then running the command line (where ****\****\ is the levels below the MP4 level): 

    for %i in (*.mkv) do c:\ffmpeg\bin\ffmpeg -i "%i" -c copy -map 0 %userprofile%\Documents\Plex\MP4\****\****\%~ni.mp4"

    This is results in the mkv files being copied and converted into files located in the directory structure that I specify under the MP4 folder. 

    I have already been able to convert my current commands to: 

    for /r %i in (*.mkv) do c:\ffmpeg\bin\ffmpeg -i "%userprofile%\documents\plex\mkv\%i" -c copy -map 0 %userprofile%\documents\plex\mp4\%~ni.mp4"

    This results in the files that are in the all of the sub-folders being copied and converted into an mp4 container format and then dumped into the MP4 folder together. I then have to go into the folder and move them into the correct sub-folders. 

    I would like to be able to adjust my current working recursive commands to be able to place the converted file copies into the same sub-folder structure that the MKV is in. 

    I.E. %userprofile%\Documents\Plex\MKV\TV Shows\Some Show\Season 01\Some Show - S01E01 - This is just an example show.mkv being copied and converted to %userprofile%\Documents\Plex\Mp4\TV Shows\Some Show\Season 01\Some Show - S01E01 - This is just an example show.mp4

    My ultimate end goal is to be able to have a scheduled task that runs once a month to take anything in the specified folder upper level folder and have it output to the same folder structure under the MP4 level.  Any input would be appreciated.


    • Edited by Majnara Friday, January 10, 2020 10:03 PM added note about forum
    Friday, January 10, 2020 10:00 PM

All replies

  • Please post issues with your program to the vendors site. This is not a vendor support forum and not a forum for end users using third party products. This is a forum for administrators and technicians doing scripting

    Also batch languages are obsolete,  The current default script language for Windows is PowerShell.

    If you want to do this in PowerShell then search in the Gallery and these forums for examples of how to move/copy files with the folder structure.  Almost the same exact question has been asked a number of times in the last week.  This threads will give you all you need to write a script.

    At this time there are very few if any people who write batch scripts.  There are other sites that still post about batch but they are disappe3aring rapidly.

    Good luck.


    \_(ツ)_/

    Friday, January 10, 2020 11:04 PM
  • Here's a little Powershell script that used to convert .wma to .mp3. My music is organized by Artist/Album so the .mp3 files are put back into the same folder as the .wma file. You'll have to modify it for your directory requirements.  

    cls
    $files = Get-ChildItem -Path C:\Multimedia\Music -Filter *.wma -Recurse
    foreach ($f in $files) {
         ""
         $f.fullname
         & C:\Utils\FFmpeg\bin\ffmpeg.exe -y -i "$($f.Fullname)"  -b:a 128k "$($f.Directory)\$($f.baseName).mp3"
    }

     
    Friday, January 10, 2020 11:25 PM
  • Here's a little Powershell script that used to convert .wma to .mp3. My music is organized by Artist/Album so the .mp3 files are put back into the same folder as the .wma file. You'll have to modify it for your directory requirements.  

    cls
    $files = Get-ChildItem -Path C:\Multimedia\Music -Filter *.wma -Recurse
    foreach ($f in $files) {
         ""
         $f.fullname
         & C:\Utils\FFmpeg\bin\ffmpeg.exe -y -i "$($f.Fullname)"  -b:a 128k "$($f.Directory)\$($f.baseName).mp3"
    }

     

    Nice. Cleaner and easier to modify than batch but the issue of copying the folder structure is the problem.

    A simple way to do that is to use RoboCopy to copy the files and folder structure than using your code to convert the files in-place in the new location. Fast and trivial.


    \_(ツ)_/

    Friday, January 10, 2020 11:44 PM
  • I'd just iterate thru the MKV folders/files and convert the files that did not exist in the mp4 folder.

    foreach…   

    Do a .replace() on the directory name to change MKV to mp4. Get the destination directory and file names.

    test-path to see if the mp4 file exists. Else..  

    test-path to see if the destination directory exists.

    new-item to create it if it's not there. 

    call ffmpeg. 

     Thought I'd give Majnara an opportunity to play around and learn some powershell.

     
    Saturday, January 11, 2020 12:59 AM