![](/img/trans.png)
[英]How to extract audio/video clips using the libvlc API or FFmpeg API?
[英]How to play only the audio of a video file using libvlc?
我想只使用libvlc
播放视频文件的音频。 我怎么能做到?
这是我的代码:
#include <vlc/vlc.h>
#include <chrono>
#include <iostream>
#include <string>
#include <thread>
#include <vector>
int main()
{
libvlc_instance_t *inst = libvlc_new(0, nullptr);
char const *location = "mario_00.webm";
libvlc_media_t *vlc_media = libvlc_media_new_path(inst, location);
libvlc_media_player_t *vlc_player = libvlc_media_player_new_from_media(vlc_media);
libvlc_media_player_play(vlc_player); //this line will play the video and audio
while(1){
if(libvlc_media_get_state(vlc_media) == libvlc_Ended){
break;
}
std::this_thread::sleep_for(std::chrono::seconds(1));
}
libvlc_media_player_release(vlc_player);
libvlc_media_release(vlc_media);
libvlc_release(inst);
}
您可以使用libvlc_new() arguments 指定选项--no-video
。
它的声明是
libvlc_instance_t* libvlc_new( int argc, const char *const *argv )
所以,它会是这样的:
const char* argv[] = { "--no-video" };
libvlc_instance_t *inst = libvlc_new( 1, argv );
如该线程中所述,另一个选项是选项--vout none
。 有了这个,代码将是:
const char* argv[] = { "--vout", "none" };
libvlc_instance_t *inst = libvlc_new( 2, argv );
但是,在播放媒体(音频)时,您将收到类似以下错误的连续 stream:
[00007f8da808b7f0] main video output error: video output creation failed
[00007f8dc741e930] main decoder error: failed to create video output
[00007f8da80d2250] main video output error: video output creation failed
[00007f8dc741e930] main decoder error: failed to create video output
[00007f8da80d2250] main video output error: video output creation failed
[00007f8dc741e930] main decoder error: failed to create video output
[h264 @ 0x7f8dc74422e0] get_buffer() failed
[h264 @ 0x7f8dc74422e0] thread_get_buffer() failed
[h264 @ 0x7f8dc74422e0] decode_slice_header error
[h264 @ 0x7f8dc74422e0] no frame!
[00007f8da4045f80] main video output error: video output creation failed
[00007f8dc741e930] main decoder error: failed to create video output
[h264 @ 0x7f8dc7453f60] get_buffer() failed
[h264 @ 0x7f8dc7453f60] thread_get_buffer() failed
[h264 @ 0x7f8dc7453f60] decode_slice_header error
[h264 @ 0x7f8dc7453f60] no frame!
[00007f8d9c045f80] main video output error: video output creation failed
[00007f8dc741e930] main decoder error: failed to create video output
[h264 @ 0x7f8dc7499c40] get_buffer() failed
[h264 @ 0x7f8dc7499c40] thread_get_buffer() failed
[h264 @ 0x7f8dc7499c40] decode_slice_header error
[h264 @ 0x7f8dc7499c40] no frame!
同样也可以使用libvlc_media_player_set_nsobject()来实现,如下所示:
libvlc_media_player_set_nsobject( vlc_player, nullptr );
在这种情况下,您不必将argc
和argv
传递给libvlc_new()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.