Git Product home page Git Product logo

v4l2test's Introduction

v4l2test
========

v4l2test is a project for video & audio recording on android platform. The project implements audio capture via tinyalsa interface, and video capture via v4l2 interface, on android platform. Rendering camrea preview on screen, and recording audio and video into mp4 files by ffmpeg library.

In the project, I write a script to customize ffmpeg library building, which only including ACC & H264 encoder and MP4 file muxer, to reduce library size. If you have a android standalone toolchain, it's very easy for you, to build out the ffmpeg library for android platform.

All code are written in C/C++, after building, you get elf binary excutable program, which can execute in adb shell.
v4l2test     - capture video from camera, and rendering on screen
encodertest  - generate randomize audio & video data, and encode into mp4 file.
recordertest - capture audio & video from mic & camera, preview camera on screen, and recording audio & video into mp4 files.

After code stable, I will implement jni and test apks. It aimed to provide api for audio & video recording and live streaming on android platform, with high stability and performace.

Why did I create it
===================

At my work, I am maintaining codes of android DVR app for in-car products, which request high stability and long time work, which using the android standard camera and recorder api. I meet many bugs and issues, on android camera hal, camera api, recorder api.

The android standard api:

android.hardware.Camera
android.media.MediaRecorder

is very unstable. My apks often meet fatal error, and crash many times. And it is very diffcult to position the problem code, and fix bugs. How is the android standard api for camera and recorder? I say, it just a toy. This is why I create the v4l2test project.

Compared with android camera hal & camera api, my project directly access to camera and mic devices, it is KISS, with out any complex architecture, with out any hal, with out any service, the code is very simple and easy to debug. above the project C/C++ code, you can write a simple jni for java, then you can write a apk, to implement the camera preview and video recording. The code is simple to read and debug, is great.


How to build
============
1. using build_ffmpeg_for_android.sh to build ffmpeg library.
2. using NDK or android build environment to build test program
   (I built these codes under AllWinner A33 Android 4.4 source code enviroment.
    So I suggest using NDK version corresponding to Android 4.4.)

if you cloned google AOSP source code, and switch to tag android-4.4.4_r2.0.1, I think it's possible to build v4l2test.

under android source dir, try steps:

1. source build/envsetup.sh
2. lunch (and select a combo, ex. aosp_arm-eng)
3. make -j8
4. cd v4l2test
5. mm -B -j8

if not using A33 platform, remove
-DUSE_MEDIASERVER_H264ENC
-DPLATFORM_ALLWINNER_A33
from Android.mk

and add
-DUSE_MEDIACODEC_H264ENC

this will disable allwinner A33 cedarx hw encoding code, and support android mediacodec hw encoding.


Features
========
1.  audio capture from tinyalsa/AudioRecord
2.  video capture from v4l2
3.  audio & video encoding into mp4
4.  rendering video on screen
5.  resize video when recording
6.  resample audio when recording
7.  change frame rate when recording
9.  optimized for allwinner A33 platorm
10. record segmented video with out dropping any frame
11. auto drop frame when could't encoding in time
12. support push rtmp/hls live stream
13. support android mediacodec h264 hardware encoding
14. support cedarx hardware encoding for A33 platfrom


How to use
==========
after build success, you will get v4l2test, encodertest, recordertest and libffrecorder_jni.

v4l2test
--------
push it to /system/bin/ (using adb), chmod 755.
in adb shell, try command:
v4l2test /dev/video0 0 640 480
/dev/video0 - video device file name
0           - video device sub source
           (for some platform front and rear camera both share using /dev/video0,
            but use different source, maybe 0 - rear camera, 1 - front camera)
640 480     - camera preview resolution.
if success, the camera preview will be displayed on screen

encodertest
-----------
try command:
encodertest
it will generate random video and audio data, and encode into mp4 file.

recordertest
------------
try command:
recordertest
it will capture video from camera, audio from mic, and encode into mp4 file.

libffrecorder_jni
-----------------
it is a jni library for MediaRecorder.java class file.
by libffrecorder_jni and MediaRecorder.java, you are able to use v4l2test for android apk development with java code.
an other related project is CameraDVR: https://github.com/rockcarry/CameraDVR


permission issue ?
==================
on android platform, we usually got the permisson issue, such as file access permission, selinux permission, ..
these permission issues, will cause our app unable to work correctly.
for v4l2test/CameraDVR project, you want to test it ? you should first fix these permission issues, example:
1. test it in adb shell as root user
2. chmod 666 /dev/video*
3. modify sepolicy if selinux is enforced
4. ...



TODO
====
1. stability and performance



rockcarry
2017-2-10



v4l2test's People

Contributors

rockcarry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

v4l2test's Issues

How to detect lost connection from Camera?

Hi CK,
in CameraDVR app, does any way to detect lost connection from camera? eg. i use CVBS camera, when unplug camera, the preview window is blue color, i want to detect lost connection and show notice message "Video Loss".

Thanks!

ffmpeg问题

我执行:./build_ffmpeg_for_android.sh
Cloning into 'x264'...
remote: Counting objects: 21253, done.
remote: Compressing objects: 100% (4652/4652), done.
remote: Total 21253 (delta 17598), reused 20107 (delta 16558)
Receiving objects: 99% (21084/21253), 5.00 MiB | 3.00 KiB/s

一直不动,不知道为什么,您能帮助解答一下吗?

context-aware encoding

Hi, thanks for the release. I'm currently working on context-aware video encoding which aims at setting different QPs for different area within frame to be encoded according to grayscale saliency map where white areas indicate ROI areas. Now I'm struggling at how to implement context-aware encoding in V4L2. Any advices would be very appritiated.

Release proposal

Hi, I'm really excited about your project, but unfortunately I couldn't manage to build it, there are always some unresolved dependency issues, probably because of ndk versions incompatibility.

So the question is, could you please build your project in your environment for all architectures and upload the binaries as release?

It would be so much helpful for all the folks(like me) stumbling upon your project and having hard time trying to build the binaries.

Thank you for your work!

Preview video is delayed and interlaced

