如何在我的软件中播放mp4文件 [英] How can I allow mp4 files to play in my software

查看:149
本文介绍了如何在我的软件中播放mp4文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被分配了一个项目,可以使用像MATLAB一样工作的软件。

它有一个功能视频同步,它可以同步视频并在绘图时在Windows媒体播放器中播放。但它只播放MP3,WMV,MPG,AVI文件,因为它们不需要编解码器。它不播放mp4文件。



桌面上的Windows媒体播放器播放mp4文件。我在系统中有必要的编解码器。

所以,任何人都可以回复我的代码,我可以在软件的DLL中更新,这样我就可以玩它们。



以下是来自videosync.c的代码片段



#include< stdio.h>

#include< string.h>

#includewavevars.h

#include< windows.h>



  long   __ declspec (< span class =code-keyword> dllimport ) __ stdcall  mciSendStringA( char  *,< span class =code-keyword> char  *, int  int  *); 



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

/ * 检查是否指定了正确数量的参数* /
if (argc!= 1
{
printf(< span class =code-string> OpenMediaFile的参数数量(%d)错误。\\ n,argc);
返回 - 1 ;
}

/ * 获取输入文件名并构建OPEN媒体文件命令* /
strFile =(( char ***)argv [ 0 ]);
strcpy_s(strCommand, 200 打开\);
strcat_s(strCommand, 200 ,strFile [ 0 ]);
strcat_s(strCommand, 200 \alias MediaFile);

/ * 调用API执行命令* /
mciSendStringA(strCommand, 0 ,& zero);

返回 1 ;







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

/ * 检查是否指定了正确数量的参数* /
if (argc!= 0
{
printf(< span class =code-string>
PlayMediaFile.\,argc)的参数数量(%d)错误;
返回 - 1 ;
}

/ * 指定PLAY媒体文件命令* /
strcpy_s(strCommand, 200 播放MediaFile);

/ * 调用API执行命令* /
mciSendStringA(strCommand, 0 ,& zero);

return 1 ;
}



< pre lang =text>< pre lang =text> 

解决方案

首先,没有MP4这样的东西,更不实际的是MP4文件这个概念。哪有这回事。相反,有一套标准的媒体容器;并且每个容器支持不同种类的的一些子集,并且每个流可以支持标准编解码器的某些子集;和一些容器/编解码器组合是有效的,有些不是(也许只有 Matroska ,有时被称为容器之王支持一切)。



MPEG-4本身就是一个很大的标准系列: https://en.wikipedia.org/wiki/MPEG -4 [ ^ ]。



另请参阅:

https:// en。 wikipedia.org/wiki/Digital_container_format [ ^ ],

https://en.wikipedia.org/wiki/Streaming_media [ ^ ],

https://en.wikipedia.org/wiki/Codec [ ^ ]。



怎么办?我会说,使用一些最好的库;其中最好的主要是跨平台和开源。首先,我建议使用VLC播放器组件:

https://en.wikipedia.org/ wiki / VLC_media_player [ ^ ],

https://videolan.org/vlc/ [ ^ ],

https://www.videolan.org/developers/vlc.html [ ^ ]。



使用C ++,您可以使用一些包装器,将播放器用作可嵌入Windows应用程序的组件。请特别注意:

https://wiki.videolan.org/LibVLC [ ^ ]。



此CodeProject文章也很有用: VLCWrapper - 一个小C ++ - 包装器libvlc [ ^ ]。



VLC的很大一部分基于FFMpeg,而FFMpeg又包含libavcodec库;它们共同支持MPEG-4世界中的大量功能。如果你想达到这个水平,你可以直接在你的C ++代码中使用这些开源产品:

https://en.wikipedia.org/wiki/FFmpeg [ ^ ],

http://ffmpeg.org/ [ ^ ],

https://en.wikipedia.org/wiki/Libavcodec [ ^ ],

http://libav.org/ [ ^ ]。



另见我过去的答案在这一篇中引用:视频(mp4)到Mp3转换 [< a href =http://www.codeproject.com/Answers/1023067/vide o-mp-to-Mp-convert#answer1target =_ blanktitle =New Window> ^ ]。



-SA

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>

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


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;




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">

解决方案

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


这篇关于如何在我的软件中播放mp4文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