Join video and audio in a single mp4 file

About encoding, codec settings, muxers and filter usage
IMS77
Blank Cone
Blank Cone
Posts: 13
Joined: 06 Jul 2011 16:38
Location: France

Join video and audio in a single mp4 file

Postby IMS77 » 26 Jul 2011 17:52

Hi,
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(&timestamp); 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; }

IMS77
Blank Cone
Blank Cone
Posts: 13
Joined: 06 Jul 2011 16:38
Location: France

Re: Join video and audio in a single mp4 file

Postby IMS77 » 27 Jul 2011 14:47

Nobody to give me an idea ?

Sébastien Escudier
Big Cone-huna
Big Cone-huna
Posts: 853
Joined: 06 Nov 2008 08:38
Operating System: linux

Re: Join video and audio in a single mp4 file

Postby Sébastien Escudier » 27 Jul 2011 14:49

this may be a bug in vlc. You can try 1.2 to see if it is better.

IMS77
Blank Cone
Blank Cone
Posts: 13
Joined: 06 Jul 2011 16:38
Location: France

Re: Join video and audio in a single mp4 file

Postby IMS77 » 27 Jul 2011 16:48

Thanks for your response. I'm installing a virtualbox to be able to compile vlc (I can't break my pc and so install new autotools..)
I hope it will not be to hard to configure & compile it ! Is the v1.2 stable ?

Sébastien Escudier
Big Cone-huna
Big Cone-huna
Posts: 853
Joined: 06 Nov 2008 08:38
Operating System: linux

Re: Join video and audio in a single mp4 file

Postby Sébastien Escudier » 27 Jul 2011 16:50

1.2 is the dev version.
You can find precompiled binaries (nightly build) for windows or compile it yourself on linux.

Rémi Denis-Courmont
Developer
Developer
Posts: 15267
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Join video and audio in a single mp4 file

Postby Rémi Denis-Courmont » 27 Jul 2011 16:54

It should be possible merge files like VLC does, if you use a "list_player" but this is more an accident than a design characteristic. The LibVLC API currently has no support for streaming/recording.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

IMS77
Blank Cone
Blank Cone
Posts: 13
Joined: 06 Jul 2011 16:38
Location: France

Re: Join video and audio in a single mp4 file

Postby IMS77 » 27 Jul 2011 17:15

With vlc I can easily record a video stream in a record (.mp4) I have some troubles only when I want to merge audio & video.
If I don't record (replacing the :file by :display in my code) I can't see my video with the audio played in the same time but it's a standard feature of vlc...
The video freeze but audio is played untill the end.

Can someone give me the command to get the v1.2 from git, I can't find it on the developers corner web site.

Sébastien Escudier
Big Cone-huna
Big Cone-huna
Posts: 853
Joined: 06 Nov 2008 08:38
Operating System: linux

Re: Join video and audio in a single mp4 file

Postby Sébastien Escudier » 28 Jul 2011 08:21

I told you to try 1.2 because there's a known bugin 1.1 where some file are not played until the end. The last seconds are drops. But I don't know if your problem is the same.

about git, look at :
http://wiki.videolan.org/Git

IMS77
Blank Cone
Blank Cone
Posts: 13
Joined: 06 Jul 2011 16:38
Location: France

Re: Join video and audio in a single mp4 file

Postby IMS77 » 28 Jul 2011 09:01

Thanks for your explanation. I will try the git version today and see if I still have the problem. On the irc channel I've learned that the 1.2 is on the trunk and the 1.1.11 on the branch so now I can't test it ! I will give you the result if I successfully compile vlc ;o)


Return to “VLC stream-output (sout)”

Who is online

Users browsing this forum: No registered users and 15 guests