流低延迟RTSP视频的ffmpeg到Android

流低延迟RTSP视频的ffmpeg到Android

问题描述:

我想从流的Ubuntu 12.04 PC现场摄像头视频与奇巧Android设备。到目前为止,我已经写配置ffserver的文件接收FFM饲料,并通过RTSP协议播放。我能看在同一个局域网其他计算机上ffplay流。

I am trying to stream live webcam video from Ubuntu 12.04 PC to android device with KitKat. So far I've written ffserver config file to receive ffm feed and broadcast it through a rtsp protocol. I am able to watch the stream on the other computer in the same LAN with ffplay.

如何观看在Android设备上的数据流?下面code效果很好,当网络摄像头图像流与VLC,但它不与ffmpeg的:

How to watch the stream on the android device? The following code works well when the webcam image is streamed with vlc but it doesn't with ffmpeg:

public class MainActivity extends Activity implements MediaPlayer.OnPreparedListener,
        SurfaceHolder.Callback {

    final static String RTSP_URL = "rtsp://192.168.1.54:4424/test.sdp";

    private MediaPlayer _mediaPlayer;
    private SurfaceHolder _surfaceHolder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Set up a full-screen black window.
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        Window window = getWindow();
        window.setFlags(
                WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        window.setBackgroundDrawableResource(android.R.color.black);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setContentView(R.layout.activity_main);

        // Configure the view that renders live video.
        SurfaceView videoView =
                (SurfaceView) findViewById(R.id.videoView); //where R.id.videoView is a simple SurfaceView element in the layout xml file
        _surfaceHolder = videoView.getHolder();
        _surfaceHolder.addCallback(this);
        _surfaceHolder.setFixedSize(320, 240);
    }
    @Override
    public void surfaceCreated(SurfaceHolder surfaceHolder) {
        _mediaPlayer = new MediaPlayer();
        _mediaPlayer.setDisplay(_surfaceHolder);
        Context context = getApplicationContext();
        Uri source = Uri.parse(RTSP_URL);
        try {
            // Specify the IP camera's URL and auth headers.
            _mediaPlayer.setDataSource(context, source);

            // Begin the process of setting up a video stream.
            _mediaPlayer.setOnPreparedListener(this);
            _mediaPlayer.prepareAsync();
        }
        catch (Exception e) {}
    }
    @Override
    public void onPrepared(MediaPlayer mediaPlayer) {
        _mediaPlayer.start();
    }
}

我ffserver.config文件:

My ffserver.config file:

HTTPPort 8090
RTSPBindAddress 0.0.0.0
RTSPPort 4424
MaxBandwidth 10000
CustomLog -

<Feed feed1.ffm>
        File /tmp/feed1.ffm
        FileMaxSize 20M
        ACL allow 127.0.0.1
</Feed>
<Stream test1.sdp>
    Feed feed1.ffm
    Format rtp  
    VideoCodec libx264
    VideoSize 640x480
    AVOptionVideo flags +global_header
    AVOptionVideo me_range 16
    AVOptionVideo qdiff 4
    AVOptionVideo qmin 10
    AVOptionVideo qmax 51
    Noaudio
    ACL allow localhost
        ACL allow 192.168.0.0 192.168.255.255
</Stream>

我开始用这个命令流:的ffmpeg -f用v412 -i的/ dev / video0的-c:v libx264 -b:v 600K的http://本地主机:8090 / feed1.ffm

此错误可能由VLC和FFmpeg的不同的编码参数最有可能造成的 - VLC可以使用的编码参数,Android是能够支持,但FFmpeg的可以使用不支持的人(最有可能的AVC档次和级别)。试图强迫基线或主配置文件,YUV 4:2:0像素格式通过FFmpeg的命令行选项和ffserver.config

This error could be most likely caused by different encoding parameters for VLC and FFmpeg - VLC could use encoding parameters that Android is able support, but FFmpeg could use unsupported ones (most likely AVC profile and level). Try to force baseline or main profile and YUV 4:2:0 pixel format through the FFmpeg command line options and ffserver.config.