首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VLC:将流保存到文件中

VLC:将流保存到文件中
EN

Stack Overflow用户
提问于 2021-05-06 15:33:59
回答 1查看 931关注 0票数 0

此代码适用于VLC 2.2.8,但不适用于VLC 3.0.9.2

代码语言:javascript
复制
if (it->second.handle  &&  it->second.fDump) {
    // Video/audio + file dump -> duplicate stream
    transcode = "#duplicate{ dst=file{ dst=" + string(it->second.fDump) + " }, dst=display }";
}
else if (it->second.handle == NULL) {
    // No video + file dump -> single stream
    transcode = "#standard{ access=file, dst='" + string(it->second.fDump) + "' }";
}

我的重点是第二个分支,我希望收到一些建议,谢谢。

更新:

它不工作意味着它不会抛出任何错误或警告,但它不会创建文件。似乎,它忽略了这个选项。

更新2:

我怀疑保存选项被忽略了,因为我在应用程序日志中看到了这一行,这与GPU有关,但是我无法看到视频输出:

  • avcodec:使用OpenGL/VAAPI后端对

进行硬件解码

它不需要解码流,而只需要保存。

更新3:

我使用的不是图形界面,而是命令行,这是可行的:

代码语言:javascript
复制
vlc rtsp://172.18.2.60:554/Streaming/Channels/1 --rtsp-user=$user --rtsp-pwd=$passwd \
    --sout="#file{dst=test.mp4}" --vout=dummy -Idummy --ignore-config --quiet \
    --rtsp-frame-buffer-size=500000 --network-caching=4000

但是,试图发送相同的VLC库API,它不保存文件。然后,这个问题应该出现在这段与VLC 2.2.8一起工作的代码中:

代码语言:javascript
复制
it->second.p_lib = libvlc_new((int)argsCount, p_args);
if (!it->second.p_lib) {
    HVLog("Cannot initialize VLC engine");
    return -1;
}

// Set up logging
libvlc_log_set(it->second.p_lib, s_vlc_logcb, nullptr);

libvlc_media_t *p_url = libvlc_media_new_location(it->second.p_lib, url.c_str());
it->second.p_player = libvlc_media_player_new_from_media(p_url);
libvlc_media_release(p_url);

if (it->second.handle)
    libvlc_media_player_set_hwnd(it->second.p_player, it->second.handle);

if (libvlc_media_player_play(it->second.p_player) < 0) {
    HVLog("HVPlayOpen(%p, %d): cannot play stream %s", p_cam, channel, url.c_str());
    return -1;
}

return 0;

在测试中,我使用了这段代码,很明显,它是有效的。

代码语言:javascript
复制
char vlcstr[1024];
snprintf(vlcstr, 1024, "vlc %s --rtsp-user=%s --rtsp-pwd=%s --sout=#file{dst=%s} --vout=dummy -Idummy "
        "--ignore-config --quiet --rtsp-frame-buffer-size=500000 --network-caching=4000 &",
        ss.str().c_str(), p_camera->getUser().c_str(), p_camera->getPassword().c_str(), it->second.fDump);
HVLog("HVPlayOpen(%p, %d): %s", p_cam, channel, vlcstr);
system(vlcstr);
return 0;

但是,我希望使用的是库API,而不是system()。

更新4:

这是日志https://pastebin.com/9zgMQiNL

EN

回答 1

Stack Overflow用户

发布于 2021-05-10 07:05:56

解出

这个问题是使用libvlc_media_add_option()函数解决的,如下所示:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67421400

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档