*libRTMP study

来自个人维基
2020年4月9日 (四) 00:37free6d1823讨论 | 贡献的版本

跳转至: 导航搜索

source code download:

git clone git://git.ffmpeg.org/rtmpdump

Calling flow:
1. Init

   RTMP_LogSetLevel(level);
   RTMP_LogSetCallback(rtmp_log);
     static void rtmp_log(int level, const char *fmt, va_list args)
   RTMP *r = {};
   RTMP_Init(r); //init RTMP. BufferMS=30000,

filename = " "+ 
app=   
tcUrl= 
pageUrl=
swfUrl=
flashVer=
conn=
live=1
subscribe=
buffer=
swfUrl=
swfVfy=1
  

2. Setup

   RTMP_SetupURL(r, filename)
   RTMP_EnableWrite(r); //r->Link.protocol |= RTMP_FEATURE_WRITE;
   RTMP_Connect(r, NULL)
   RTMP_ConnectStream(r, 0)
   //
   setsockopt()

3. write

   RTMP_Write(r, buf, size);

4. read

   RTMP_Read(r, buf, size);
   RTMP_Pause(r, pause);
   RTMP_SendSeek(r, timestamp);

5. close

  RTMP_Close(r)
  RTMP_Free(RTMP *r) // free(r)


Use ffmpeg/libavformat/rtmpproto.c
Log:
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x29a9800] Setting codecpar->delay to 2 for stream st: 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x29a9800] Unknown dref type 0x206c7275 size 12
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x29a9800] Processing st: 1, edit list 0 - media time: 2048, duration: 21168000
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x29a9800] drop a frame at curr_cts: 0 @ 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x29a9800] drop a frame at curr_cts: 1024 @ 1
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x29a9800] Before avformat_find_stream_info() pos: 385043 bytes read:402457 seeks:0 nb_streams:2
[h264 @ 0x29ab280] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 0x29ab280] nal_unit_type: 8(PPS), nal_ref_idc: 3
[h264 @ 0x29ab280] nal_unit_type: 6(SEI), nal_ref_idc: 0
[h264 @ 0x29ab280] nal_unit_type: 5(IDR), nal_ref_idc: 3
[h264 @ 0x29ab280] Format yuv420p chosen by get_format().
[h264 @ 0x29ab280] Reinit context to 1920x1088, pix_fmt: yuv420p
[h264 @ 0x29ab280] no picture
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x29a9800] demuxer injecting skip 2048 / discard 0
[aac @ 0x29afc80] skip 2048 / discard 0 samples due to side data
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x29a9800] All info found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x29a9800] After avformat_find_stream_info() pos: 450824 bytes read:483220 seeks:0 frames:2
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/jammy/test.mp4':

 Metadata:
   major_brand     : isom
   minor_version   : 512
   compatible_brands: isomiso2avc1mp41
   encoder         : Lavf56.15.102
 Duration: 00:08:00.05, start: 0.000000, bitrate: 4817 kb/s
   Stream #0:0(und), 1, 1/12800: Video: h264 (High), 1 reference frame (avc1 / 0x31637661), yuv420p(left), 1920x1080 (1920x1088), 0/1, 4683 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
   Metadata:
     handler_name    : VideoHandler
   Stream #0:1(und), 1, 1/44100: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
   Metadata:
     handler_name    : SoundHandler

Successfully opened the file.
Parsing a group of options: output url rtmp://localhost/myapp/mystream.
Applying option c (codec name) with argument copy.
Applying option f (force format) with argument flv.
Successfully parsed a group of options.
Opening an output file: rtmp://localhost/myapp/mystream.
[rtmp @ 0x2a2e300] No default whitelist set
[tcp @ 0x2a2e240] No default whitelist set
[tcp @ 0x2a2e240] Original list of addresses:
[tcp @ 0x2a2e240] Address 127.0.0.1 port 1935
[tcp @ 0x2a2e240] Interleaved list of addresses:
[tcp @ 0x2a2e240] Address 127.0.0.1 port 1935
[tcp @ 0x2a2e240] Starting connection attempt to 127.0.0.1 port 1935
[tcp @ 0x2a2e240] Successfully connected to 127.0.0.1 port 1935
[rtmp @ 0x2a2e300] Handshaking...
[rtmp @ 0x2a2e300] Type answer 3
[rtmp @ 0x2a2e300] Server version 13.14.10.13
[rtmp @ 0x2a2e300] Proto = rtmp, path = /myapp/mystream, app = myapp, fname = mystream
[rtmp @ 0x2a2e300] Window acknowledgement size = 5000000
[rtmp @ 0x2a2e300] Max sent, unacked = 5000000
[rtmp @ 0x2a2e300] New incoming chunk size = 4096
[rtmp @ 0x2a2e300] Releasing stream...
[rtmp @ 0x2a2e300] FCPublish stream...
[rtmp @ 0x2a2e300] Creating stream...
[rtmp @ 0x2a2e300] Sending publish command for 'mystream'
Successfully opened the file.
Output #0, flv, to 'rtmp://localhost/myapp/mystream':

 Metadata:
   major_brand     : isom
   minor_version   : 512
   compatible_brands: isomiso2avc1mp41
   encoder         : Lavf58.30.100
   Stream #0:0(und), 0, 1/1000: Video: h264 (High), 1 reference frame ([7][0][0][0] / 0x0007), yuv420p(left), 1920x1080 (0x0), 0/1, q=2-31, 4683 kb/s, 25 fps, 25 tbr, 1k tbn, 12800 tbc (default)
   Metadata:
     handler_name    : VideoHandler
   Stream #0:1(und), 0, 1/1000: Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, 128 kb/s (default)
   Metadata:
     handler_name    : SoundHandler

Stream mapping:

 Stream #0:0 -> #0:0 (copy)
 Stream #0:1 -> #0:1 (copy)

Press [q] to stop, [?] for help
cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
cur_dts is invalid st:1 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)

   Last message repeated 1 times

frame= 15 fps=0.0 q=-1.0 size= 379kB time=00:00:00.51 bitrate=6079.8kbits/frame= 28 fps= 28 q=-1.0 size= 715kB time=00:00:01.02 bitrate=5735.0kbits/frame= 41 fps= 27 q=-1.0 size= 981kB time=00:00:01.52 bitrate=5285.2kbits/frame= 54 fps= 27 q=-1.0 size= 1280kB time=00:00:02.04 bitrate=5135.7kbits/frame= 66 fps= 26 q=-1.0 size= 1668kB time=00:00:02.55 bitrate=5351.0kbits/frame= 79 fps= 26 q=-1.0 size= 1907kB time=00:00:03.04 bitrate=5136.1kbits/frame= 91 fps= 26 q=-1.0 size= 2163kB time=00:00:03.55 bitrate=4988.2kbits/[flv @ 0x29ac580] Failed to update header with correct duration.
[flv @ 0x29ac580] Failed to update header with correct filesize.
frame= 94 fps= 26 q=-1.0 Lsize= 2197kB time=00:00:03.66 bitrate=4904.6kbits/s speed= 1x
video:2133kB audio:59kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.228048%
Input file #0 (/home/jammy/test.mp4):

 Input stream #0:0 (video): 94 packets read (2183894 bytes); 
 Input stream #0:1 (audio): 161 packets read (60374 bytes); 
 Total: 255 packets (2244268 bytes) demuxed

Output file #0 (rtmp://localhost/myapp/mystream):

 Output stream #0:0 (video): 94 packets muxed (2183894 bytes); 
 Output stream #0:1 (audio): 161 packets muxed (60374 bytes); 
 Total: 255 packets (2244268 bytes) muxed

0 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0x2a2e080] Statistics: 0 seeks, 281 writeouts
[rtmp @ 0x2a2e300] UnPublishing stream...
[rtmp @ 0x2a2e300] Deleting stream...
[AVIOContext @ 0x29b2580] Statistics: 2630641 bytes read, 0 seeks
Exiting normally, received signal 2.