Encoding Using Ffmpeg For Mac

broken image


To encode a high quality MP3 from an AVI best use -q:a for variable bit rate: ffmpeg -i sample.avi -q:a 0 -map a sample.mp3 If you want to extract a portion of audio from a video use the -ss option to specify the starting timestamp, and the -t option to specify the encoding duration, eg from 3 minutes and 5 seconds in for 45 seconds. Question: My question here because I am confused, is how to import a library into Xcode so I can use it in the application I am about to build for my Mac. I can see plenty of GitHub projects related to FFMPEG with IOS/Android, but none for OSX. All the FFMPEG commands under terminal are working fine, such as converting a video etc.

This weekend I experimented a little with re-encoding videoas H.265/HEVC, now that the codec has good support on bothhardware and in Mac OS/iOS. The FFmpeg wikiestimates that you should be able to produce video files ofsimilar video quality as H.264 that are about half thesize. That sort of space saving should be interesting toeverybody, but especially for those who carry videos aroundon laptops, which still tend to come with SSDs of modestsize even in the advanced year of 2019.

I wanted to produce something that was QuickTimecompatible, which means complying with Apple's veryspecific rules around encoding. It might seemcrazy to want to do this, but I still find that QuickTimeis in the unique position of being simultaneously the bestand worst video player ever made. While its narrowversatility makes it incredibly frustrating to work with,there's never been another video player in history thatscrubs as well, or uses laptop CPU/battery as efficiently.

For the copy/pasters out there, here's the FFmpeginvocation that worked well for me:

Or for GPU-based encoding, which is much faster, butproduces a larger file size:

The gritty details

The invocations above are all you really need to know, butI'll walk through some caveats and explanations for thoseinterested.

CPU versus GPU

libx265 encodes via the CPU while hevc_videotoolboxuses the GPU. libx265 produces a much smaller file size,but hevc_videotoolbox runs significantly faster (5 to 10times the speed on my box).

You might have noticed that for hevc_videotoolbox Ispecified a target bitrate with -b:v 6000k. I tried toget away without doing that, but found that regardless ofthe selected video profile (main or main10), unless Iforced a higher bitrate, the output video quality would begarbage. And when I say garbage, I mean garbage; as intotally unwatchable, with visual artifacts and blurrinesseverywhere. Specifying a target video bitrate works aroundthe problem, at the cost of producing an even larger finalvideo.

Microsoft xbox 360 live vision camera driver for mac. From what I can tell, the right compromise is to uselibx265 for any videos that you want to keep around, butfor videos that you'd prefer encoded quickly and willprobably delete (say you want them for a single trip),hevc_videotoolbox is perfectly fine. Output videos arestill small enough, and the significantly faster encodingspeeds mean that FFmpeg finishes far more quickly.

Audio, Dolby Digital Plus, and AAC

The samples above use -c:a eac3, which QuickTime seems to handle more easily than AAC.

QuickTime will play multi-channel AAC, but it's more finnicky, and a video with even a slightly 'wrong' audio configuration won't be openable. Images ru kids. I've had luck forcing 5.1 with channel_layout:

If your input sources are only stereo anyway, or you never expect to watch the output video on anything but a stereo device (i.e., headphones, TV minus sound system), FFmpeg can trivially downmix to stereo AAC, which QuickTime will play wit no trouble:

The `fast` preset

The libx265preset setting accepts the wide array ofadjectives ultrafast, superfast, veryfaster,faster, fast, medium, slow, slower, veryslow,and placebo. Updd console keygen. Specifying a faster setting means thatencoding speed will be preferred over file size. Both endsof the spectrum have extreme diminishing returns.

I found that there was very little file size differencebetween fast, medium, and slow, but some encodingspeed difference, so I just default to -preset fast foreverything.

The `hvc1` tag

The argument -tag:v hvc1 tags the video with hvc1,which is purely for QuickTime's benefit. It allows thisVery Smart Player to recognize the fact that it will beable to play the resulting file.

1 I don't even want to admit how long I spent trying tofigure out why QuickTime wouldn't open my encoded files. Icombed through my video settings about a hundred timesbefore realizing that it wasn't the video Apple didn'tlike, it was the 5.1 AAC.

Fragment
Encoding H.265/HEVC for QuickTime with FFmpeg

Published
May 27, 2019

Find me on Twitter at @brandur.

Encoding

Did I make a mistake? Please consider sending a pull request.

If you are installing Adobe CQ5, you'll love the fact that FFmpeg integration is supported out of the box. The bad news is that due to licensing restrictions Adobe does not bundle FFmpeg with the standard CQ installation. Another issue is that the 'standard' FFmpeg build does not include support for H264 which is useful for video playback on iOS devices etc.

Given that I had to repeat the installation process recently after reinstalling my MacBook AIR with Mountain Lion, I took some notes compiled from a few different sites into one quick cheat sheet. Note that this will take at least an hour to complete due to the need to download and compile a bunch of stuff.

Hear is the quick summary of what needs to be done;

  1. Install XCode
  2. Install Command Line tools for Xcode
  3. Install MacPorts
  4. Install FFmpeg

Now here is the longer explanation;

First install XCode

Xcode is required to be installed as its needed in step 4 to actually download and compile FFMPEG. I've tested with XCode 4.3 on Lion, and XCode 4.4 on Mountain Lion without issues.

Install Command Line tools for XCode

How To Install Ffmpeg On Mac

The Command Line Tools make the XCode 'stuff' available to MacPorts, which we will install in the next step. You can download Command Line tools for XCode for free, you just need an Apple ID.

Install MacPorts

Encoding Using Ffmpeg For Mac Windows 10

You can grab the latest from MacPorts.org. I'm using the Mountain Lion version

MacPorts is actually pretty useful and gives you access to a whole bunch of open source software. It's worth while typing the following command to keep MacPorts up to date;

If you are curious and want to explore more about MacPorts and arent that comfortable in a terminal window, I recommend installing Pallet, but its optional and not required for FFmpeg

Install FFmpeg

Finally we actually get to install FFmpeg! Open up a Terminal window and type the following (all on one line)

This will take some time, as your Mac will chug away downloading the various packages, compiling them and installing them. On my Mac & Connection it took about 45 minutes to complete the above command. You will notice the various options, including +264 etc which include the various options needed. I'd recommend the above configuration for use with CQ5.

Ffmpeg Mac Audacity

Thats it. congratulations, you should now have FFmpeg installed!





broken image