Add a script to trim videos
This commit is contained in:
		
							parent
							
								
									4129ca58d1
								
							
						
					
					
						commit
						8e440d74da
					
				
							
								
								
									
										4
									
								
								aliases
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								aliases
									
									
									
									
									
								
							| 
						 | 
					@ -544,9 +544,9 @@ dl_twitch_vid() {
 | 
				
			||||||
        printf "${BOLD}Downloading Twitch vid with compression.${NORMAL}\n"
 | 
					        printf "${BOLD}Downloading Twitch vid with compression.${NORMAL}\n"
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
    if [[ $format == "" ]]; then
 | 
					    if [[ $format == "" ]]; then
 | 
				
			||||||
 | 
					        # Twitch only supplies pre-merged mp4s so we can ask for the best format and not worry about anything else.
 | 
				
			||||||
        printf "${BOLD}No format given; using best available.${NORMAL}\n"
 | 
					        printf "${BOLD}No format given; using best available.${NORMAL}\n"
 | 
				
			||||||
        format="best"
 | 
					        format="b"
 | 
				
			||||||
        #opts+=" --merge-output-format mp4"
 | 
					 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if [[ $make_folder == "1" ]]; then
 | 
					    if [[ $make_folder == "1" ]]; then
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -63,7 +63,7 @@ function encode() {
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        ffmpeg $timing_args -i "$filename.$extension" -c:v libx264 -crf $crf -preset veryfast -profile:v baseline -level 3.0 -strict -2 "$output"
 | 
					        ffmpeg $timing_args -i "$filename.$extension" -c:v libx264 -crf $crf -preset veryfast -profile:v baseline -level 3.0 -strict -2 "$output"
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
    printf "\n${GREEN}${BOLD}Done encoding '$filename.$extension' (CRF $crf) | output name '$output'${NORMAL}\n\n"
 | 
					    printf "\n${GREEN}${BOLD}Finished encoding '$filename.$extension' (CRF $crf) | output name '$output'${NORMAL}\n\n"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [[ $use_crf -ne -1 ]]; then
 | 
					if [[ $use_crf -ne -1 ]]; then
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										46
									
								
								bin/trim-video
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								bin/trim-video
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,46 @@
 | 
				
			||||||
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if which tput >/dev/null 2>&1; then
 | 
				
			||||||
 | 
					    ncolors=$(tput colors)
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
 | 
				
			||||||
 | 
					    RED="$(tput setaf 1)"
 | 
				
			||||||
 | 
					    GREEN="$(tput setaf 2)"
 | 
				
			||||||
 | 
					    YELLOW="$(tput setaf 3)"
 | 
				
			||||||
 | 
					    BLUE="$(tput setaf 4)"
 | 
				
			||||||
 | 
					    MAGENTA="$(tput setaf 5)"
 | 
				
			||||||
 | 
					    CYAN="$(tput setaf 6)"
 | 
				
			||||||
 | 
					    BOLD="$(tput bold)"
 | 
				
			||||||
 | 
					    NORMAL="$(tput sgr0)"
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
					    RED=""
 | 
				
			||||||
 | 
					    GREEN=""
 | 
				
			||||||
 | 
					    YELLOW=""
 | 
				
			||||||
 | 
					    BLUE=""
 | 
				
			||||||
 | 
					    MAGENTA=""
 | 
				
			||||||
 | 
					    CYAN=""
 | 
				
			||||||
 | 
					    BOLD=""
 | 
				
			||||||
 | 
					    NORMAL=""
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					filename=$(basename -- "$1")
 | 
				
			||||||
 | 
					output_name="$2"
 | 
				
			||||||
 | 
					start_time="$3"
 | 
				
			||||||
 | 
					end_time="$4"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [[ $filename == "" || $output_name == "" || $start_time == "" || $end_time == "" ]]; then
 | 
				
			||||||
 | 
					    printf "${BOLD}${RED}Usage: $0 <filename> <output name> <start time HH:MM:SS> <end time HH:MM:SS>${NORMAL}\n"
 | 
				
			||||||
 | 
					    exit 1
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extension="${filename##*.}"
 | 
				
			||||||
 | 
					filename="${filename%.*}"
 | 
				
			||||||
 | 
					output="${output_name}.$extension"
 | 
				
			||||||
 | 
					timing_args="-ss $start_time -to $end_time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					printf "\n${YELLOW}${BOLD}Trimming '$filename.$extension' | output: $output | start: $start_time | end: $end_time${NORMAL}\n"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ffmpeg -y -stats -loglevel level+error $timing_args -i "$filename.$extension" -c:a copy -c:v copy "$output"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					printf "\n${GREEN}${BOLD}Finished trimming${NORMAL}\n\n"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user