This script (vidconv.py
) provides a flexible command-line interface for converting video files. It uses ffmpeg
and ffprobe
for video processing, and supports various operations including changing resolution, bitrate, codec, cropping, and cutting the videos.
- Resolution Change: Convert videos to various resolutions such as 360p, 480p, 720p, 1080p, and 2160p.
- Bitrate Adjustment: Modify the bitrate to 'low', 'mid', 'high', or specify any numeric value.
- Codec Conversion: Convert videos to H.265 (HEVC) or H.264.
- Cropping: Crop videos for portrait mode on phones.
- Cutting: Extract a specific segment of the video.
- File Removal: Option to remove the original video after conversion.
- Bulk Conversion: Convert all videos in a directory and its subdirectories.
ffmpeg
andffprobe
need to be installed on your system.- Ensure the script (
vidconv.py
) has the necessary permissions to execute.
python vidconv.py INPUT_PATH [OPTIONS]
INPUT_PATH
: Path to the input video file or directory.--resolution
: Target video resolution. Default is1080
.--bitrate
: Target bitrate level. Can be 'low', 'mid', 'high', or a specific value like '4000k'. Default is 'unchanged'.--codec
: Video codec to use. Options are 'h265' or 'h264'. Default is 'h265'.--quality
: Quality value for encoding (0-51). Lower is better but will produce bigger files. Default is13
.--crop
: Crop video for portrait mode on phones.--remove
: Remove the input file after conversion.--cut
: Cut video from specific timestamps. Provide start and optionally end timestamps.--length
: Length of the video in seconds. If the value is decimal, it's interpreted as minutes.
Convert a single video to 720p with high bitrate:
python vidconv.py video.mp4 --resolution 720 --bitrate high
Convert all videos in a directory to H.265 with default quality:
python vidconv.py /path/to/directory --codec h265
Crop and convert a video for phone portrait mode:
python vidconv.py video.mp4 --crop
Cut a video segment from 2 minutes to 5 minutes:
python vidconv.py video.mp4 --cut 00:02:00 00:05:00
- Always backup your videos before using this tool, especially if you choose the
--remove
option. - The script checks the properties of the video before conversion. If the video already satisfies the given criteria, it won't be converted to save processing time.
This tool overlays various KPIs (Key Performance Indicators) on a video taken during an enduro bike ride. It uses the GPS data embedded in the video to generate visualizations such as speed, elevation, and g-force, and then overlays these visualizations on the original video.
- Elevation GIF: Shows the elevation profile of the ride with a moving point indicating the current elevation.
- Speed Map GIF: Displays the route on a map with color-coded speed data. A moving marker indicates the current position.
- KPIs: Displays the current speed and g-force on the video.
- Python 3.x
- Libraries:
sys
,os
,logging
,imageio
,matplotlib
,seaborn
,warnings
,numpy
,pandas
,gpxpy
,geopy
,folium
,selenium
,time
,srtm
. - Firefox browser (for the
selenium
webdriver). - FFmpeg (for video processing).
- GoPro video with embedded GPS data.
- Set the
video
variable to the path of your GoPro video. - Run the script:
python script_name.py
- The script will generate various GIFs and overlay them on the original video. The final output will be saved as
final_out.mp4
.
- Extract GPS Data: Extracts the GPS data from the GoPro video.
- Parse GPX Data: Parses the extracted GPS data.
- Compute Speed and Acceleration: Calculates speed and acceleration (g-force) from the GPS data.
- Generate Elevation GIF: Creates a GIF showing the elevation profile of the ride.
- Generate Speed Map GIF: Creates a GIF showing the route on a map with color-coded speed data.
- Generate KPIs GIF: Creates a GIF displaying the current speed and g-force.
- Overlay All Elements: Overlays all the generated GIFs on the original video.
- All temporary files are saved in a
temp
directory. This directory can be deleted after processing to clean up temporary files. - The Firefox browser runs in the background (headless mode) during processing.