Kazam Video Error SOLLUTION | Video Codec Error SOLLUTION | Fix Codec Error: H.264 video editing on Windows. | Not Playing in other Platform (Windows/Android)

Codec Error

I was using Kazam to record my Kali Linux screen and exported the recordings to Windows for editing, as Linux isn't as robust for video editing. The editor was throwing a codec error because the recordings were in H.264 (.mp4) format. Kazam doesn't offer much flexibility to change codecs, so manual re-encoding was necessary.

This codec error isn't exclusive to Kazam recordings. Other videos in the same format might encounter similar issues and can likely be resolved with the same solution.

Solution

I re-encoded the video files using FFmpeg. To streamline and automate the process, I created a Python script to re-encode all video files within a specified folder.

You can find the code and explanation below.

 

Installing Dependencies

Make shoure to have all the required pakages

  1. sudo apt update
  2. sudo apt install ffmpeg
     

Code Explanation

This Python script is designed to process video files within a specified directory. It performs the following tasks:

  1. Prompts for Input:


     

    • Asks the user to provide the path to the folder containing the video files.
  2. Creates Output Directory:


     

    • Checks if a folder named "Formatted_Videos" exists within the specified path.
    • If not, it creates this folder to store the processed video files.
  3. Processes Video Files:


     

    • Iterates through each file in the directory.
    • For files with .mp4 extensions (or other specified extensions), it executes an ffmpeg command to re-encode the video.
    • The ffmpeg command re-encodes the video using the specified codec and parameters:
      • -c:v libx264: Uses the H.264 video codec.
      • -c:a aac: Uses the AAC audio codec.
      • -strict experimental: Allows experimental options for encoding.
      • -tune fastdecode: Optimizes for fast decoding.
      • -pix_fmt yuv420p: Sets the pixel format to YUV420p.
      • -b:a 192k: Sets the audio bitrate to 192 kbps.
      • -ar 48000: Sets the audio sample rate to 48 kHz.
    • The processed video is saved in the "Formated_Videos" folder with the same filename.

Full code:

Code Snippet

import os

path = input("folder path: ")

if "Formatted_Videos" not in os.listdir(path):
    os.mkdir(f"{path}/Formatted_Videos")

for filename in os.listdir(path):
    if (filename.endswith(".mp4")):
        print(filename)
        os.system(f"ffmpeg -y -i {path}/{filename} -c:v libx264 -c:a aac -strict experimental -tune 
                    fastdecode -pix_fmt yuv420p -b:a 192k -ar 48000 {path}/Formatted_Videos/{filename}")
    else:
        continue
                    

Example Usage:

  1. Save the script as a Python file (e.g., video_processor.py).
  2. Open a terminal and navigate to the directory containing the script.
  3. Run the script using the following command:
    Bash
    python video_processor.py
    
  4. Enter the path to the folder containing your video files when prompted.

The script will then process the videos and save the formatted versions in the "Formatted_Videos" folder.

 

 

 

  • fix codec error for video editing
  • convert H.264 video for Windows editor
  • re-encode Kazam recording for Windows
  • automate video re-encoding with Python
  • FFmpeg script for video format conversion
  • Linux video editing workflow with Windows compatibility
  • best codec for video editing on Windows
  • Python script for batch video processing
  • optimize video for faster decoding
  • improve video compatibility across platforms
  •  

    Comments

    Recommended

    New Sketch | Not Good in Portraits Sketch | My way to Improve Portraits Sketch

    Mastering Portfolio Analysis with Python: Calculate Risk and Return | Can Python Predict Your Next Million-Dollar Investment?

    Unlock the Full Potential of Jupyter Notebooks in VS Code | A Step-by-Step Guide to Using Jupyter Notebooks in VS Code

    Lessons from the Leaders: How Veeba, Jumbo King, and Royal Enfield Built Sustainable Businesses Through Customer Focus and Strategic Growth