-1

I want to stream endless live video data, e.g. from my webcam of my Ubuntu machine to an Android client. Therefore, I use ffmpeg (2.2.git) and ffserver (2.2.git) in order to encode with H.264, wrap into mp4 and, finally, stream via RTSP.

I succeed in streaming (send, receive and play) files, e.g. with ffmpeg being configured like that:

ffmpeg -re -i input.mp4 \
   -pix_fmt yuv420p \
   -c:v libx264 -profile:v baseline -level 3.0 \
   -c copy http://127.0.0.1:8888/feed1.ffm

However, also with help of (1), (2), (3) and other articles, I do not arrive in successfully streaming 'endless' webcam data - let alone anything Android compatible. The idea is to use fragmented mp4.

When I try the following:

ffmpeg -re -f v4l2 -video_size 1280x720 -i /dev/video0 \
   -pix_fmt yuv420p \
   -c:v libx264 -profile:v baseline -level 3.0 \
   -f mp4 -movflags frag_keyframe+empty_moov \
   -c copy http://127.0.0.1:8888/feed1.ffm

ffmpeg shows errors:

[NULL @ 0x26b3ce0] [Eval @ 0x7fffa0738a20] Undefined constant or missing '(' in 'baseline'
[NULL @ 0x26b3ce0] Unable to parse option value "baseline"
[NULL @ 0x26b3ce0] Error setting option profile to value baseline.
[mp4 @ 0x26b2f20] Using AVStream.codec.time_base as a timebase hint to the muxer is deprecated. Set AVStream.time_base instead.
[mp4 @ 0x26b2f20] Could not find tag for codec rawvideo in stream #0, codec not currently supported in container

With the following slight differences:

ffmpeg \
   -re -f v4l2 -i /dev/video0 \
   -pix_fmt yuv420p \
   -c:v libx264 \
   -f mp4 -movflags frag_keyframe+empty_moov http://127.0.0.1:8888/feed2.ts

ffmpeg starts encoding but stops after ~2 seconds with the following output:

[libx264 @ 0x2549aa0] frame=   0 QP=23.20 NAL=3 Slice:I Poc:0   I:1200 P:0    SKIP:0    size=15471 bytes

It lets the shell crash.

I also tried multiple variants of the configurations above. V4l2 works fine. I assume that because I can record videos from my webcam, for example.

What do I have to do in order to stream webcam data?

EDIT: I use the combination of H.264, H.264's baseline profile and mp4 because I know about Android's compatibility. As I said, streaming works well when used with ordinary files.

Community
  • 1
  • 1
Finnfalter
  • 732
  • 2
  • 7
  • 22

1 Answers1

2

Try outputting as HLS for Android which is basically fragmented mp4 cut up into a playlist.

E.g.

ffmpeg -re -f v4l2 -video_size 1280x720 -i /dev/video0 -acodec libfdk_aac -b:a 64k -pix_fmt yuv420p -vcodec libx264 -x264opts level=41 -r 25 -profile:v baseline -b:v 1500k -maxrate 2000k -force_key_frames 50 -s 640×360 -map 0 -flags -global_header -f segment -segment_list index_1500.m3u8 -segment_time 10 -segment_format mpeg_ts -segment_list_type m3u8 segment%05d.ts

I haven't had a chance to test this but it is copied from previous code snippets so should work. There have also been a few changes that have gone into ffmpeg of late I need to catch up on and one of your error messages has an open bug.

Andrew
  • 742
  • 8
  • 21