C++ 在视频结束或调用libvlc_media_player_stop后退出程序

C++ 在视频结束或调用libvlc_media_player_stop后退出程序,c++,windows,visual-studio,libvlc,C++,Windows,Visual Studio,Libvlc,我使用vlc-3.0.0将视频帧读入内存。问题是,当我调用libvlc_media_player_stop函数或它到达视频末尾时,程序会退出。我使用的是windows 7和Visual Studio 2012。也使用夜间构建来测试 以下是我的资料来源: #include <vlc/vlc.h> #include <string> #include <iostream> static unsigned char* buffer = new unsigned c

我使用vlc-3.0.0将视频帧读入内存。问题是,当我调用libvlc_media_player_stop函数或它到达视频末尾时,程序会退出。我使用的是windows 7和Visual Studio 2012。也使用夜间构建来测试

以下是我的资料来源:

#include <vlc/vlc.h>
#include <string>
#include <iostream>

static unsigned char* buffer = new unsigned char[1024*1024*3];

static void cbVideoPrerenderDispatcher(void *p_video_data, unsigned char **pp_pixel_buffer, int size)
{
    *pp_pixel_buffer = buffer;
}

static void cbVideoPostrenderDispatcher(void *p_video_data, unsigned char *p_pixel_buffer, int width, int height, int pixel_pitch, int size, long long pts)
{

}

int main()
{
    libvlc_media_player_t *mMedia_player;
    libvlc_media_t *media;
    libvlc_instance_t *vlcInstance;
    void *pUserData = 0;

    char *mVideoSource = "xylophone.mp4"; // size is 320x240
    char *vcodecStr = "I420";

    // VLC options
    char smem_options[1000];
    char* timeSyncStr = "time-sync";


    sprintf(smem_options
        , "#transcode{vcodec=%s,acodec=s16l}:smem{"
        "video-prerender-callback=%lld,"
        "video-postrender-callback=%lld,"
        "audio-prerender-callback=%lld,"
        "audio-postrender-callback=%lld,"
        "audio-data=%lld,"
        "video-data=%lld,"
        "%s},"
        , vcodecStr
        , (long long int)(intptr_t)(void*)&cbVideoPrerenderDispatcher
        , (long long int)(intptr_t)(void*)&cbVideoPostrenderDispatcher
        , (long long int)(intptr_t)(void*)0
        , (long long int)(intptr_t)(void*)0
        , (long long int)(intptr_t)0 //This would normally be useful data, 100 is just test data
        , (long long int)(intptr_t)0 //Test data
        , timeSyncStr); 

    const char * const vlc_args[] = {
        "-I", "dummy", // Don't use any interface
        "--ignore-config", // Don't use VLC's config
        //"--extraintf=logger", // Log anything
        "--verbose=0", // Be verbose
        "--sout", smem_options // Stream to memory
    };

    // We launch VLC
    vlcInstance = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);

    mMedia_player = libvlc_media_player_new(vlcInstance);

    media = libvlc_media_new_path(vlcInstance, mVideoSource);

    libvlc_media_player_set_media(mMedia_player, media);
    libvlc_media_release(media);
    libvlc_release(vlcInstance);
    libvlc_media_player_play(mMedia_player);

   int counter = 0;
   while(true)
   {
      if(++counter == 10)
         libvlc_media_player_stop(mMedia_player);
      _sleep(40);
   }
}
#包括
#包括
#包括
静态无符号字符*缓冲区=新的无符号字符[1024*1024*3];
静态void cbVideoPrerenderDispatcher(void*p\u视频数据,无符号字符**pp\u像素缓冲区,整数大小)
{
*pp_像素_缓冲区=缓冲区;
}
静态void cbVideoPostrenderDispatcher(void*p_视频数据、无符号字符*p_像素缓冲区、int宽度、int高度、int像素间距、int大小、长pts)
{
}
int main()
{
libvlc_media_player_t*mMedia_player;
libvlc_media_t*media;
libvlc_实例_t*vlcInstance;
void*pUserData=0;
char*mVideoSource=“xylophone.mp4”//大小为320x240
char*vcodecStr=“I420”;
//VLC选项
char smem_选项[1000];
char*timeSyncStr=“时间同步”;
sprintf(smem_选项
,“#转码{vcodec=%s,acodec=s16l}:smem{”
“视频预渲染回调=%lld,”
“视频后期渲染回调=%lld,”
音频预渲染回调=%lld
音频渲染后回调=%lld
音频数据=%lld
视频数据=%lld
“%s},”
,vcodecStr
,(长整型)(整型)(无效*)和cbVideoPrerenderDispatcher
,(长整型)(整型)(无效*)和cbVideoPostrenderDispatcher
,(长整型)(整型)(空*)0
,(长整型)(整型)(空*)0
,(long long int)(intptr_t)0//这通常是有用的数据,100只是测试数据
,(长整型)(整型)0//测试数据
,timeSyncStr);
常量字符*常量vlc_参数[]={
“-I”、“dummy”//不要使用任何接口
“--忽略配置”,//不要使用VLC的配置
//“--extrantf=logger”,//记录任何内容
--verbose=0“,//详细
“--sout”,smem\U选项//流到内存
};
//我们发射VLC
vlcInstance=libvlc_new(sizeof(vlc_args)/sizeof(vlc_args[0]),vlc_args);
mMedia_player=libvlc_media_player_new(vlcInstance);
媒体=libvlc_媒体_新路径(vlcInstance,mVideoSource);
libvlc_media_player_set_media(多媒体播放器,媒体);
libvlc_媒体发布(媒体);
libvlc_释放(vlcInstance);
libvlc媒体播放器播放(媒体播放器);
int计数器=0;
while(true)
{
如果(++计数器==10)
libvlc_媒体播放器_站(媒体播放器);
_睡眠(40);
}
}
如果有帮助,这是程序的输出:

