Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been assigned a project to work in a software which works like MATLAB.
It has a feature videosync which would sync a video and play it in windows media player while plotting. But it only plays MP3,WMV,MPG,AVI files as they dont need codecs. It doesnot play mp4 files.

The windows media player in my desktop however plays mp4 files. Which I have the necessary codecs in the system.
So, can anyone reply me with a code which I can update in the DLL of the software that would allow me to do play them.

Below is a snippet of my code from videosync.c

#include <stdio.h>
#include <string.h>
#include "wavevars.h"
#include <windows.h>

C++
long __declspec(dllimport) __stdcall mciSendStringA(char *, char *, int ,int *);

C++
int OpenMediaFile(int argc, char ** argv)
{
    char strCommand[200] = "", **strFile;
    int zero = 0;

    /* Check if the right number of parameters are specified */
    if (argc != 1)
    {
        printf("Wrong # of parameters (%d) for OpenMediaFile.\n",argc);
        return -1;
    }

    /* Get the input file name and build the OPEN media file command */
    strFile = ((char ***)argv[0]);
    strcpy_s(strCommand, 200, "Open \"");
    strcat_s(strCommand, 200, strFile[0]);
    strcat_s(strCommand, 200, "\" alias MediaFile");

    /* Call the API to execute the command */
    mciSendStringA(strCommand, "", 0, &zero);

    return 1;



C++
int PlayMediaFile(int argc, char ** argv)
{
    char strCommand[200] = "";
    int zero = 0;

    /* Check if the right number of parameters are specified */
    if (argc != 0)
    {
        printf("Wrong # of parameters (%d) for PlayMediaFile.\n",argc);
        return -1;
    }

    /* Specify the PLAY media file command */
    strcpy_s(strCommand, 200, " Play MediaFile");

    /* Call the API to execute the command */
    mciSendStringA(strCommand, "", 0, &zero);

    return 1;
}

<pre lang="text"><pre lang="text">
Posted
Updated 20-Nov-15 2:27am
v2

1 solution

First of all, there is no such thing as just "MP4", and even less real thing is the notion "MP4 file". There is no such thing. Instead, there is a set of standard media containers; and each container supports some subset of different kinds of stream, and each stream can support some subset of standard codec; and some container/codec combinations are valid and some are not (perhaps only Matroska, sometimes referred to as the "king of containers" supports everything).

MPEG-4 is itself a big family of standards: https://en.wikipedia.org/wiki/MPEG-4[^].

See also:
https://en.wikipedia.org/wiki/Digital_container_format[^],
https://en.wikipedia.org/wiki/Streaming_media[^],
https://en.wikipedia.org/wiki/Codec[^].

What to do with that? I would say, use some of the best libraries; and best of them are mostly cross platform and open-source. First of all, I would advise using VLC player components:
https://en.wikipedia.org/wiki/VLC_media_player[^],
https://videolan.org/vlc/[^],
https://www.videolan.org/developers/vlc.html[^].

With C++, you can use some wrapper, to use the player as a component you could embed in your Windows application. Please see, in particular:
https://wiki.videolan.org/LibVLC[^].

This CodeProject article can also be useful: VLCWrapper - A Little C++-wrapper Around libvlc[^].

Big part of VLC based on FFMpeg, which, in turn, includes the libavcodec library; together, they support the great deal of functionality in the MPEG-4 world. If you want to get to this level, you can use these open-source products directly in your C++ code:
https://en.wikipedia.org/wiki/FFmpeg[^],
http://ffmpeg.org/[^],
https://en.wikipedia.org/wiki/Libavcodec[^],
http://libav.org/[^].

See also my past answers referenced in this one: video (mp4) to Mp3 convert[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900