Hello CK,
as discussion with you via email before. Now i can stream video and capture to .jpg file in 720*480. But preview video is delayed and interlaced when capture moving object. My input format is YUV422 from isl79985 (Intersil's video decoder). If i use application "mxc_v4l2_tvin" to test video, i can render video to LCD screen without delay time and interlaced line.

Here is my log:
D/camdev: VIDIOC_S_FMT
D/camdev: ------------------
D/camdev: width: 720
D/camdev: height: 480
D/camdev: pixfmt: 0x56595559
field: 0
bytesperline: 1440
sizeimage: 691200
colorspace: 0
current camera frame rate: 30/1 !
assume camera frame rate is 30fps !

and capture image as attached file.

Please give me any suggestion!

Thanks!
Phi
a_img_19700101_055020

Build Errors

Hi Kai,

This is a great initiative to test an android camera without using the android.hardware.Camera apis.
I am trying to build the the examples, but I get the following attached errors.
screenshot from 2017-02-09 15-04-18

The application.mk file is.
APP_ABI := armeabi APP_PLATFORM := android-19

And the android.mk file is.
`LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := v4l2test

LOCAL_MODULE_TAGS := optional

LOCAL_MODULE_PATH := $(TARGET_OUT)/bin

LOCAL_SRC_FILES :=
v4l2test.cpp
ffjpeg.cpp
camdev.cpp

LOCAL_SHARED_LIBRARIES :=
libutils
libcutils
libui
libgui
libandroid_runtime

#++ for ffmpeg library
LOCAL_CFLAGS +=
-D__STDC_CONSTANT_MACROS

LOCAL_C_INCLUDES +=
$(LOCAL_PATH)/ffmpeg/include

LOCAL_C_INCLUDES += /AOSP/frameworks/native/include/
LOCAL_C_INCLUDES += /AOSP/system/core/include/
LOCAL_C_INCLUDES += /AOSP/hardware/libhardware/include

LOCAL_LDFLAGS += -ldl
$(LOCAL_PATH)/ffmpeg/lib/libavformat.a
$(LOCAL_PATH)/ffmpeg/lib/libavcodec.a
$(LOCAL_PATH)/ffmpeg/lib/libswresample.a
$(LOCAL_PATH)/ffmpeg/lib/libswscale.a
$(LOCAL_PATH)/ffmpeg/lib/libavutil.a
$(LOCAL_PATH)/ffmpeg/lib/libx264.a
#-- for ffmpeg library

LOCAL_MULTILIB := 32

include $(BUILD_EXECUTABLE)

include $(CLEAR_VARS)

LOCAL_MODULE := encodertest

LOCAL_MODULE_TAGS := optional

LOCAL_MODULE_PATH := $(TARGET_OUT)/bin

LOCAL_SRC_FILES :=
ffjpeg.cpp
ffencoder.cpp
encodertest.cpp

LOCAL_SHARED_LIBRARIES :=
libutils
libcutils

#++ for ffmpeg library
LOCAL_CFLAGS +=
-D__STDC_CONSTANT_MACROS

LOCAL_C_INCLUDES +=
$(LOCAL_PATH)/ffmpeg/include

LOCAL_C_INCLUDES += /AOSP/frameworks/native/include/
LOCAL_C_INCLUDES += /AOSP/system/core/include/
LOCAL_C_INCLUDES += /AOSP/hardware/libhardware/include

LOCAL_LDFLAGS += -ldl
$(LOCAL_PATH)/ffmpeg/lib/libavformat.a
$(LOCAL_PATH)/ffmpeg/lib/libavcodec.a
$(LOCAL_PATH)/ffmpeg/lib/libswresample.a
$(LOCAL_PATH)/ffmpeg/lib/libswscale.a
$(LOCAL_PATH)/ffmpeg/lib/libavutil.a
$(LOCAL_PATH)/ffmpeg/lib/libx264.a
#-- for ffmpeg library

LOCAL_MULTILIB := 32

include $(BUILD_EXECUTABLE)

include $(CLEAR_VARS)

LOCAL_MODULE := recordertest

LOCAL_MODULE_TAGS := optional

LOCAL_MODULE_PATH := $(TARGET_OUT)/bin

LOCAL_C_INCLUDES := /AOSP/external/tinyalsa/include

LOCAL_SRC_FILES :=
micdev_tinyalsa.cpp
ffjpeg.cpp
camdev.cpp
ffencoder.cpp
ffrecorder.cpp
recordertest.cpp

LOCAL_SHARED_LIBRARIES :=
libutils
libcutils
libui
libgui
libandroid_runtime
libtinyalsa

#++ for ffmpeg library
LOCAL_CFLAGS +=
-D__STDC_CONSTANT_MACROS

LOCAL_C_INCLUDES +=
$(LOCAL_PATH)/ffmpeg/include
LOCAL_C_INCLUDES += /AOSP/frameworks/native/include/
LOCAL_C_INCLUDES += /AOSP/system/core/include/
LOCAL_C_INCLUDES += /AOSP/hardware/libhardware/include

LOCAL_LDFLAGS += -ldl
$(LOCAL_PATH)/ffmpeg/lib/libavformat.a
$(LOCAL_PATH)/ffmpeg/lib/libavcodec.a
$(LOCAL_PATH)/ffmpeg/lib/libswresample.a
$(LOCAL_PATH)/ffmpeg/lib/libswscale.a
$(LOCAL_PATH)/ffmpeg/lib/libavutil.a
$(LOCAL_PATH)/ffmpeg/lib/libx264.a
#-- for ffmpeg library

LOCAL_MULTILIB := 32

include $(BUILD_EXECUTABLE)
`

What platform SDK was this built on? I am using the newest NDK from android studio. I am building your examples through nkd-build.

Thanks in advance.

any plan to simplify the build steps?

Hi,

your project looks very interesting. However, we were not able to build it, except for the ffmpeg/x264 part.

Could you elaborate more on the dependencies? The infrastructure you have, A33 sdk, is hardly available. I stopped after cloning 6 different git repos from the original google android git and going back to tag android-4.4.4_r2.0.1, but still no luck. It seems to be almost impossible to build it without the A33 SDK.

Best
Clemens

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.