Run an FFmpeg command and see the percentage progress and ETA.

Overview

better-ffmpeg-progress

A command line program that runs an FFmpeg command and shows the following in addition to the FFmpeg output:

  • Percentage Progress
  • Speed
  • ETA (minutes and seconds)

Example: Progress: 25% | Speed: 22.3x | ETA: 1m 33s

Usage

python3 better_ffmpeg_progress.py -c "ffmpeg -i input.mp4 -c:a libmp3lame output.mp3"

I have also included a function, which can be imported and used in your own Python program or script:

run_ffmpeg_show_progress("ffmpeg -i input.mp4 -c:a libmp3lame output.mp3")

Comments
  • [BUG] local variable 'progress_bar' referenced before assignment

    [BUG] local variable 'progress_bar' referenced before assignment

    HI, after runnning the primary example with some minor modifications I got an exception. I'm running version 2.0.5.

    Code:

    from better_ffmpeg_progress import FfmpegProcess
    # Pass a list of FFmpeg arguments, like you would if using subprocess.run()
    process = FfmpegProcess(["ffmpeg", "-i", "./music/arctic.flac", "-c:a", "libopus", "-b:a", "64k", "arctic.mka"])
    # Use the run method to run the FFmpeg command.
    process.run()
    

    Exception:

    Traceback (most recent call last):
      File "[REDACTED].py", line 5, in <module>
        process.run()
      File "[REDACTED]/.venv/lib/python3.10/site-packages/better_ffmpeg_progress/better_ffmpeg_progress.py", line 114, in run
        progress_bar.close()
    UnboundLocalError: local variable 'progress_bar' referenced before assignment
    
    opened by abreumatheus 7
  • Feature: Add estimated file size

    Feature: Add estimated file size

    I was able to add an estimated file size that seems to estimate okay after a few progress updates. It checks for changes because ffmpeg sporadically writes to disk and it's probably the most accurate when it writes.

                    totalSize = 0;
                    prevTotalSize = 0;
                    etaSize = "unknown"
    
                                                    if "total_size" in ffmpeg_output:
                                                            totalSize = int(ffmpeg_output.split("=")[1]);
                                                            if(percentage != "unknown" and percentage > 0):
                                                                    if(totalSize != prevTotalSize):
                                                                            prevTotalSize = totalSize;
                                                                            etaSize = int(totalSize * (100 / percentage))
                                                                            if(etaSize > (1024*1024*1024)):
                                                                                    etaSize = str(round(etaSize / (1024*1024*1024), 2)) + "G";
                                                                            elif(etaSize > (1024*1024)):
                                                                                    etaSize = str(round(etaSize / (1024*1024), 2)) + "M";
                                                                            elif(etaSize > 1024):
                                                                                    etaSize = str(round(etaSize / (1024), 2)) + "K";
    
                                                    elif "out_time_ms" in ffmpeg_output:
                                                            microseconds = int(ffmpeg_output[12:])
                                                            secs = microseconds / 1_000_000
                                                            if file_duration is not None:
                                                                    percentage = round((secs / file_duration) * 100, 1)
    
                                                    elif "speed" in ffmpeg_output:
                                                            speed = ffmpeg_output.split("=")[1].strip()
                                                            speed = 0 if " " in speed or "N/A" in speed else float(speed[:-1])
                                                            if speed != 0:
                                                                    eta = (file_duration - secs) / speed
                                                                    seconds = round(eta % 60)
                                                                    minutes = int(eta / 60)
                                                                    hours = int(minutes / 60)
                                                                    minutes = round(minutes % 60)
                                                                    eta_string = f"{hours}:{minutes:02d}:{seconds:02d}"
    
                                                            if progress_handler is None:
                                                                    print(f"Progress: {percentage}% | Speed: {speed}x | ETA: {eta_string} | Estimated Size: {etaSize}    ", end="\r")
                                                            else:
                                                                    progress_handler(percentage, f"{speed}x", eta)
    
    enhancement 
    opened by jmraker 6
  • [Error] float division by zero

    [Error] float division by zero

    Hi,

    when I run the script with the progress_handler I see the error message:

    (env) [xxxx]$ /Users/[xxxx]/env/bin/python [xxxx]test_runner.py Running: ffmpeg -y -i [xxxx] -c:a libmp3lame -y output.mp3 -loglevel verbose -progress pipe:1 -nostats 0%| | 0/384.304 [00:00<?, ?s/s] [Error] float division by zero Exiting Better FFmpeg Progress.

    The code below:

    from better_ffmpeg_progress import FfmpegProcess

    def handle_progress_info(percentage): print(f"The FFmpeg process is {percentage}% complete. ETA is / seconds.")

    process = FfmpegProcess(["ffmpeg", "-i", "[xxxx]", "-c:a", "libmp3lame", "-y", "output.mp3"], ) process.run(progress_handler=handle_progress_info)

    opened by janciev 3
  • Add a callback event?

    Add a callback event?

    Adding an optional callback/event that passes the 3+ numbers (and maybe the process handle) when needed might be useful for those who want to customize the output to . Add ANSI colors . Put the info into a GUI . Reword/translate something or represent it as ASCII art. . Remove or re-arrange things

    opened by jmraker 3
  • 'estimated_size' referenced before assignment

    'estimated_size' referenced before assignment

    from better_ffmpeg_progress import FfmpegProcess
    
    
    def handle_progress_info(percentage, speed, eta, estimated_filesize):
        print(f"The FFmpeg process is {percentage}% complete. ETA is {eta} seconds.")
    
    
    # Pass a list of FFmpeg arguments, like you would if using subprocess.run()
    process = FfmpegProcess(["ffmpeg", "-i", "/home/freetalk/Opinie over Auschwitz vakantiekamp VRT.mp4", "-c:v", "libvpx-vp9", "-threads", "8", "/home/freetalk/Opinie.webm"])
    
    # Use the run method to run the FFmpeg command.
    process.run(progress_handler=handle_progress_info)
    

    CLI output:

    The duration of /home/freetalk/Opinie over Auschwitz vakantiekamp VRT.mp4 has been detected as 2561.302 seconds.
    Running: ffmpeg -y -i /home/freetalk/Opinie over Auschwitz vakantiekamp VRT.mp4 -c:v libvpx-vp9 -threads 8 /home/freetalk/Opinie.webm -hide_banner -loglevel verbose -progress pipe:1 -nostats
      0%|                                                                                                                               | 0/2561.3030000000003 [00:00<?, ?s/s]
    [Error] local variable 'estimated_size' referenced before assignment
    Exiting Better FFmpeg Progress.
    
    opened by wtechgo 1
