Advertisement
Guest User

Untitled

a guest
Nov 19th, 2023
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. max_file_size=2800
  4. DEFAULT_OFFSET=0
  5.  
  6. if [ $# -eq 0 ]; then
  7. echo "No arguments supplied. Please provide the video path."
  8. exit 1
  9. fi
  10.  
  11. VIDEO_PATH="$1"
  12.  
  13. # Get the original video length in seconds
  14. FULL_LENGTH=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$VIDEO_PATH")
  15.  
  16. DEFAULT_LENGTH=$FULL_LENGTH
  17. DEFAULT_RESOLUTION=$(ffprobe -v error -select_streams v:0 -show_entries stream=width -of csv=p=0 "$VIDEO_PATH")
  18.  
  19. echo "Please enter an offset from the video beginning (in seconds) [default: $DEFAULT_OFFSET]:"
  20. read OFFSET
  21. OFFSET=${OFFSET:-$DEFAULT_OFFSET}
  22.  
  23. echo "Please enter the length of the clip (in seconds) [default: $DEFAULT_LENGTH]:"
  24. read LENGTH
  25. LENGTH=${LENGTH:-$DEFAULT_LENGTH}
  26.  
  27. echo "Enter the preferred video resolution (width:height, e.g., 720:1280 or original) [default: $DEFAULT_RESOLUTION]:"
  28. read RESOLUTION
  29. RESOLUTION=${RESOLUTION:-$DEFAULT_RESOLUTION}
  30.  
  31. # Now you can use the variables OFFSET, LENGTH, and RESOLUTION in your script
  32. echo "VIDEO_PATH: $VIDEO_PATH"
  33. echo "OFFSET: $OFFSET"
  34. echo "LENGTH: $LENGTH"
  35. echo "RESOLUTION: $RESOLUTION"
  36.  
  37. OUTPUT_NAME=$(basename "$VIDEO_PATH" | cut -d. -f1)
  38.  
  39. # Determine output video path
  40. OUTPUT_PATH=$(dirname "${VIDEO_PATH}")
  41.  
  42. # Use bc for floating-point arithmetic to calculate the bitrate
  43. bitrate=$(echo "scale=2; 8 * $max_file_size / $LENGTH" | bc)
  44.  
  45. echo "Target bitrate: $bitrate"
  46.  
  47. ffmpeg -y -ss ${OFFSET} -i ${VIDEO_PATH} -t ${LENGTH} -pass 1 -c:v libvpx -b:v ${bitrate}K -vf scale=${RESOLUTION}:-1 -an -sn -f webm /dev/null && \
  48. ffmpeg -ss ${OFFSET} -i ${VIDEO_PATH} -t ${LENGTH} -pass 2 -c:v libvpx -b:v ${bitrate}K -vf scale=${RESOLUTION}:-1 -an -sn -c:a libvorbis ${OUTPUT_PATH}/${OUTPUT_NAME}-out.webm
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement