Skip to content

Instantly share code, notes, and snippets.

@mattak
Created February 10, 2026 03:24
Show Gist options
  • Select an option

  • Save mattak/92b7b1686f7bf8497a0116c3d883edb0 to your computer and use it in GitHub Desktop.

Select an option

Save mattak/92b7b1686f7bf8497a0116c3d883edb0 to your computer and use it in GitHub Desktop.
Pull latest video screencapture on MetaQuest, convert the file to h264 compression, remove original video on device.
#!/bin/bash
set -eu
# --- Configuration ---
REMOTE_DIR="/sdcard/Oculus/VideoShots"
LOCAL_TMP_DIR="/tmp"
CONVERT_QUALITY=32
# Scale long side to 1920px while maintaining aspect ratio
SCALE_FILTER="scale='if(gt(iw,ih),1920,-2)':'if(gt(ih,iw),1920,-2)'"
# --- Logic ---
# Get the latest filename (tr removes potential carriage returns from adb output)
latest_filename=$(adb shell ls "$REMOTE_DIR" | tail -1 | tr -d '\r')
if [ -z "$latest_filename" ]; then
echo "Error: No files found in $REMOTE_DIR"
exit 1
fi
remote_path="$REMOTE_DIR/$latest_filename"
local_raw_path="$LOCAL_TMP_DIR/$latest_filename"
local_conv_path="${local_raw_path%.*}_large.mp4"
echo "Target file: $latest_filename"
# 1. Pull file from device to local temp directory
adb pull "$remote_path" "$local_raw_path"
echo "Pulled: $local_raw_path"
# 2. Encode with FFmpeg
# -y: Overwrite output files without asking
# -crf: Constant Rate Factor (Higher is lower quality)
ffmpeg -i "$local_raw_path" \
-vf "$SCALE_FILTER" \
-c:v libx264 \
-crf "$CONVERT_QUALITY" \
-b:v 0 \
-y "$local_conv_path"
# 3. Remove the original file from the device to save space
adb shell rm "$remote_path"
echo "Removed from device: $remote_path"
# 4. Move the converted file to the current directory
final_output="$(basename "$local_conv_path")"
mv "$local_conv_path" "./$final_output"
# 5. Open current directory (macOS)
open .
cat <<__SUMMARY__
-----------------------------------------
Succeeded! 🎉
- Original copy: $local_raw_path
- Converted: ./$final_output
-----------------------------------------
__SUMMARY__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment