Cannot play MPEG-TS from webcam using ExoPlayer on Android or Quicktime on Mac

0

I'm trying to use FFmpeg to stream my webcam to an Android device based on the HttpLiveStreaming(HLS). In order to play the MPEG-TS on Android, I use ExoPlayer.


FFmpeg streaming command: ffmpeg -f avfoundation -video_size 1280x720 -framerate 30 -i "0" -vcodec libx264 -preset veryfast -f flv rtmp://localhost:1935/hls/test

When I used VLC to play the MPEG-TS, everything was OK. However, I failed to play it using the ExoPlayer on Android or the Quicktime(Safari) on Mac OS. Then I tried to find out the reason.


I tried to stream a mp4 video using FFmpeg in the same way. For example: ffmpeg -re -i test.mp4 -vcodec libx264 -preset veryfast -f flv rtmp://localhost:1935/hls/test

I can play it using both ExoPlayer and Quicktime.


The only difference I found between these two cases is that the Webcam's capturing format is YUY2 while the mp4 video is YUV420 and they used different H264 encoders. I guess the H264 decoders for YUY2 and YUV420 are not the same.

I'm not sure if my inference was correct and the only solution to this problem is to convert YUY2 to YUV420 before streaming.

I hope someone using Mac could try to stream the Facetime camera using the same way as me and see if it can be played in the Safari.

Galaxy

Posted 2016-07-25T05:41:10.090

Reputation: 101

Answers

0

Finally, I found the solution. Just as I inferred, I need to convert YUY2 to YUV420 before the H264 encoding and streaming. So the command should be ffmpeg -f avfoundation -pix_fmt uyvy422 -video_size 1280x720 -framerate 30 -i "0" -pix_fmt yuv420p -vcodec libx264 -preset veryfast -f flv rtmp://localhost:1935/hls/test

Thanks to this.

Galaxy

Posted 2016-07-25T05:41:10.090

Reputation: 101