Record video/audio and count frames

This forum is about all development around libVLC.
michikommader
New Cone
New Cone
Posts: 6
Joined: 15 May 2013 15:16

Record video/audio and count frames

Postby michikommader » 07 Jun 2013 17:54

Heho!
I'm new to libvlc and want to save h264-video and aac-audio from an RTSP-stream into a file plus count the recorded video frames (for logging together with data from other sensors).

My recording works well with this example but obviously I have no possibility to access any frames to count them:

Code: Select all

libvlc_instance_t* inst = libvlc_new(0, NULL); libvlc_media_t* m = libvlc_media_new_location(inst, "rtsp://ip-address/stream.sdp"); libvlc_media_add_option (m, ":sout=#std{access=file,mux=mp4,dst=\"outfile.mp4\"}"); libvlc_media_player_t* mp = libvlc_media_player_new_from_media(m); libvlc_media_release(m); libvlc_media_player_play (mp);
On the other hand I can count my frames using custom callbacks like described in viewtopic.php?f=32&t=110586. But this way I do not know how to mux my incoming video and audio into a file simultaneously. Is there any tutorial I can follow? Or do I have to choose a totally different approach?

I already asked on IRC today and got the hint to implement my own video output and use libvlc_video_set_callbacks together with libvlc_video_set_format. But I have no clue how to do the synchronised video- and audio-processing into my file. Maybe I am just searching for the wrong keywords. Any help and further hints are warmly welcome! :)

der Michi

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: Record video/audio and count frames

Postby Jean-Baptiste Kempf » 07 Jun 2013 23:38

You could use smem to get the callbacks, but that's harder.

I'm not sure if the stats are available from libVLC.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

michikommader
New Cone
New Cone
Posts: 6
Joined: 15 May 2013 15:16

Re: Record video/audio and count frames

Postby michikommader » 10 Jul 2013 12:11

Heho!

It works fine with smem and custom callbacks. For orientation I used the wiki tutorial on smem and pass a this-pointer of my handling object (where I increase the frame count) into smem's video-data-parameter:

Code: Select all

... sprintf(media_options, ":sout=#duplicate{dst=std{access=file,mux=mp4,dst=\"%s.mp4\"}," "dst=smem{video-prerender-callback=%lld,video-postrender-callback=%lld,video-data=%lld}}", outfile.c_str(), (long long int)(intptr_t)(void*)&cbVideoPrerender, (long long int)(intptr_t)(void*)&cbVideoPostrender, (long long int)(intptr_t)(void*)this); libvlc_media_add_option (media, media_options); ...
This allows me to access members and functions of my object within a callback. My two static video callback functions do the handling:

Code: Select all

void cbVideoPrerender(void *p_video_data, uint8_t **pp_pixel_buffer, int size) { *pp_pixel_buffer = (uint8_t *)malloc(size); } void cbVideoPostrender(void *p_video_data, uint8_t *p_pixel_buffer, int width, int height, int pixel_pitch, int size, int64_t pts) { //Get instance of the desired object MyFancyClass* obj = static_cast<MyFancyClass*>(p_video_data); obj->doFancyStuff(); }
The static_cast from a void pointer has to be handled with care because there is no possibility to validate my resulting object as far as I know. So obj will never be NULL after the cast but may point to a crappy object with mysterious members if something went wrong.

I wish there would be more documentation on all this ...

Michi


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 12 guests