1 | #include <unistd.h> |
2 | #include <stdio.h> |
3 | #include <librtmp/rtmp.h> |
4 | #include "iview.h" |
5 | |
6 | int iv_fetch_video(const struct iv_auth *auth, const struct iv_item *item, |
7 | const char *outpath) { |
8 | int result; |
9 | int return_val = IV_OK; |
10 | #define BUF_SZ (64*1024) |
11 | char *buf = malloc(BUF_SZ); |
12 | if(!buf) { |
13 | return -IV_ENOMEM; |
14 | } |
15 | char *rtmp_uri = iv_generate_video_uri(auth, item); |
16 | printf("rtmp_uri: %s\n", rtmp_uri); |
17 | FILE *outfile = fopen(outpath, "w"); |
18 | RTMP *rtmp = RTMP_Alloc(); |
19 | RTMP_Init(rtmp); |
20 | RTMP_SetupURL(rtmp, rtmp_uri); |
21 | RTMP_Connect(rtmp, NULL); |
22 | RTMP_ConnectStream(rtmp, 0); |
23 | RTMP_SetBufferMS(rtmp, (uint32_t) (2 * 3600 * 1000)); // 2hrs |
24 | RTMP_UpdateBufferMS(rtmp); |
25 | int read; |
26 | size_t wrote; |
27 | while(0 <= (read = RTMP_Read(rtmp, buf, BUF_SZ))) { |
28 | wrote = fwrite(buf, 1, read, outfile); |
29 | if(wrote != read) { |
30 | return_val = -IV_ENOMEM; |
31 | goto done; |
32 | } |
33 | } |
34 | done: |
35 | RTMP_Close(rtmp); |
36 | RTMP_Free(rtmp); |
37 | fclose(outfile); |
38 | free(buf); |
39 | iv_destroy_video_uri(rtmp_uri); |
40 | return 0; |
41 | } |
rtmp 使用
最新推荐文章于 2024-06-20 16:36:28 发布