Reputation: 11
so I'm trying to get a really simple livestreaming system running through Azure Media Services. I've got ffmpeg installed on a Raspberry Pi w/ a USB camera, and I'm just trying to get the camera feed received through Azure so I can start tinkering with the Media Player. The ffmpeg command appears to run without a hitch, but whenever I attempt to preview the stream, I get a the following error:
"The video playback was aborted due to a corruption problem or because the video used features your browser did not support. 0x20400003"
The 0x0400003 part of the code is listed in the docs (http://amp.azure.net/libs/amp/latest/docs/index.html#error-codes) as meaning the presentation of the video is not supported, but I can't find what that actually means in terms of what's wrong.
I'm using the following ffmpeg command for encoding,
ffmpeg -v verbose -framerate 30 -r 30 -i /dev/video0 -vcodec libx264 -preset ultrafast -acodec libfdk-aac -ab 48k -b:v 500k -maxrate 500k -bufsize 500k -r 30 -g 60 -keyint_min 60 -sc_threshold 0 -f flv rtmp://{Azure channel address}/channel5
which results in the following output:
ffmpeg version N-83743-gd757ddb Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.9.2 (Raspbian 4.9.2-10)
configuration: --enable-gpl --enable-libx264 --enable-nonfree --enable-libfdk-aac
libavutil 55. 47.101 / 55. 47.101
libavcodec 57. 82.100 / 57. 82.100
libavformat 57. 66.103 / 57. 66.103
libavdevice 57. 3.100 / 57. 3.100
libavfilter 6. 74.100 / 6. 74.100
libswscale 4. 3.101 / 4. 3.101
libswresample 2. 4.100 / 2. 4.100
libpostproc 54. 2.100 / 54. 2.100
[video4linux2,v4l2 @ 0x1f7a430] fd:3 capabilities:84200001
[video4linux2,v4l2 @ 0x1f7a430] Querying the device for the current frame size
[video4linux2,v4l2 @ 0x1f7a430] Setting frame size to 640x480
[video4linux2,v4l2 @ 0x1f7a430] The driver changed the time per frame from 1/30 to 1/15
Input #0, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 169752.581724, bitrate: 73728 kb/s
Stream #0:0: Video: rawvideo, 1 reference frame (YUY2 / 0x32595559), yuyv422, 640x480, 73728 kb/s, 15 fps, 15 tbr, 1000k tbn, 1000k tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[graph 0 input from stream 0:0 @ 0x1f89eb0] w:640 h:480 pixfmt:yuyv422 tb:1/30 fr:30/1 sar:0/1 sws_param:flags=2
[auto_scaler_0 @ 0x1f8a9c0] w:iw h:ih flags:'bicubic' interl:0
[format @ 0x1f8a040] auto-inserting filter 'auto_scaler_0' between the filter 'Parsed_null_0' and the filter 'format'
[graph 0 input from stream 0:0 @ 0x1f89eb0] TB:0.033333 FRAME_RATE:30.000000 SAMPLE_RATE:nan
[auto_scaler_0 @ 0x1f8a9c0] w:640 h:480 fmt:yuyv422 sar:0/1 -> w:640 h:480 fmt:yuv422p sar:0/1 flags:0x4
No pixel format specified, yuv422p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0x1f7d650] using cpu capabilities: ARMv6 NEON
[libx264 @ 0x1f7d650] profile High 4:2:2, level 3.0, 4:2:2 8-bit
[libx264 @ 0x1f7d650] 264 - core 148 r2762 90a61ec - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=60 keyint_min=31 scenecut=0 intra_refresh=0 rc_lookahead=0 rc=cbr mbtree=0 bitrate=500 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 vbv_maxrate=500 vbv_bufsize=500 nal_hrd=none filler=0 ip_ratio=1.40 aq=0
Output #0, flv, to 'rtmp://{Azure Channel Address}/channel5':
Metadata:
encoder : Lavf57.66.103
Stream #0:0: Video: h264 (libx264), 1 reference frame ([7][0][0][0] / 0x0007), yuv422p, 640x480, q=-1--1, 500 kb/s, 30 fps, 1k tbn, 30 tbc
Metadata:
encoder : Lavc57.82.100 libx264
Side data:
cpb: bitrate max/min/avg: 500000/0/500000 buffer size: 500000 vbv_delay: -1
[flv @ 0x1f7c1c0] Failed to update header with correct duration.ate= 501.5kbits/s speed=0.25x
[flv @ 0x1f7c1c0] Failed to update header with correct filesize.
frame= 2155 fps=7.5 q=-1.0 Lsize= 4392kB time=00:01:11.80 bitrate= 501.1kbits/s speed=0.25x
video:4350kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.974120%
I'm not sure if the header errors are significant, as the program continues to run as expected, but please let me know if there's anything here that's blatantly an issue, or whether there's a meaningful explanation for what the presentation issues are.
Upvotes: 1
Views: 719
Reputation: 2512
Ok here is a quick helper for Raspberry PI Live streaming to Azure Media Services that worked out well for me.
There are a few tricks you can do here to make it work a lot better. The problem is mostly with the FFMPEG command, but you can optimize encoding as well by using the hardware acceleration support on the PI (if you have 2 or higher).
I initially followed this guide to build FFMPEG. https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu
Once I had a compiled FFMPEG, I used the new H264 Open Max (OMX) acceleration feature.
Once i had that working I did a quick test to make sure I could successfully capture an MP4 File
ffmpeg -framerate 30 -r 30 -s 640x360 -i /dev/video0 -vcodec h264_omx -preset ultrafast -acodec libfaac -ab 48k -b:v 2000k -bufsize 500k -g 60 -keyint_min 60 -sc_threshold 0 out.mp4
Finally I went with the Smooth Streaming protocol support (which is a lot more reliable than RTMP).
ffmpeg -i /dev/video1 -pix_fmt yuv420p -f ismv -movflags isml+frag_keyframe -video_track_timescale 10000000 -frag_duration 2000000 -framerate 30 -r 30 -c:v h264_omx -preset ultrafast -map 0:v:0 -b:v:0 2000k -minrate:v:0 2000k -maxrate:v:0 2000k -bufsize 2500k -s:v:0 640x360 -map 0:v:0 -b:v:1 500k -minrate:v:1 500k -maxrate:v:1 500k -s:v:1 480x360 -g 60 -keyint_min 60 -sc_threshold 0 -c:a libfaac -ab 48k -map 0:a? -threads 0 "http://***your-account-***channel.mediaservices.windows.net/ingest.isml/Streams(video)"
DEEP EXPLANATION OF WHAT IS GOING ON ABOVE ON THE FFMPEG COMMAND LINE:
ffmpeg
-re **READ INPUT AT NATIVE FRAMERATE
-stream_loop -1 **LOOP INFINITE
-i C:\Video\tears_of_steel_1080p.mov **INPUT FILE IS THIS MOV FILE
-movflags isml+frag_keyframe **OUTPUT IS SMOOTH STREAMING THIS SETS THE FLAGS
-f ismv **OUTPUT ISMV SMOOTH
-threads 0 ** SETS THE THREAD COUNT TO USE FOR ALL STREAMS. YOU CAN USE A STREAM SPECIFIC COUNT AS WELL
-c:a aac ** SET TO AAC CODEC
-ac 2 ** SET THE OUTPUT TO STEREO
-b:a 64k ** SET THE BITRATE FOR THE AUDIO
-c:v libx264 ** SET THE VIDEO CODEC
-preset fast ** USE THE FAST PRESET FOR X246
-profile:v main **USE THE MAIN PROFILE
-g 48 ** GOP SIZE IS 48 frames
-keyint_min 48 ** KEY INTERVAL IS SET TO 48 FRAMES
-sc_threshold 0 ** NOT SURE!
-map 0:v ** MAP THE FIRST VIDEO TRACK OF THE FIRST INPUT FILE
-b:v:0 5000k **SET THE OUTPUT TRACK 0 BITRATE
-minrate:v:0 5000k ** SET OUTPUT TRACK 0 MIN RATE TO SIMULATE CBR
-maxrate:v:0 5000k ** SET OUTPUT TRACK 0 MAX RATE TO SIMULATE CBR
-s:v:0 1920x1080 **SCALE THE OUTPUT OF TRACK 0 to 1920x1080.
-map 0:v ** MAP THE FIRST VIDEO TRACK OF THE FIRST INPUT FILE
-b:v:1 3000k ** SET THE OUTPUT TRACK 1 BITRATE TO 3Mbps
-minrate:v:1 3000k -maxrate:v:1 3000k ** SET THE MIN AND MAX RATE TO SIMULATE CBR OUTPU
-s:v:1 1280x720 ** SCALE THE OUTPUT OF TRACK 1 to 1280x720
-map 0:v -b:v:2 1800k ** REPEAT THE ABOVE STEPS FOR THE REST OF THE OUTPUT TRACKS
-minrate:v:2 1800k -maxrate:v:2 1800k -s:v:2 854x480
-map 0:v -b:v:3 1000k -minrate:v:3 1000k -maxrate:v:3 1000k -s:v:3 640x480
-map 0:v -b:v:4 600k -minrate:v:4 600k -maxrate:v:4 600k -s:v:4 480x360
-map 0:a:0 ** FINALLY TAKE THE SOURCE AUDIO FROM THE FIRST SOURCE AUDIO TRACK.
http://<yourchannel>.channel.mediaservices.windows.net/ingest.isml/Streams(stream0)
Hope that helps get you started in the right direction. Let me know if you have any more questions.
Upvotes: 1