Skip to content

Instantly share code, notes, and snippets.

@civa86
Last active January 15, 2025 10:27
Show Gist options
  • Save civa86/1a9c3b484637639e74d686bb52369936 to your computer and use it in GitHub Desktop.
Save civa86/1a9c3b484637639e74d686bb52369936 to your computer and use it in GitHub Desktop.
Utils
# Download from: https://www.ffmpeg.org/download.html
# Install ffmpeg and ffprobe in yout PATH
# Convert all mp4 in the folder to mkv
find ./ -name '*.mp4' -exec bash -c 'ffmpeg -i $0 -c copy ${0/mp4/mkv}' {} \;
# Save the first minute of a video
ffmpeg -v error -stats -ss 00:00:00 -i path/to/input.mkv -to 00:01:00 -codec copy -avoid_negative_ts make_zero path/to/output.mkv
# Read duration of a video with ffmpeg
ffmpeg -i path/to/video.mkv 2>&1 | grep Duration | awk '{print $2}' | tr -d ,
# Read duration of a video with ffprobe
## Output in seconds
ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 path/to/video
## Output in HOURS:MM:SS.MICROSECONDS
ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 -sexagesimal path/to/video
# Covert flac to mp3
find . -name "*.flac" -exec bash -c 'ffmpeg -i "$0" -ab 192k -map_metadata 0 -id3v2_version 3 "${0/flac/mp3}"' {} \;
# Dump all collections
ump --host localhost --port 27017 --out /path/to/output -d database_name -u root -p password --authenticationDatabase "admin"
# Restore collection from file
mongorestore --host localhost --port 27017 --db database_name --collection collection_name -u root -p password --authenticationDatabase "admin" /path/to/input.bson
# Import Data in MongoAtlas (AWS Role Access)
USER="AWS_ACCESS_KEY_ID"
PASS="AWS_SECRET_ACCESS_KEY"
TOKEN="AWS_SESSION_TOKEN"
URI="cluster_endpoint/database_name"
COLLECTION="collection_name"
JSON_PATH="/path/to/input.json"
mongoimport \
--uri "mongodb+srv://$USER:$PASS@$URI?authMechanism=MONGODB-AWS&authSource=%24external&authMechanismProperties=AWS_SESSION_TOKEN%3A$TOKEN" \
--collection $COLLECTION \
--type json \
--file $JSON_PATH \
--jsonArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment