I'm using FFmpegFrameRecorder
to get the video input from my webcam and record it into a video file. The problem is that I'm building my application using a few different demo source codes that I found and I use properties some of which are not completely clear to me.
First, here is my code snippet :
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(FILENAME, grabber.getImageWidth(),grabber.getImageHeight());
recorder.setVideoCodec(13);
recorder.setFormat("mp4");
recorder.setPixelFormat(avutil.PIX_FMT_YUV420P);
recorder.setFrameRate(30);
recorder.setVideoBitrate(10 * 1024 * 1024);
recorder.start();
- setVideoCodec(13) - What is the meaning of this
(13)
how can I understand what actual codec stands behind any number? - setPixelFormat - Just get this, don't know what it's doing in general
- setFrameRate(30) - I think this should be pretty clear but still what is the logic behind what frame rate we choose (isn't the high the better?)
- setVideoBitrate(10*1024*1024) - again almost no idea what this does and what's the logic behind the numbers?
At the end I just want to mention one last problem that I get recording video like this. If the actual length of the video is let's say 20secs. When I play the video file created from the program it runs significantly faster. Can't tell if it's exactly 2 times faster than it should be but in general if I record a 20sec video then it's played for about 10secs. What may cause this and how can I fix it?
VideoCodec can be chosen from this list found in
avcodec.h
/avcodec.java
(As you can see, the number 13 gets us MPEG4, and there are others, but FFmpeg doesn't have an encoder for all of them):PixelFormat can be selected from this list in
pixfmt.h
/avutil.java
, but each codec only supports a few of them (most of them support at leastAV_PIX_FMT_YUV420P
):FrameRate indicates the number of frames per second the video should be played back at (it has nothing to do with the number or the timing of images you actually record, although it provides a basis for the encoding bitrate). So, in the case of 30 FPS, to cover 20 seconds of video, you need to call
record()
30 * 20 = 600 times. If you do no callrecord()
600 times, then this is the cause of your problem.VideoBitrate provides the video bitrate (in bits per second) at which the video stream should be encoded at. Wikipedia has a nice article about that.