Coders Packet

Trim an Audio file with FFMPEG using Tkinter Python

By Ramya Sri Balla

This project aims to trim an audio file with FFmpeg using Tkinter GUI(Graphical User Interface) Python. FFmpeg is a software, which is a multimedia framework.

First, make sure FFmpeg is installed in your system.

Steps to install ffmpeg for Windows


    Here is the download link:

  • once downloaded the ffmpeg we need to open that file then choose extract file on right-click, then save it to some location.
  • Add this folder to the windows path, to run it, just come to the search icon and search env and click the Environment variables button. 
  • select the path variable under User variables and click Edit. 
  • Add the FFmpeg directory to the path and click ok to finish. 


   FFmpeg is software that is a multimedia framework that handles audio and video files and other multimedia files. ffmpeg is a very fast video and audio converter. Using ffmpeg we can manipulate all multimedia files. It is used to convert files, trim video and audio files, reduce the file size and crop the video, etc.

   Use this command to install ffmpeg.

      pip install ffmpeg


     A list box is a box that holds a list of items. It's a tkinter widget that can be used for all sorts of things. We can add, select and delete the items.

   here we use Listbox curselection to display the selected items. curselection is a predefined function that fetches the values of a selected items.

Glob module

    Here we use glob which is an inbuilt module in the Python standard library, which helps you to find the file pathnames that match a specific pattern.


Tkinter is the inbuilt library of Python that allows you to create a GUI Graphical User Interface, a relatively easy and most commonly used application.

let us create a Tkinter application 

Creation of Tkinter application  

  1. Import the Tkinter module

  2. Create the GUI application main window

  3. Add widgets to the main window

  4. Apply the event Trigger on the widgets.

Here is the code implementation:


from tkinter import *
import os
import glob
label=Label(root,text="TRIM AN AUDIO FILE",font=("times new roman",25,"bold"),fg="white",bg="black"),y=50)
label=Label(root,text="select an audio from list",font=("times new roman",13,"bold"),fg="blue",bg="black"),y=115)
#function for adding audio to entry field
def add_to_entry(event):
    global item
#function for trim an audio
def trims():
    start=input("enter start in seconds:")  
    end=input("enter end in seconds:") 
    command=f"ffmpeg -i {item} -ss {start} -to {end} -c copy {short}"
#function for exit an application
def exit():
#creation of list box
for f in glob.glob("*.mp3"):

#creation of buttons
button1=Button(root,text="TRIM AN AUDIO FILE",fg="blue",font=("times new roman",15,"bold"),command=trims,cursor="hand2"),y=350)
button3=Button(root,text="EXIT APPLICATION",fg="red",font=("times new roman",15,"bold"),command=exit,cursor="hand2"),y=420)



Download Complete Code


No comments yet