Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

HLS stream created from webcam with ffmpeg is not displayed correctly

Writer Sophia Terry

I want to create a HLS live stream from my webcam using ffmpeg.

I have this command which creates files used by HLS to stream the video in input.

sudo ffmpeg \ -i path/to/video.mp4 \ -preset slow \ -f hls -hls_list_size 2 \ -hls_flags independent_segments -hls_flags delete_segments \ -hls_segment_type mpegts \ -hls_segment_filename data%02d.ts \ -master_pl_name master.m3u8 out1

When ran inside a folder served by a web server, I can watch the stream from an Android application using ExoPlayer.

I also have this command which takes my webcam input and place it into a video file.

ffmpeg \ -f v4l2 -video_size 640x480 \ -i /dev/video0 \ output.mkv

I tried to combine both of these commands.
When I try to stream my webcam using HLS with the following command, the HLS files are being generated, but the display on the android app is wrong.

sudo ffmpeg \ -f v4l2 -video_size 640x480 \ -i /dev/video0 \ -c:v libx264 -crf 21 -preset veryfast \ -b:v 100M -b:a 128k \ -f hls -hls_list_size 2 \ -hls_flags independent_segments -hls_flags delete_segments \ -hls_segment_type mpegts \ -hls_segment_filename data%02d.ts \ -master_pl_name master.m3u8 out1

The android app show a black screen with glitches.

I tried adding -b:v 100M -b:a 128k because the message Bandwidth info not available, set audio and video bitrates was displayed by ffmpeg.

Then I tried adding -c:v libx264 -crf 21 -preset veryfast based on others HLS tutorial but the problem persists.

Because my two first command worked, I thought that ffmpeg understood the format of the input and output streams.

Why isn't the stream working properly ?

Edit1 : Image showing the output on the ExoPlayer player

Edit2 :
The .m3u8 generated is readable with vlc. The problem might come from ExoPlayer not understanding the format. I'll close the post if it is the case.

1

1 Answer

Adding -vf format=yuv420p to the command solved the issue.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy