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
- sudo apt update
- sudo apt install ffmpeg
Code Explanation
This Python script is designed to process video files within a specified directory. It performs the following tasks:
-
Prompts for Input:
- Asks the user to provide the path to the folder containing the video files.
- Asks the user to provide the path to the folder containing the video files.
-
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.
-
Processes Video Files:
- Iterates through each file in the directory.
- For files with
.mp4
extensions (or other specified extensions), it executes anffmpeg
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:
- Save the script as a Python file (e.g.,
video_processor.py
). - Open a terminal and navigate to the directory containing the script.
- Run the script using the following command:
Bash
python video_processor.py
- 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.
Comments
Post a Comment