2

I have roughly 10 files that I want to run through this fairly simple command

ffmpeg -i "INPUT" -map 0:0 -map 0:1 -c:v copy -c:a ac3 "OUTPUT"

Usually I would do each file seperately and run 10 seperate command prompt windows so I was wondering if there is any way to run all the commands together?

2

1 Answer 1

1

Using Python:

ex. ffmpeg-copy.py

import os
import os.path
import subprocess

# What directory do we wish to work with?
# '.' is shorthand for the current directory.
root_dir = '.'

# What type of files are we looking for?
# prefix = 'image_'
# ext = '.png'
ext = '.mp4'

# Lists to hold directory item names
included_files = []
skipped_files = []
directories = []

# Get a list of items in our root_dir
everything = []
everything = os.listdir(root_dir)

# For each of the items in our root_dir
for item in everything:

    # Get the full path to our item
    temp_item = os.path.join (root_dir, item)

    # If our item is a file that ends with our selected extension (ext), put
    # its name in our included_files list. Otherwise, put its name in either
    # our skipped_files or directories lists, as appropriate.
    if os.path.isfile(temp_item):
        #if item.startswith(prefix) and item.endswith(ext):
        if item.endswith(ext):
            included_files.append(item)
        else:
            skipped_files.append(item)
    else:
        directories.append(item)

# Visual aid
print('')

# Process our included_files with ffmpeg
for file in included_files:

    input_file = file

    # Get just the base file name, excluding any extension
    output_file = os.path.splitext(file)[0]

    # Form our final output name e.g. example-output.mp4
    output_file += '-output' + ext

    ffmpeg_command = 'ffmpeg -i "' + input_file + \
                     '" -map 0:0 -map 0:1 -c:v copy -c:a ac3 "' + \
                     output_file + '"'

    # Run our ffmpeg command on our file
    try:
        print(ffmpeg_command)
        print('')
        subprocess.run(ffmpeg_command)
    except CalledProcessError as err:
        print('')
        print(err)
        exit()

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .