rtmp 使用

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
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值