Skip to content

Instantly share code, notes, and snippets.

@donovankeith
Last active September 3, 2018 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save donovankeith/533051c65a534653a9a7cb386016b72b to your computer and use it in GitHub Desktop.
Save donovankeith/533051c65a534653a9a7cb386016b72b to your computer and use it in GitHub Desktop.
Variable Framerate .mov to 30 fps mp4 Converter Batch Script Generator

FFmpeg Convert to non-variable 30 FPS MP4

NOTE: For the most recent version of this Script, please go to this GitHub Gist

This Python Script searches for all video files matching a specific pattern in the same directory (sub-directories not included) and then generates a Windows Batch Script (UseOnce.cmd) you can then execute to convert those matching video files into Non-Variable 30fps MP4s.

Background

At Cineversity.com we often find ourselves converting large numbers of poorly formed .mov files to 30 FPS non-variable .mp4 files so that we can edit C4DLive Rewinds. FFmpeg is the best solution to this problem that we've discovered. Unfortunately, it's a pain to manually convert a bunch of files, so I've developed this set of scripts.

Instructions

  1. Ensure your computer matches the Requirements.

    • Requirements
      • Windows
      • FFmpeg must be installed and accessible as ffmpeg from the Windows Command Line
      • Python 2.6 is Installed (I'm using print "Hello World" rather than print("Hell World"))
      • If your system doesn't meet these requirements, this script won't work.
  2. Copy buildConverterBatch.py into the same directory as your video files.

  3. Edit buildConverterBatch.py in a text editor to match the naming of your files. Specifically:

    source_prefix = "18_NAB_SCREEN"
    source_suffix = ".mov"
    destination_suffix = "_30fps.mp4"
  4. Save your edited file.

  5. Tap the Windows key on your keyboard and type command then hit Enter.

  6. Drag the buildConverterBatch.py file into the command prompt. Hit Enter. You should see something like:

    ================================================================================
    Generate Ffmpeg Converter Script
    Creates a  Windows Batch file for converting files to constant 30fps with Ffmpeg
    
    Note: Open this file in a Text Editor and change the values under `# USER INPUT`
    if you would like something other than default behavior.
    ================================================================================
    
    Searching E:\NAB_18_BU\Captures\Sabour_Day3_20180411 for 18_NAB_SCREEN*.mov
    
    MATCH: 18_NAB_Screen-4_11_2018-1_34_PM-1523478892_1.mov
    MATCH: 18_NAB_Screen-4_11_2018-1_34_PM-1523478892_2.mov
    MATCH: 18_NAB_Screen-4_11_2018-1_34_PM-1523478892_3.mov
    MATCH: 18_NAB_Screen-4_11_2018-1_34_PM-1523478892_4.mov
    
    Generating UseOnce.cmd...
    
    SUCCESS: Double click on UseOnce.cmd to convert matched files.
    
  7. The buildConverterBatch.py script will create a file named UseOnce.cmd that will looks something like:

    REM UseOnce.cmdREM Batch converts files in this directory to 30fps.
    Ffmpeg -i E:\NAB_18_BU\Captures\Sabour_Day3_20180411\18_NAB_Screen-4_11_2018-1_34_PM-1523478892_1.mov -r 30 E:\NAB_18_BU\Captures\Sabour_Day3_20180411\18_NAB_Screen-4_11_2018-1_34_PM-1523478892_1_30fps.mp4
    Ffmpeg -i E:\NAB_18_BU\Captures\Sabour_Day3_20180411\18_NAB_Screen-4_11_2018-1_34_PM-1523478892_2.mov -r 30 E:\NAB_18_BU\Captures\Sabour_Day3_20180411\18_NAB_Screen-4_11_2018-1_34_PM-1523478892_2_30fps.mp4
    Ffmpeg -i E:\NAB_18_BU\Captures\Sabour_Day3_20180411\18_NAB_Screen-4_11_2018-1_34_PM-1523478892_3.mov -r 30 E:\NAB_18_BU\Captures\Sabour_Day3_20180411\18_NAB_Screen-4_11_2018-1_34_PM-1523478892_3_30fps.mp4
    Ffmpeg -i E:\NAB_18_BU\Captures\Sabour_Day3_20180411\18_NAB_Screen-4_11_2018-1_34_PM-1523478892_4.mov -r 30 E:\NAB_18_BU\Captures\Sabour_Day3_20180411\18_NAB_Screen-4_11_2018-1_34_PM-1523478892_4_30fps.mp4
    
  8. If everything looks correct, run UseOnce.cmd and make yourself a pot of coffee, it's going to be a long wait.

Credits

This script was developed by Donovan Keith for Cineversity.com and is Copyright (C) 2018 Maxon Computer Inc.

License

MIT License

Copyright (c) 2018 Maxon Computer Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""Generate Ffmpeg Converter Script
Creates a Windows Batch file for converting files to constant 30fps with Ffmpeg
Note: Open this file in a Text Editor and change the values under `# USER INPUT`
if you would like something other than default behavior."""
# IMPORTS
import os
import fnmatch
# USER INPUT
source_prefix = "18_NAB_SCREEN"
source_suffix = ".mov"
destination_suffix = "_30fps.mp4" # Must be different from `source_suffix`
# MAIN
def main():
line_width = 80
print "\n"
print "="*line_width
print __doc__
print "="*line_width
current_directory = os.getcwd()
file_list = os.listdir(current_directory)
filename_pattern = "%s*%s" % (source_prefix, source_suffix)
batch_commands = []
print "\nSearching " + current_directory + " for " + filename_pattern + "\n"
for filename in file_list:
if not fnmatch.fnmatch(filename, filename_pattern):
continue
print "MATCH: " + filename
source_file = filename
destination_file = filename
destination_file = destination_file.replace(source_suffix, destination_suffix)
if source_file == destination_file:
print "\nERROR: Destination file will overwrite source file! Open this .py file "
print "and modify it so they don't."
print "\nEXIT"
return
batch_command = "Ffmpeg -i %s -r 30 %s" % (os.path.abspath(source_file), os.path.abspath(destination_file))
batch_commands.append(batch_command)
if not batch_commands:
print "ERROR: Unable to find any matching files."
return
output_filename = "UseOnce.cmd"
print "\nGenerating " + output_filename + "..."
f = open(output_filename, "w+")
f.write("REM UseOnce.cmd")
f.write("REM Batch converts files in this directory to 30fps.\n")
for batch_command in batch_commands:
f.write(batch_command + "\n")
f.close()
print "\nSUCCESS: Double click on " + output_filename + " to convert matched files."
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment