Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
888 views
in Technique[技术] by (71.8m points)

macos - How to capture a timed screen recording on a Mac with ffmpeg

I'm on a Mac with MacOS Sierra installed. I've installed ffmpeg with homebrew. I list my devices via:

ffmpeg -f avfoundation -list_devices true -i ""

which returns:

[AVFoundation input device @ 0x7fc2de40e840] AVFoundation video devices:
[AVFoundation input device @ 0x7fc2de40e840] [0] FaceTime HD Camera
[AVFoundation input device @ 0x7fc2de40e840] [1] Capture screen 0
[AVFoundation input device @ 0x7fc2de40e840] AVFoundation audio devices:
[AVFoundation input device @ 0x7fc2de40e840] [0] Built-in Microphone

I don't need audio so I start my 5 second screen recording via:

ffmpeg -f avfoundation -t '5' -i '1' test.mov

It creates an mov file in the working directory but doesn't stop after 5 seconds. In fact, I can't even stop the recording as it suggests by pressing 'q'. Ctl-C doesn't work either, and I am left with force quitting via Activity Monitor. I've tried this same command but using device 0 (FaceTime camera) and it stops after 5 seconds.

If someone can solve that riddle, my next question is how can I watch the newly created file in quicktime (I'm thinking I'll need to encode or decode or something) because even the FaceTime video file would not open in QuickTime. It just says "The document could not be opened". It does, however, open with VLC.

UPDATE: I've tried this on an older OS (Yosemite) and got the same results (thought it might be the new OS that broke it).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I guess most of the time we'll ignore the program warnings, but not this one.

If recording screen with no other options like this:

ffmpeg -f avfoundation -i "1" out.mov

You'll probably see some warnings:

[mov @ 0x7f7fcf19da00] Frame rate very high for a muxer not efficiently supporting it.
Please consider specifying a lower framerate, a different muxer or -vsync 2
No pixel format specified, yuv422p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
......
[mov @ 0x7f7fcf19da00] WARNING codec timebase is very high. If duration is too long,
file may not be playable by quicktime. Specify a shorter timebase
or choose different container.

And the output video stream fps will be 1000k, which is unreasonable.

So I set the fps option. Also I set pixel format to yuv420p, otherwise the default yuv422p color space cannot be played by quicktime:

ffmpeg -f avfoundation -i "1" -pix_fmt yuv420p -r 25 -t 5 out.mov

I'm using a 2013-mid MBP with MacOS sierra, also brew installed ffmpeg 3.1.1.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...