简体   繁体   English

使用ffmpeg将低延迟RTSP视频流传输到android

[英]Stream low latency RTSP video to android with ffmpeg

I am trying to stream live webcam video from Ubuntu 12.04 PC to android device with KitKat. 我正在尝试使用KitKat将实时网络摄像头视频从Ubuntu 12.04 PC传输到android设备。 So far I've written ffserver config file to receive ffm feed and broadcast it through a rtsp protocol. 到目前为止,我已经编写了ffserver配置文件来接收ffm提要并通过rtsp协议对其进行广播。 I am able to watch the stream on the other computer in the same LAN with ffplay. 我可以使用ffplay在同一LAN中的另一台计算机上观看流。

How to watch the stream on the android device? 如何在Android设备上观看视频流? The following code works well when the webcam image is streamed with vlc but it doesn't with ffmpeg: 当使用vlc传输网络摄像头图像但不使用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();
    }
}

My ffserver.config file: 我的ffserver.config文件:

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>

I am starting the stream with this command: ffmpeg -f v4l2 -i /dev/video0 -c:v libx264 -b:v 600k http://localhost:8090/feed1.ffm 我使用以下命令启动流: ffmpeg -f v4l2 -i /dev/video0 -c:v libx264 -b:v 600k http://localhost:8090/feed1.ffm

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). 此错误很可能是由VLC和FFmpeg的不同编码参数引起的-VLC可以使用Android能够支持的编码参数,但是FFmpeg可以使用不受支持的编码参数(最可能是AVC配置文件和级别)。 Try to force baseline or main profile and YUV 4:2:0 pixel format through the FFmpeg command line options and ffserver.config. 尝试通过FFmpeg命令行选项和ffserver.config强制设置基线或主配置文件和YUV 4:2:0像素格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM