AsifHabib
AsifHabib

Reputation: 950

Capture Video using ffmpeg / mobile-ffmpeg

I have to use the FFmpeg in my project. I have integrated mobile-ffmpeg according to instruction given. github/tanersener/mobile-ffmpeg

I have used the pod which is as following.

pod 'mobile-ffmpeg-full'

I have to open the camera and I have executed the command as following.

[MobileFFmpeg execute: @"-f avfoundation -r 30 -video_size 1280x720 -pixel_format bgr0 -i 0:0 -vcodec h264_videotoolbox -vsync 2 -f h264 -t 00:00:05 %@", recordFilePath];

It also asked the permission for camera, also for microphone then log starts appearing that camera is capturing the video, but there is no camera preview. After saving the video I found the link in the documents directory, but those links do not get played.

I also executed the commands given by the library for video information and other but they always went in the failure case.

Any help, sample project, wrapper(Objecitve-C or Swift), instruction please.

Upvotes: 6

Views: 2564

Answers (1)

igdev
igdev

Reputation: 351

I spent a lot of time to figure out what I do wrong. And finally, I figure out how to record video using ffmpeg-mobile. My code looks like:

let temp = FileManager.default.temporaryDirectory
let outputFilePath = temp.absoluteString + UUID().uuidString + ".mp4"
MobileFFmpeg.execute("-f avfoundation -r 60 -video_size 1280x720 -i 0:0 -vcodec h264_videotoolbox -vsync 2 -f mp4 -t 00:00:05 " + outputFilePath)

For some reason which I don't know, AVPlayer cannot play h264 videos. And it's why you will see infinity loading when you try to execute code from ffmpeg-mobile documentation

Upvotes: 2

Related Questions