Writing a find command with ffmpeg to process videos
I want to write a command or script to find all my .mkv videos larger than 3Gb, then run ffmpeg to make them smaller (720p) and change the extension to mp4. I have it working except the file ends up with .mkv.mp4 extension.
I'm also sure there is probably a much better way of doing this, such as with a script. Here is what I have come up with:
find '/home/username/Videos/' -type f -size +3G -exec ffmpeg -i "{}" -c:v libx264 -c:a copy -acodec copy -vf scale="trunc(oh*a/2)*2:720" -preset superfast -crf 24 -b:v 400k "{}.mp4" ;
I would also like to have the output files to a directory like /home/username/Videos/Changed, and then delete the original .mkv.
Can anyone help teach me the best method to do this?
command-line scripts video ffmpeg find
add a comment |
I want to write a command or script to find all my .mkv videos larger than 3Gb, then run ffmpeg to make them smaller (720p) and change the extension to mp4. I have it working except the file ends up with .mkv.mp4 extension.
I'm also sure there is probably a much better way of doing this, such as with a script. Here is what I have come up with:
find '/home/username/Videos/' -type f -size +3G -exec ffmpeg -i "{}" -c:v libx264 -c:a copy -acodec copy -vf scale="trunc(oh*a/2)*2:720" -preset superfast -crf 24 -b:v 400k "{}.mp4" ;
I would also like to have the output files to a directory like /home/username/Videos/Changed, and then delete the original .mkv.
Can anyone help teach me the best method to do this?
command-line scripts video ffmpeg find
add a comment |
I want to write a command or script to find all my .mkv videos larger than 3Gb, then run ffmpeg to make them smaller (720p) and change the extension to mp4. I have it working except the file ends up with .mkv.mp4 extension.
I'm also sure there is probably a much better way of doing this, such as with a script. Here is what I have come up with:
find '/home/username/Videos/' -type f -size +3G -exec ffmpeg -i "{}" -c:v libx264 -c:a copy -acodec copy -vf scale="trunc(oh*a/2)*2:720" -preset superfast -crf 24 -b:v 400k "{}.mp4" ;
I would also like to have the output files to a directory like /home/username/Videos/Changed, and then delete the original .mkv.
Can anyone help teach me the best method to do this?
command-line scripts video ffmpeg find
I want to write a command or script to find all my .mkv videos larger than 3Gb, then run ffmpeg to make them smaller (720p) and change the extension to mp4. I have it working except the file ends up with .mkv.mp4 extension.
I'm also sure there is probably a much better way of doing this, such as with a script. Here is what I have come up with:
find '/home/username/Videos/' -type f -size +3G -exec ffmpeg -i "{}" -c:v libx264 -c:a copy -acodec copy -vf scale="trunc(oh*a/2)*2:720" -preset superfast -crf 24 -b:v 400k "{}.mp4" ;
I would also like to have the output files to a directory like /home/username/Videos/Changed, and then delete the original .mkv.
Can anyone help teach me the best method to do this?
command-line scripts video ffmpeg find
command-line scripts video ffmpeg find
asked Jan 21 at 23:18
ticotexasticotexas
386
386
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
IMHO, the "Good" way to do this is to break it into two steps:
- Find the big files.
- "Fix" them.
And, I'd put step 2 into a bash
script, stored in /home/username/bin/fixvideos
My find
command would then look like:
find '/home/username/Videos/' -type f -name '*.mkv' -size +3G -print0 |
xargs -0 --no-run-if-empty /home/username/fixvideos
and, the script in /home/username/fixvideos
is something like:
#!/bin/bash
# handle "-v" or "--verbose" as optional 1st parameter, the rest are "*.mkv" files
# which will be rescaled and converted to ".mp4", using ffmpeg
declare -i verbose=0
#
if [[ "$1" = "-v" ]] || [[ "$1" = "--verbose" ]] ; then
verbose=1
shift
fi
while [[ $# -ne 0 ]] ; do
# the base name, without the extension
bname="${1//.mkv}"
oname="$bname.mkv"
if [[ $verbose -ne 0 ]] ; then
echo "Reading $1, writing $oname" >&2
fi
ffmpeg -i "$1" -c:v libx264 -c:a copy -acodec copy
-vf scale="trunc(oh*a/2)*2:720" -preset superfast
-crf 24 -b:v 400k "$oname"
#
# shift all the filenames down so the next file is actually next
shift
done
exit 0
Thanks @waltinator! It's great. It will take me some time to learn exactly how it works. I changed this lineoname="$bname.mkv"
tooname="$bname.mp4"
and it worked. How can I have it save the new .mp4s to a different folder, like /home/username/Videos/Changed?
– ticotexas
Jan 22 at 19:43
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1111796%2fwriting-a-find-command-with-ffmpeg-to-process-videos%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
IMHO, the "Good" way to do this is to break it into two steps:
- Find the big files.
- "Fix" them.
And, I'd put step 2 into a bash
script, stored in /home/username/bin/fixvideos
My find
command would then look like:
find '/home/username/Videos/' -type f -name '*.mkv' -size +3G -print0 |
xargs -0 --no-run-if-empty /home/username/fixvideos
and, the script in /home/username/fixvideos
is something like:
#!/bin/bash
# handle "-v" or "--verbose" as optional 1st parameter, the rest are "*.mkv" files
# which will be rescaled and converted to ".mp4", using ffmpeg
declare -i verbose=0
#
if [[ "$1" = "-v" ]] || [[ "$1" = "--verbose" ]] ; then
verbose=1
shift
fi
while [[ $# -ne 0 ]] ; do
# the base name, without the extension
bname="${1//.mkv}"
oname="$bname.mkv"
if [[ $verbose -ne 0 ]] ; then
echo "Reading $1, writing $oname" >&2
fi
ffmpeg -i "$1" -c:v libx264 -c:a copy -acodec copy
-vf scale="trunc(oh*a/2)*2:720" -preset superfast
-crf 24 -b:v 400k "$oname"
#
# shift all the filenames down so the next file is actually next
shift
done
exit 0
Thanks @waltinator! It's great. It will take me some time to learn exactly how it works. I changed this lineoname="$bname.mkv"
tooname="$bname.mp4"
and it worked. How can I have it save the new .mp4s to a different folder, like /home/username/Videos/Changed?
– ticotexas
Jan 22 at 19:43
add a comment |
IMHO, the "Good" way to do this is to break it into two steps:
- Find the big files.
- "Fix" them.
And, I'd put step 2 into a bash
script, stored in /home/username/bin/fixvideos
My find
command would then look like:
find '/home/username/Videos/' -type f -name '*.mkv' -size +3G -print0 |
xargs -0 --no-run-if-empty /home/username/fixvideos
and, the script in /home/username/fixvideos
is something like:
#!/bin/bash
# handle "-v" or "--verbose" as optional 1st parameter, the rest are "*.mkv" files
# which will be rescaled and converted to ".mp4", using ffmpeg
declare -i verbose=0
#
if [[ "$1" = "-v" ]] || [[ "$1" = "--verbose" ]] ; then
verbose=1
shift
fi
while [[ $# -ne 0 ]] ; do
# the base name, without the extension
bname="${1//.mkv}"
oname="$bname.mkv"
if [[ $verbose -ne 0 ]] ; then
echo "Reading $1, writing $oname" >&2
fi
ffmpeg -i "$1" -c:v libx264 -c:a copy -acodec copy
-vf scale="trunc(oh*a/2)*2:720" -preset superfast
-crf 24 -b:v 400k "$oname"
#
# shift all the filenames down so the next file is actually next
shift
done
exit 0
Thanks @waltinator! It's great. It will take me some time to learn exactly how it works. I changed this lineoname="$bname.mkv"
tooname="$bname.mp4"
and it worked. How can I have it save the new .mp4s to a different folder, like /home/username/Videos/Changed?
– ticotexas
Jan 22 at 19:43
add a comment |
IMHO, the "Good" way to do this is to break it into two steps:
- Find the big files.
- "Fix" them.
And, I'd put step 2 into a bash
script, stored in /home/username/bin/fixvideos
My find
command would then look like:
find '/home/username/Videos/' -type f -name '*.mkv' -size +3G -print0 |
xargs -0 --no-run-if-empty /home/username/fixvideos
and, the script in /home/username/fixvideos
is something like:
#!/bin/bash
# handle "-v" or "--verbose" as optional 1st parameter, the rest are "*.mkv" files
# which will be rescaled and converted to ".mp4", using ffmpeg
declare -i verbose=0
#
if [[ "$1" = "-v" ]] || [[ "$1" = "--verbose" ]] ; then
verbose=1
shift
fi
while [[ $# -ne 0 ]] ; do
# the base name, without the extension
bname="${1//.mkv}"
oname="$bname.mkv"
if [[ $verbose -ne 0 ]] ; then
echo "Reading $1, writing $oname" >&2
fi
ffmpeg -i "$1" -c:v libx264 -c:a copy -acodec copy
-vf scale="trunc(oh*a/2)*2:720" -preset superfast
-crf 24 -b:v 400k "$oname"
#
# shift all the filenames down so the next file is actually next
shift
done
exit 0
IMHO, the "Good" way to do this is to break it into two steps:
- Find the big files.
- "Fix" them.
And, I'd put step 2 into a bash
script, stored in /home/username/bin/fixvideos
My find
command would then look like:
find '/home/username/Videos/' -type f -name '*.mkv' -size +3G -print0 |
xargs -0 --no-run-if-empty /home/username/fixvideos
and, the script in /home/username/fixvideos
is something like:
#!/bin/bash
# handle "-v" or "--verbose" as optional 1st parameter, the rest are "*.mkv" files
# which will be rescaled and converted to ".mp4", using ffmpeg
declare -i verbose=0
#
if [[ "$1" = "-v" ]] || [[ "$1" = "--verbose" ]] ; then
verbose=1
shift
fi
while [[ $# -ne 0 ]] ; do
# the base name, without the extension
bname="${1//.mkv}"
oname="$bname.mkv"
if [[ $verbose -ne 0 ]] ; then
echo "Reading $1, writing $oname" >&2
fi
ffmpeg -i "$1" -c:v libx264 -c:a copy -acodec copy
-vf scale="trunc(oh*a/2)*2:720" -preset superfast
-crf 24 -b:v 400k "$oname"
#
# shift all the filenames down so the next file is actually next
shift
done
exit 0
edited Jan 22 at 6:04
answered Jan 22 at 5:58
waltinatorwaltinator
22.6k74169
22.6k74169
Thanks @waltinator! It's great. It will take me some time to learn exactly how it works. I changed this lineoname="$bname.mkv"
tooname="$bname.mp4"
and it worked. How can I have it save the new .mp4s to a different folder, like /home/username/Videos/Changed?
– ticotexas
Jan 22 at 19:43
add a comment |
Thanks @waltinator! It's great. It will take me some time to learn exactly how it works. I changed this lineoname="$bname.mkv"
tooname="$bname.mp4"
and it worked. How can I have it save the new .mp4s to a different folder, like /home/username/Videos/Changed?
– ticotexas
Jan 22 at 19:43
Thanks @waltinator! It's great. It will take me some time to learn exactly how it works. I changed this line
oname="$bname.mkv"
to oname="$bname.mp4"
and it worked. How can I have it save the new .mp4s to a different folder, like /home/username/Videos/Changed?– ticotexas
Jan 22 at 19:43
Thanks @waltinator! It's great. It will take me some time to learn exactly how it works. I changed this line
oname="$bname.mkv"
to oname="$bname.mp4"
and it worked. How can I have it save the new .mp4s to a different folder, like /home/username/Videos/Changed?– ticotexas
Jan 22 at 19:43
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1111796%2fwriting-a-find-command-with-ffmpeg-to-process-videos%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown