Last active
April 8, 2018 12:04
-
-
Save RenatoUtsch/906156e5352ec8e362c694d07fe5d53d to your computer and use it in GitHub Desktop.
Scale, re-encode and add hardsubs to video files using ffmpeg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Args: ./convert.sh <file glob> <output folder> | |
# Don't forget to escape the wildcards used in the file glob. | |
# | |
# This is a bash script I wrote to convert my high-quality videos to | |
# lower-quality ones that can be played in my car's player. As it | |
# (unfortunately) doesn't support softsubs, I also have to encode hardsubs into | |
# the videos. The only format supported by the player is mp4, so I always convert | |
# to that by default. | |
# | |
# To add hardsubs and re-encode files to mp4 when they have multiple sources of | |
# audio / subtitles, first use the Copy command to map only the sources you want | |
# to another file, and then convert using scaling from it. | |
for filename in ${1}; do | |
if [[ -f "${2}/${filename}" ]]; then | |
continue | |
fi | |
name=$(basename "${filename}") | |
name_no_extension="${name%.*}" | |
# Copy | |
# Change the maps to the sources you want to keep. Only one source per video, audio and subtitle. | |
#ffmpeg -y -i "${filename}" -map 0:v:0 -map 0:a:1 -map 0:s:1 -c:v copy -c:a copy -c:s copy "${2}/${name_no_extension}.mkv" | |
# Best quality/speed with hardsubs | |
#ffmpeg -y -i "${filename}" -vf "subtitles='${filename}'" "${2}/${name_no_extension}.mp4" | |
# Scaling to 720p | |
#ffmpeg -y -i "${filename}" -vf 'subtitles="${filename}"' scale="-1:720" -c:v libx264 -c:a copy "${2}/${name_no_extension}.mp4" | |
# Scaling to 720p + aac | |
ffmpeg -y -i "${filename}" -vf "subtitles='${filename}'",scale=-1:720 -c:v libx264 -c:a aac -b:a 160k "${2}/${name_no_extension}.mp4" | |
done |
Great !
How i can do it for Bulk files ?
ex: i have 50 video and 50 subtitles ?
can i do it automatically ?
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. I'm wondering how you call your benchmark function.
What are the arguments: void func(void *, size_t), void *data, size_t numBytes, int numBenchmarks