core libvlc debug: VLC media player - 3.0.0-git-20151221-0002 Vetinari
core libvlc debug: Copyright © 1996-2015 the VideoLAN team
core libvlc debug: revision 2.2.0-git-5758-g0358127
core libvlc debug: configured with ../extras/package/win32/../../../configure  '--enable-update-check' '--enable-lua' '--enable-faad' '--enable-flac' '--enable-theora' '--enable-twolame' '--enable-quicktime' '--enable-avcodec' '--enable-merge-ffmpeg' '--enable-dca' '--enable-mpc' '--enable-libass' '--enable-x264' '--enable-schroedinger' '--enable-realrtsp' '--enable-live555' '--enable-dvdread' '--enable-shout' '--enable-goom' '--enable-caca' '--disable-sdl' '--enable-qt' '--enable-skins2' '--enable-sse' '--enable-mmx' '--enable-libcddb' '--enable-zvbi' '--disable-telx' '--enable-nls' '--host=i686-w64-mingw32' '--enable-debug' 'host_alias=i686-w64-mingw32'
core libvlc debug: using multimedia timers as clock source
core libvlc debug:  min period: 1 ms, max period: 1000000 ms
core libvlc debug: searching plug-in modules
core libvlc debug: loading plugins cache file D:\apps\VLC\vlc-3.0.0\plugins\plugins.dat
core libvlc warning: cannot read D:\apps\VLC\vlc-3.0.0\plugins\plugins.dat: No such file or directory
core libvlc debug: recursively browsing `D:\apps\VLC\vlc-3.0.0\plugins'
core libvlc debug: plug-ins loaded: 436 modules
core logger debug: looking for logger module matching "any": 2 candidates
core logger debug: using logger module "console"
core libvlc debug: translation test: code is "C"
core libvlc debug: CPU has capabilities MMX MMXEXT SSE SSE2 SSE3 SSSE3 SSE4.1 SSE4.2 FPU 
core generic debug: creating audio output
core audio output debug: looking for audio output module matching "any": 6 candidates
mmdevice audio output debug: using default device
mmdevice audio output debug: version 2 session control unavailable
mmdevice audio output debug: display name changed: VLC media player (LibVLC 3.0.0-git-20151221-0002)
mmdevice audio output debug: volume from -65.250000 dB to +0.000000 dB with 0.031250 dB increments
core audio output debug: using audio output module "mmdevice"
core generic debug: keeping audio output
core input debug: Creating an input for 'xylophone.mp4'
core stream output debug: using sout chain=`transcode{vcodec=I420,acodec=s16l}:smem{video-prerender-callback=18236016,video-postrender-callback=18235968,audio-prerender-callback=0,audio-postrender-callback=0,audio-data=0,video-data=0,time-sync},'
core stream output debug: stream=`smem'
core stream out debug: looking for sout stream module matching "smem": 22 candidates
core stream out debug: set config option: sout-smem-video-prerender-callback to 18236016
core stream out debug: set config option: sout-smem-video-postrender-callback to 18235968
core stream out debug: set config option: sout-smem-audio-prerender-callback to 0
core stream out debug: set config option: sout-smem-audio-postrender-callback to 0
core stream out debug: set config option: sout-smem-audio-data to 0
core stream out debug: set config option: sout-smem-video-data to 0
core stream out debug: set config option: sout-smem-time-sync to (null)
core stream out debug: using sout stream module "smem"
core stream output debug: stream=`transcode'
core stream out debug: looking for sout stream module matching "transcode": 22 candidates
core stream out debug: set config option: sout-transcode-vcodec to I420
core stream out debug: set config option: sout-transcode-acodec to s16l
stream_out_transcode stream out debug: Checking codec mapping for s16l got s16l 
stream_out_transcode stream out debug: codec audio=s16l 0Hz 0 channels 96Kb/s
stream_out_transcode stream out debug: Checking video codec mapping for I420 got I420 
stream_out_transcode stream out debug: codec video=I420 0x0 scaling: 0.000000 0kb/s
core stream out debug: using sout stream module "stream_out_transcode"
core input debug: using timeshift granularity of 50 MiB
core input debug: using timeshift path: C:\Users\GTANIS~1.MST\AppData\Local\Temp
core input debug: `file:///D:/projeler/denemeler/libvlctest/ConsoleApplication1/xylophone.mp4' gives access `file' demux `' path `/D:/projeler/denemeler/libvlctest/ConsoleApplication1/xylophone.mp4'
core input source debug: specified demux: any
core input source debug: creating demux: access='file' demux='any' location='/D:/projeler/denemeler/libvlctest/ConsoleApplication1/xylophone.mp4' file='D:\projeler\denemeler\libvlctest\ConsoleApplication1\xylophone.mp4'
core demux debug: looking for access_demux module matching "file": 13 candidates
core demux debug: no access_demux modules matched
core access debug: creating access: file:///D:/projeler/denemeler/libvlctest/ConsoleApplication1/xylophone.mp4
core access debug:  (path: D:\projeler\denemeler\libvlctest\ConsoleApplication1\xylophone.mp4)
core access debug: looking for access module matching "file": 25 candidates
core access debug: using access module "filesystem"
core stream debug: looking for stream_filter module matching "prefetch,cache_read": 7 candidates
cache_read stream debug: Using stream method for AStream*
cache_read stream debug: starting pre-buffering
cache_read stream debug: received first data after 1 ms
cache_read stream debug: pre-buffering done 1024 bytes in 0s - 999 KiB/s
core stream debug: using stream_filter module "cache_read"
core stream debug: looking for stream_filter module matching "any": 7 candidates
core stream debug: no stream_filter modules matched
core stream debug: looking for stream_filter module matching "record": 7 candidates
core stream debug: using stream_filter module "record"
core input source debug: creating demux: access='file' demux='any' location='/D:/projeler/denemeler/libvlctest/ConsoleApplication1/xylophone.mp4' file='D:\projeler\denemeler\libvlctest\ConsoleApplication1\xylophone.mp4'
core demux debug: looking for demux module matching "mp4": 68 candidates
mp4 stream debug: read box: "mvhd" creation 694977d-48h:00m:00s modification 694977d-48h:00m:00s time scale 30000 duration 0d-00h:00m:04s rate 1.000000 volume 1.000000 next track id 2
mp4 stream debug: read box: "tkhd" creation 694977d-48h:00m:00s modification 694977d-48h:00m:00s duration 1d-39h:10m:00s track ID 1 layer 0 volume 0.000000 rotation 0.000000 scaleX 1.000000 scaleY 1.000000 translateX 0.000000 translateY 0.000000 width 320.000000 height 240.000000. Matrix: 65536 0 0 0 65536 0 0 0 1073741824
mp4 stream debug: read box: "mdhd" creation 694977d-48h:00m:00s modification 694977d-48h:00m:00s time scale 30000 duration 1d-39h:10m:00s language    
mp4 stream debug: read box: "hdlr" handler type: "vide" name: "VideoHandler"
mp4 stream debug: read box: "vmhd" graphics-mode 0 opcolor (0, 0, 0)
mp4 stream debug: read box: "url" url: (null)
mp4 stream debug: read box: "dref" entry-count 1
mp4 stream debug: read box: "avcC" version=1 profile=0x4d level=0xd length size=4 sps=1 pps=1
mp4 stream debug:          - sps[0] length=11
mp4 stream debug:          - pps[0] length=4
mp4 stream debug: read box: "vide" in stsd 320x240 depth 24 (AVC Coding)
mp4 stream debug: read box: "stsd" entry-count 1
mp4 stream debug: read box: "stts" entry-count 1
mp4 stream debug: read box: "stsc" entry-count 1
mp4 stream debug: read box: "stsz" sample-size 0 sample-count 141
mp4 stream debug: read box: "co64" entry-count 1
mp4 stream debug: read box: "stss" entry-count 2
mp4 stream debug: read box: "hdlr" handler type: "mdir" name: "(null)"
mp4 demux debug: unrecognized major media specification (mp42).
mp4 demux debug: added fragment moov
mp4 stream debug: dumping root Box "root"
mp4 stream debug: |   + ftyp size 24 offset 0
mp4 stream debug: |   + mdat size 473925 offset 24
mp4 stream debug: |   + moov size 1256 offset 473949
mp4 stream debug: |   |   + mvhd size 108 offset 473957
mp4 stream debug: |   |   + trak size 1072 offset 474065
mp4 stream debug: |   |   |   + tkhd size 92 offset 474073
mp4 stream debug: |   |   |   + mdia size 972 offset 474165
mp4 stream debug: |   |   |   |   + mdhd size 32 offset 474173
mp4 stream debug: |   |   |   |   + hdlr size 44 offset 474205
mp4 stream debug: |   |   |   |   + minf size 888 offset 474249
mp4 stream debug: |   |   |   |   |   + vmhd size 20 offset 474257
mp4 stream debug: |   |   |   |   |   + dinf size 36 offset 474277
mp4 stream debug: |   |   |   |   |   |   + dref size 28 offset 474285
mp4 stream debug: |   |   |   |   |   |   |   + url  size 12 offset 474301
mp4 stream debug: |   |   |   |   |   + stbl size 824 offset 474313
mp4 stream debug: |   |   |   |   |   |   + stsd size 136 offset 474321
mp4 stream debug: |   |   |   |   |   |   |   + avc1 size 120 offset 474337
mp4 stream debug: |   |   |   |   |   |   |   |   + avcC size 34 offset 474423
mp4 stream debug: |   |   |   |   |   |   + stts size 24 offset 474457
mp4 stream debug: |   |   |   |   |   |   + stsc size 28 offset 474481
mp4 stream debug: |   |   |   |   |   |   + stsz size 584 offset 474509
mp4 stream debug: |   |   |   |   |   |   + stco size 20 offset 475093
mp4 stream debug: |   |   |   |   |   |   + stss size 24 offset 475113
mp4 stream debug: |   |   + udta size 68 offset 475137
mp4 stream debug: |   |   |   + meta size 52 offset 475145
mp4 stream debug: |   |   |   |   + hdlr size 32 offset 475157
mp4 demux debug: found 1 tracks
mp4 demux debug: track[Id 0x1] read 1 chunk
mp4 demux warning: STTS table of 1 entries
mp4 demux debug: track[Id 0x1] read 141 samples length:4s
core input debug: selecting program id=0
mp4 demux debug: adding track[Id 0x1] video (enable) language undef
fragments demux debug: fragment offset 473949, data 32<->473949 @0, durations (null)
core demux debug: using demux module "mp4"
mp4 demux warning: control query 3 unimplemented
mp4 demux warning: control query 2 unimplemented
core input debug: looking for a subtitle file in D:\projeler\denemeler\libvlctest\ConsoleApplication1\
core decoder debug: looking for packetizer module matching "any": 23 candidates
h264 decoder debug: found NAL_SPS (sps_id=0)
h264 decoder debug: found NAL_PPS (pps_id=0 sps_id=0)
h264 decoder debug: Packetizer fed with AVC, nal length size=4
core decoder debug: using packetizer module "h264"
core input debug: starting in async mode
core demux meta debug: looking for meta reader module matching "any": 2 candidates
lua demux meta debug: Trying Lua scripts in C:\Users\gtanisik.MSTNET\AppData\Roaming\vlc\lua\meta\reader
lua demux meta debug: Trying Lua scripts in D:\apps\VLC\vlc-3.0.0\lua\meta\reader
lua demux meta debug: Trying Lua playlist script D:\apps\VLC\vlc-3.0.0\lua\meta\reader\filename.luac
lua demux meta warning: Error loading script D:\apps\VLC\vlc-3.0.0\lua\meta\reader\filename.luac: D:\apps\VLC\vlc-3.0.0\lua\meta\reader\filename.luac: bad header in precompiled chunk
core demux meta debug: no meta reader modules matched
core input debug: `file:///D:/projeler/denemeler/libvlctest/ConsoleApplication1/xylophone.mp4' successfully opened
mp4 demux debug: track[Id 0x1] using Sync Sample Box (stss)
mp4 demux debug: stss gives 0 --> 0 (sample number)
core input debug: Buffering 0%
core input debug: switching to sync mode
core input debug: Buffering 11%
core input debug: Buffering 22%
core stream output debug: adding a new sout input (sout_input: 02c54d48)
stream_out_transcode stream out debug: creating video transcoding from fcc=`h264' to fcc=`I420'
core generic debug: looking for decoder module matching "any": 44 candidates
core input debug: Buffering 33%
core input debug: Buffering 44%
core input debug: Buffering 55%
core input debug: Buffering 66%
core input debug: Buffering 77%
core input debug: Buffering 88%
core input debug: Buffering 100%
core input debug: Stream buffering done (333 ms in 2 ms)
avcodec generic debug: CPU flags: 0x010053db
avcodec generic debug: allowing 4 thread(s) for decoding
avcodec generic debug: codec (h264) started
avcodec generic debug: using frame thread mode with 4 threads
core generic debug: using decoder module "avcodec"
core encoder debug: looking for encoder module matching "any": 22 candidates
avcodec encoder debug: CPU flags: 0x010053db
avcodec encoder debug: Time base for probing setted to 1/1000000
avcodec encoder debug: Time base set to 1/1000000
avcodec encoder debug: found encoder Raw video
core encoder debug: using encoder module "avcodec"
core encoder debug: removing module "avcodec"
core input debug: Decoder wait done in 14 ms
avcodec generic debug: available hardware decoder output format 61 (dxva2_vld)
avcodec generic debug: available hardware decoder output format 128 (d3d11va_vld)
avcodec generic debug: available software decoder output format 0 (yuv420p)
core generic debug: looking for hw decoder module matching "any": 2 candidates
core generic debug: no hw decoder modules matched
core generic debug: looking for hw decoder module matching "any": 2 candidates
core generic debug: no hw decoder modules matched
avcodec generic warning: plane 0 not aligned: disabling direct rendering
stream_out_transcode stream out debug: decoder aspect is 1.240310:1
stream_out_transcode stream out debug: source pixel aspect is 0.930233:1
stream_out_transcode stream out debug: scaled pixel aspect is 0.930233:1
stream_out_transcode stream out debug: source 320x240, destination 320x240
stream_out_transcode stream out debug: source fps 30/1, destination 30/1
stream_out_transcode stream out debug: encoder aspect is 320:258
stream_out_transcode stream out debug: destination (after video filters) 320x258
core encoder debug: looking for encoder module matching "any": 22 candidates
avcodec encoder debug: CPU flags: 0x010053db
avcodec encoder debug: Time base for probing setted to 1/30
avcodec encoder debug: Time base set to 1/30
avcodec encoder debug: found encoder Raw video
core encoder debug: using encoder module "avcodec"
The thread 0x21b8 has exited with code 0 (0x0).
core decoder debug: killing decoder fourcc `h264', 0 PES in FIFO
core decoder debug: removing module "h264"
core stream output debug: removing a sout input (sout_input: 02c54d48)
The thread 0x157c has exited with code 3 (0x3).
The thread 0x17f4 has exited with code 3 (0x3).
The thread 0xef0 has exited with code 3 (0x3).
The thread 0x15b4 has exited with code 3 (0x3).
The thread 0x1008 has exited with code 3 (0x3).
The thread 0x1ff8 has exited with code 3 (0x3).
The thread 0x16b8 has exited with code 3 (0x3).
The thread 0x1664 has exited with code 3 (0x3).
The thread 0x1474 has exited with code 3 (0x3).
The thread 0x1f94 has exited with code 3 (0x3).
The thread 0x1ddc has exited with code 3 (0x3).
The program '[6332] ConsoleApplication1.exe' has exited with code 3 (0x3).
核心libvlc调试:VLC媒体播放器-3.0.0-git-20151221-0002 Vetinari
核心libvlc调试:版权所有©1996-2015 VideoLAN团队
核心libvlc调试:版本2.2.0-git-5758-g0358127
核心libvlc调试:配置为../extras/package/win32/../../../../../configure'--启用更新检查'--启用lua'--启用faad'--启用flac'--启用theora'--启用twolame'--启用quicktime'--启用avcodec'--启用合并ffmpeg'--启用dca'--启用mpc'--启用libass'--启用x264'--启用schroedinger'“--启用realrtsp”“--启用-live555”“--启用dvdread”“--启用hout”“--启用goom”“--启用caca”“--禁用sdl”“--启用qt”“--启用-skins2”“--启用sse”“--启用mmx”“--启用libcddb”“--启用zvbi”“--禁用telx”“--启用nls”“--主机=i686-w64-mingw32”“--启用调试”“主机\u别名=i686-w64-mingw32”
核心libvlc调试:使用多媒体定时器作为时钟源
核心libvlc调试:最小周期:1毫秒,最大周期:1000000毫秒
核心libvlc调试:搜索插件模块
核心libvlc调试:加载插件缓存文件D:\apps\VLC\VLC-3.0.0\plugins\plugins.dat
core libvlc警告:无法读取D:\apps\VLC\VLC-3.0.0\plugins\plugins.dat:没有这样的文件或目录
核心libvlc调试:递归浏览'D:\apps\VLC\VLC-3.0.0\plugins'
核心libvlc调试:加载的插件:436个模块
核心记录器调试:寻找与“任意”匹配的记录器模块:2个候选
核心记录器调试:使用记录器模块“控制台”
核心libvlc调试:翻译测试:代码为“C”
核心libvlc调试:CPU具有MMX MMXEXT SSE2 SSE3 SSE3 SSE4.1 SSE4.2 FPU功能
核心通用调试:创建音频输出
核心音频输出调试:寻找与“任意”匹配的音频输出模块:6个候选模块
mmdevice音频输出调试:使用默认设备
mmdevice音频输出调试:版本2会话控制不可用
mmdevice音频输出调试:显示名称更改:VLC媒体播放器(LibVLC 3.0.0-git-20151221-0002)
mmdevice音频输出调试:音量从-65.250000 dB到+0.000000 dB,增量为0.031250 dB
核心音频输出调试:使用音频输出模块“mmdevice”
核心通用调试:保持音频输出
核心输入调试:为“xylophone.mp4”创建输入
核心流输出调试:使用sout chain=`transcode{vcodec=I420,acodec=s16l}:smem{video prerender callback=18236016,video postreder callback=18235968,audio prerender callback=0,audio postreder callback=0,audio data=0,video data=0,time sync},'
核心流输出调试:流=`smem'
核心流输出调试:寻找与“smem”匹配的源流模块:22个候选
核心流输出调试:设置配置选项:sout smem视频预渲染回调到18236016
核心流输出调试:设置配置选项:sout smem video postrender回调至18235968
core stream out调试:设置配置选项:sout smem音频预渲染回调到0
core stream out调试:设置配置选项:sout smem audio postrender回调为0
core stream out调试:设置配置选项:将smem音频数据设置为0
core stream out调试:设置配置选项:将smem视频数据设置为0
核心流输出调试:设置配置选项:sout smem时间同步到(null)
核心流输出调试:使用sout流模块“smem”
核心流输出调试:流=`transcode'
core stream out调试:查找与“transcode”匹配的源流模块:22 candid