How to Batch Convert Mp4 Files to Ogg with Ffmpeg Using a Bash Command or Ruby

How to batch convert mp4 files to ogg with ffmpeg using a bash command or Ruby

While the direct answer to your question would be like this:

#!/bin/bash
MOVIES=~/Movies/
find "$MOVIES" -name '*.mp4' -exec sh -c 'ffmpeg -i "$0" -sameq "${0%%.mp4}.ogg"' {} \;
exit;

I think you might find better results using the VP8 or webm codec as it will give you much better results and is actually preferred in modern versions of Firefox. Given that, you should try this:

#!/bin/bash
MOVIES=~/Movies/
find "$MOVIES" -name '*.mp4' -exec sh -c 'ffmpeg -i "$0" -sameq "${0%%.mp4}.webm"' {} \;
exit;

Both of these methods WILL result in a loss of quality in your resulting videos as they are re-encoding the already encoded material and, in my opinion, even the webm codec is not nearly as good as a properly encoded MP4 using the h.264 codec.

How do you convert an entire directory with ffmpeg?

Previous answer will only create 1 output file called out.mov. To make a separate output file for each old movie, try this.

for i in *.avi;
do name=`echo "$i" | cut -d'.' -f1`
echo "$name"
ffmpeg -i "$i" "${name}.mov"
done

Mac Terminal (Bash) batch program to get multimedia file info using ffmpeg

.command files don't receive dropped files as input.

You might just open a Terminal window, type for f in, drop the files on the window, and type ; do ffmpeg -i "$f"; done.

Or save a script like this as an application in AppleScript Editor:

on open argv
set paths to ""
repeat with f in argv
set paths to paths & quoted form of POSIX path of f & " "
end repeat
tell application "Terminal"
do script "for f in " & paths & "; do ffprobe -i \"$f\"; done"
activate
end tell
end open

ffprobe -i is like ffmpeg -i but it doesn't show an error like At least one output file must be specified.

Edit: you could also use Platypus:

Sample Image

Set the script to something like for f; do ffprobe -i "$f"; done.

Changing switch statement to include both mp4 and ogg files

You can use a different filename based on the browser. See Detect all Firefox versions in JS for detecting Firefox by sniffing user agent.

However, it would be better to detect whether the browser can display MP4 video, rather than simply using user agent sniffing. Firefox may install a plugin to allow MP4; other browsers (e.g., Chromium) won't report as Firefox, but may not support MP4.

You can use the strategy from here to adapt your code: https://developer.mozilla.org/en-US/Apps/Build/Audio_and_video_delivery/H.264_support_in_Firefox

Create a utility checker function (caching the video element so we don't create a new video each time we call the function):

var mp4VideoChecker = document.createElement('video');
function canPlayH264() {
return !!(mp4VideoChecker.canPlayType && mp4VideoChecker.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"').replace(/no/, ''));
};

Then in your existing code:
...

case "mindful":
this.videoFile = canPlayH264() ? "video/vezo_mindful.mp4" : "path/to/ogg/video";
break;
case "sad":
this.videoFile = canPlayH264() ? "video/vezo_sad.mp4" : "path/to/ogg/video";
break;
case "ecstatic":
this.videoFile = canPlayH264() ? "video/vezo_ecstatic.mp4" : "path/to/ogg/video";
break;
case "goodMorning":
this.videoFile = canPlayH264() ? "video/vezo_goodMorning.mp4" : "path/to/ogg/video";
break;

This could be further optimized depending on your file paths (e.g., if the ogg files are named exactly the same as the MP4 files except for the extension, you could simply determine the extension before the case statement and then append the appropriate extension in the body of your case statement.

(Please note that your code as posted doesn't look syntactically correct. I'm assuming that's an artifact of copy/paste, and focusing only on the guts of your switch statement.)

command line list all files in directory & all combinations

Algorithm: Iterate through all the .mp4 files (f1). Inside that loop, iterate through all the .mp4 files again (f2). If f1 != f2, then process the combination.

Assuming that your script to combine videos is called combine-videos.sh, here's a script to do what you are asking (I named it combo-script.sh):

#!/bin/sh

for f1 in `ls *.mp4`
do
for f2 in `ls *.mp4`
do
if [ $f1 != $f2 ]
then
echo combine-videos.sh $f1 $f2
fi
done
done

Remove the echo when you are ready to actually run the script. Testing:

$ touch VID1.mp4 VID2.mp4 VID3.mp4
$ sh combo-script.sh
combine-videos.sh VID1.mp4 VID2.mp4
combine-videos.sh VID1.mp4 VID3.mp4
combine-videos.sh VID2.mp4 VID1.mp4
combine-videos.sh VID2.mp4 VID3.mp4
combine-videos.sh VID3.mp4 VID1.mp4
combine-videos.sh VID3.mp4 VID2.mp4

Note that this script assumes that the .mp4 files are in the same directory as the script.

command line list all files in directory & all combinations

Algorithm: Iterate through all the .mp4 files (f1). Inside that loop, iterate through all the .mp4 files again (f2). If f1 != f2, then process the combination.

Assuming that your script to combine videos is called combine-videos.sh, here's a script to do what you are asking (I named it combo-script.sh):

#!/bin/sh

for f1 in `ls *.mp4`
do
for f2 in `ls *.mp4`
do
if [ $f1 != $f2 ]
then
echo combine-videos.sh $f1 $f2
fi
done
done

Remove the echo when you are ready to actually run the script. Testing:

$ touch VID1.mp4 VID2.mp4 VID3.mp4
$ sh combo-script.sh
combine-videos.sh VID1.mp4 VID2.mp4
combine-videos.sh VID1.mp4 VID3.mp4
combine-videos.sh VID2.mp4 VID1.mp4
combine-videos.sh VID2.mp4 VID3.mp4
combine-videos.sh VID3.mp4 VID1.mp4
combine-videos.sh VID3.mp4 VID2.mp4

Note that this script assumes that the .mp4 files are in the same directory as the script.



Related Topics



Leave a reply



Submit