Getting realtime progress of ffmpeg / subprocess

Hey Folks

Our playblast tools have some optional calls to ffmpeg through subprocess, sometimes it can take a while. I’d love to show the user a progress bar but I’m struggling to get realtime output, I can only seem to get output all at once when it’s done.

Dunno if this is even possible in Maya with subproess, or if I have to use QProcess or something else.

Here’s an example of part of a thing to take 2 playblasts and stack them vertically

import subprocess

ffmpeg_path = "C:/ffmpeg/bin/ffmpeg.exe"

pb_folder = "C:/playblasts/"
file1_path = pb_folder + "playblast1.mp4"
file2_path = pb_folder + "playblast2.mp4"
outFile_path = pb_folder + "playblast_stacked.mov"

cmd = [ffmpeg_path,"-y", '-i', file1_path, "-i", file2_path, "-filter_complex", "vstack", outFile_path]
    
# run the cmd
process = subprocess.Popen(cmd, stderr=subprocess.PIPE, universal_newlines=True)

# print the output
output, error = process.communicate()

if output:
      print "success ",output
else:
      print "error ",error

EDIT:

OK this will do it:

import subprocess

ffmpeg_path = "C:/ffmpeg/bin/ffmpeg.exe"

pb_folder = "C:/playblasts/"
file1_path = pb_folder + "playblast1.mp4"
file2_path = pb_folder + "playblast2.mp4"
outFile_path = pb_folder + "playblast_stacked.mov"

cmd = [ffmpeg_path,"-y", '-i', file1_path, "-i", file2_path, "-filter_complex", "vstack", outFile_path]
    
# run the cmd
process = subprocess.Popen(cmd,
                    stdout=subprocess.PIPE,
                    stderr=subprocess.STDOUT,
                    universal_newlines=True)

for line in iter(process.stdout.readline, b''):
    print(">>> " + line.rstrip())

Then as you read the lines, instead of printing them as I do here, I can get the currently processing frame from the line and compare is to the frame length of the file to get the progress.

2 Likes

Check out ffmpeg-bar.