Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 774
AsifHabib Avatar asked Feb 07 '20 09:02

AsifHabib


People also ask

How to capture Linux desktop video using FFmpeg?

The command to capture the Linux desktop video by ‘ffmpeg’ is as follows. ‘-s 1280×1024’ is the resolution of the screen. Change it to the screen resolution you use. ‘-r 25’ is the FPS rate. For more usage of ffmpeg, please check ffmpeg manual.

Does ffffmpeg do it all?

FFMpeg does it all. However, the combination of video and audio capture raises some delicate problems. The present article explains all the options and considerations for Windows.

How to record from the framebuffer device /dev/fb0 with ffmpeg?

To record from the framebuffer device /dev/fb0 with ffmpeg : Set the frame rate. Default is 25. Win32 GDI-based screen capture device. This device allows you to capture a region of the display on Windows. The first option will capture the entire desktop, or a fixed region of the desktop.

How to use FFmpeg with Video4Linux2?

Set the sample rate in Hz. Default is 48000. Set the number of channels. Default is 2. Video4Linux2 input video device. "v4l2" can be used as alias for "video4linux2". If FFmpeg is built with v4l-utils support (by using the --enable-libv4l2 configure option), it is possible to use it with the -use_libv4l2 input device option.


1 Answers

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

like image 125
igdev Avatar answered Oct 18 '22 13:10

igdev