LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

playing mp4 sound files

I am trying to make my code play a sound when a button is pressed. 

At the moment I am using the play sound file block, but this block only accepts files in a .WAV format. 

I am creating this program for someone who is not great with computers. Their easiest way to record sounds to be played saves them in an MP4 format.

Having to make them convert the files to .WAV would be very difficult and frustraiting for them.

 

 

 

 

What I am asking is if there is a way to play a MP4 file in labview, or a way to programatically convert a MP4 file into a .WAV file for the play sound file block.

 

Thanks for your time. 

0 Kudos
Message 1 of 6
(4,717 Views)

When you say "MP4", do you mean "MP4", which is an MPEG-4 Video format, or "MP3", which is an MPEG-2 Level III audio format?  I don't think LabVIEW has a native MP3 reader (perhaps because it is proprietary) -- there is probably software out there to convert MP3 to WAV, which LabVIEW can read.

 

Bob Schor

0 Kudos
Message 2 of 6
(4,689 Views)

You can try the .net function Play Sound, it should handle all the system can handle.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 6
(4,670 Views)

When I record a sound with the program it says it is in an MP4 format. I do not actually know much about what MP4 actually means and how it is different than MP3. 

Whatever it is I need the recorded sound to play from it. The program does have an option to convert the sound file to MP3, which I assume means the audio MP3 you mentioned. 

 

From what I have found so far it looks like the only way to do it is to somehow convert it into a .WAV to run in labview rather than run as a MP3 or MP4. 

0 Kudos
Message 4 of 6
(4,646 Views)

This might work.

"If you weren't supposed to push it, it wouldn't be a button."
Message 5 of 6
(4,634 Views)

Do you have an example MP4 file?

 

In any case, you can use ffmpeg to extract the audio component of the file, automatically convert it to WAV, and then playback the WAV using the LabVIEW sound VIs. The attached (quick and dirty) VI can read an MP4, then play it back with a button press. Just make sure ffmpeg.exe is in the same directory as the VI. The key part is the conversion to WAV using ffmpeg, with the command:

 

 

ffmpeg.exe -i input_file.mp4 -acodec pcm_s16le -ar 44100 output_file.wav

 

This will read the input MP4 file, set the output audio codec to a signed, 16-bit, little endian PCM wave with a 44100Hz sample rate, then write to an output wave file.mp4_button_player.PNG

 




Certified LabVIEW Architect
Unless otherwise stated, all code snippets and examples provided
by me are "as is", and are free to use and modify without attribution.
0 Kudos
Message 6 of 6
(3,692 Views)