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

前端 未结 2 1598
没有蜡笔的小新
没有蜡笔的小新 2020-12-18 04:33

I am running a OSX, don\'t know tons about video conversions. But I have like 200 videos that are all in mp4 format and won\'t play in Firefox. I need to convert them to o

相关标签:
2条回答
  • 2020-12-18 05:01

    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.

    0 讨论(0)
  • 2020-12-18 05:14

    This is using Ruby, assuming the ffmpeg you used is correct:

    Dir.glob("**/*.mp4").each do |filename|
      new_filename = File.join(
        File.dirname(filename),
        "#{File.basename(filename, ".mp4")}.ogg")
      `ffmpeg -i "#{filename}" -acodec vorbis -vcodec libtheora "#{new_filename}"`
    end
    

    Dir.glob with "**/*.mp4" recursively matches all the files within subdirectories witha .mp4 extension.

    0 讨论(0)
提交回复
热议问题