Owner
null
Enlighten Progress Bar is a console progress bar library for Python.

Overview Enlighten Progress Bar is a console progress bar library for Python. The main advantage of Enlighten is it allows writing to stdout and stder

Rockhopper Technologies 265 Dec 28, 2022
CLI Utility to encode and recursively recreate directories with ffmpeg.

FFenmass CLI Utility to encode and recursively recreate directories with ffmpeg. Report Bug · Request Feature Table of Contents Getting Started Prereq

George Av. 8 May 6, 2022
A simple file transfer tools, similar to rz / sz but compatible with tmux (control mode), which works with iTerm2 and has a nice progress bar

trzsz A simple file transfer tools, similar to rz/sz but compatible with tmux (control mode), which works with iTerm2 and has a nice progress bar. Why

null 561 Jan 5, 2023
Multifunctional library for creating progress bars.

?? Content Installation Using github Using pypi Quickstart Flags Useful links Documentation Pypi Changelog TODO Contributing FAQ Bar structure ⚙️ Inst

DenyS 27 Jan 1, 2023
A python package to display progress of loops to the user

ProgressBars A python package to display progress of loops to the user. Installation This package can be installed using pip. pip install progressbars

Matthias 3 Jan 16, 2022
Squirrel - A cli program to track writing progress

Squirrel Very much a WIP project squirrel is a command line program that tracks you writing progress and gives you useful information and cute and pic

null 3 Mar 23, 2022
Loading animation; a progress bar

Loading animation; a progress bar. When you know the remaining time or task completion percentage, then you’re able to show an animated progress bar:

Goldy 1 Jan 23, 2022
🏃 Python3 Solutions of All Problems in GCJ 2022 (In Progress)

GoogleCodeJam 2022 Python3 solutions of Google Code Jam 2022. Solution begins with * means it will get TLE in the largest data set. Total computation

kamyu 12 Dec 20, 2022
Shortcut-Maker - It is a tool that can be set to run any tool with a single command

Shortcut-Maker It is a tool that can be set to run any tool with a single command Coded by Dave Smith(Owner of Sl Cyber Warriors) Command list ?? pkg

Dave Smith 10 Sep 14, 2022
A command-line based, minimal torrent streaming client made using Python and Webtorrent-cli. Stream your favorite shows straight from the command line.

A command-line based, minimal torrent streaming client made using Python and Webtorrent-cli. Installation pip install -r requirements.txt It use

Jonardon Hazarika 17 Dec 11, 2022
A cd command that learns - easily navigate directories from the command line

NAME autojump - a faster way to navigate your filesystem DESCRIPTION autojump is a faster way to navigate your filesystem. It works by maintaining a d

William Ting 14.5k Jan 3, 2023
commandpack - A package of modules for working with commands, command packages, files with command packages.

commandpack Help the project financially: Donate: https://smartlegion.github.io/donate/ Yandex Money: https://yoomoney.ru/to/4100115206129186 PayPal:

null 4 Sep 4, 2021
AML Command Transfer. A lightweight tool to transfer any command line to Azure Machine Learning Services

AML Command Transfer (ACT) ACT is a lightweight tool to transfer any command from the local machine to AML or ITP, both of which are Azure Machine Lea

Microsoft 11 Aug 10, 2022
Ros command - Unifying the ROS command line tools

Unifying the ROS command line tools One impairment to ROS 2 adoption is that all

null 37 Dec 15, 2022
A Python-based command prompt concept which includes windows command emulation.

PythonCMD A Python-based command prompt concept which includes windows command emulation. Current features: echo: Input your message and it will be cl

null 1 Feb 5, 2022
Pymongo based CLI client, to run operation on existing databases and collections

Mongodb-Operations-Console Pymongo based CLI client, to run operation on existing databases and collections Program developed by Gustavo Wydler Azuaga

Gus 1 Dec 1, 2021
A Python script for finding a food-truck based on latitude and longitude coordinates that you can run in your shell

Food Truck Finder Project Description This repository contains a Python script for finding a food-truck based on latitude and longitude coordinates th

null 1 Jan 22, 2022
Seamlessly run Python code in IPython from Vim

Seamlessly run Python code from Vim in IPython, including executing individual code cells similar to Jupyter notebooks and MATLAB. This plugin also supports other languages and REPLs such as Julia.

Hans Chen 269 Dec 20, 2022
Ipylivebash - Run shell script in Jupyter with live output

ipylivebash ipylivebash is a library to run shell script in Jupyter with live ou

Ben Lau 6 Aug 27, 2022