I'm trying to develop a recording application.
Audio is recorded by a third system (asterisk) and give me a .wav (ulaw). I record the video coming from a rstp url to a file in H264 format to a .mp4 without audio.
Next, I need to merge the audio and the video in a single .mp4 file (H264+AAC).
It's working but the end of the output file is troncated. I can't merge untill the end !!!
I'm using the last release of vlc (1.1.11) and I know that there is a bug (corrected) with mp4 to synchonize sound and video. Is it the same problem or not ?
I can't compile myselft vlc from the git because I need to updated my system (autotools & co) and it's not curently possible (impossible to compile other applications with the last autoconf...)
Can someone tell me if it's the good way to join the 2 files and if there is a bug or not with the last release version of vlc.
Thanks for any help.
Sebastien.
Here my code :
Code: Select all
int convert_file(struct m_info* trt_info, const char* input_audio, const char* input_video, const char* output_file)
{
//Create a tmp file to process
char output_tmp_file[FILENAME_MAX] = "";
time_t timestamp;
struct tm * t;
timestamp = time(NULL);
t = localtime(×tamp);
snprintf(output_tmp_file, FILENAME_MAX, "%s%04u%02u%02u_%02u%02u%02u.mp4", _PATH_TMP, 1900 + t->tm_year, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
/* Load the VLC engine */
if(iinfos.vlc_instance == NULL)
{
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=2" // Be much more verbose then normal for debugging purpose
};
iinfos.vlc_instance = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
}
char input_audio_stream[FILENAME_MAX] = "";
snprintf(input_audio_stream, FILENAME_MAX, "file:///%s", input_audio);
char input_video_stream[FILENAME_MAX] = "";
snprintf(input_video_stream, FILENAME_MAX, "file:///%s", input_video);
/* Create a new item */
libvlc_media_t *media;
media = libvlc_media_new_path(iinfos.vlc_instance, input_video_stream);
//Media options
char options[256] = "";
//Add audio file
sprintf(options, ":input-slave=%s", input_audio_stream);
libvlc_media_add_option(media, options);
//Option to transcode
sprintf(options, ":sout=#transcode{vcodec=h264,acodec=mp4a,channels=1,samplerate=44100,scale=1}:file{dst='%s'}", output_tmp_file);
//sprintf(options, ":sout=#transcode{vcodec=h264,acodec=mp4a,ab=128,channels=2,samplerate=44100,deinterlace,audio-sync}:file{dst='%s'}", output_tmp_file);
libvlc_media_add_option(media, options);
/* Create a media player playing environment */
trt_info->vlc_media_player = libvlc_media_player_new_from_media(media);
trt_info->trt_running = 1;
/* No need to keep the media now */
libvlc_media_release(media);
/* Attach event to the media player */
libvlc_event_manager_t *eventManager = libvlc_media_player_event_manager(trt_info->vlc_media_player);
libvlc_event_attach(eventManager, libvlc_MediaPlayerEndReached, (libvlc_callback_t)trapTrtFinishEvent, trt_info);
libvlc_event_attach(eventManager, libvlc_MediaPlayerEncounteredError, (libvlc_callback_t)trapTrtFinishEvent, trt_info);
/* Start merging from the media_player */
libvlc_media_player_play(trt_info->vlc_media_player);
while(trt_info->trt_running)
{
sleep(1); /* Let it play a bit */
}
/* Stop playing */
libvlc_media_player_stop(trt_info->vlc_media_player);
//Move from tmp to output file only at the end
rename(output_tmp_file, output_file);
return 0;
}