The simplest mobile-based FFmpeg example: Windows Phone HelloWorld

Source: Internet
Author: User


The simplest ffmpeg-based mobile case series List of articles:

The simplest mobile-based FFmpeg example: Android HelloWorld

The simplest mobile-based FFmpeg example: Android Video Decoder

The simplest mobile-based FFmpeg example: Android Video Decoder-Single library version

The simplest ffmpeg-based mobile example: Android push-to-stream

The simplest mobile-based FFmpeg example: Android video transcoding

The simplest ffmpeg-based mobile example attachment: Android comes with the player

The simplest ffmpeg mobile-based example attachment: SDL Android HelloWorld

The simplest mobile-based FFmpeg example: IOS HelloWorld

The simplest mobile-based FFmpeg example: IOS Video Decoder

The simplest mobile-based FFmpeg example: IOS streaming

The simplest mobile-based FFmpeg example: IOS video transcoding

The simplest ffmpeg-based mobile example attachment: iOS comes with a player

The simplest mobile-based FFmpeg example: Windows Phone HelloWorld


This document records the FFmpeg-based HelloWorld program under the Windows Phone platform. The source code for the example C language comes from the simplest ffmpeg-based HelloWorld program. The related concepts are no longer duplicated.

Since only Android and iOS have real-time experience in ffmpeg mobile development, I only did the Android and iOS sample programs from the beginning. The first two days to attend Microsoft in the Water Cube's Windows 10 Conference, the pre-visit information when the Windows 10 in the AV processing has joined the FFmpeg support. At the same time, Microsoft also unveiled an open source project, Ffmpeginterop, dedicated to compiling a class library containing FFmpeg functionality to the Windows Plus app. Out of curiosity i downloaded and ffmpeginterop the project and finally summed up a sample program that ffmpeg the HelloWorld on the Windows Phone platform.

Instructions for using the FFmpeg class library under the Windows phone platform

The process for using the FFmpeg class library with the Windows Phone platform (Windows App Store,windows store) is as follows.

1. Compiling the FFmpeg class library

(1) Prerequisites need to install VS2013 and MSYS2 (preferably you can successfully use both tools to compile the ffmpeg used on the PC).

(2) Obtain the Ffmpeginterop project (the project is located on GitHub and the address is Https://

(3) Add FFmpeg source code. After downloading the source code from the official website, extract the source code into the Ffmpeginterop ffmpeg directory.

(4) Start the "VS2013 Developer Command Prompt" console as an administrator and switch to the Ffmpeginterop directory.

(5) Configure MSYS2, run the following command to set the MSYS2_BIN environment variable (this is different depending on the MSYS2 installation path):
Set msys2_bin= "E:\msys64\usr\bin\bash.exe"

(6) Handling a small bug. You need to change the name of the Link.exe in MSYS2 (you can change it, such as "Link_msys.exe"). Because the MSYS2 in Link.exe and VS2013 in the name of the Link.exe, if not changed, the system will mistakenly use MSYS2 link.exe (instead of VS2013 link.exe), resulting in a compilation failure. Do not know is not all the machine has this problem, then did card me for a while.

(7) Execute the command to compile the class library. Direct execution of Buildffmpeg.bat will print the Help menu. Execute the following statement to compile the class library for the Windows8.1 x86 platform. After the successful compilation, the class library is located under the "ffmpeg\build\windows8.1\x86" directory.
Buildffmpeg win8.1 x86
Executing the following statement compiles the class libraries of the Windows8.1 x86 and x64 platforms at the same time.
Buildffmpeg win8.1 x86 x64
Other compile commands are no longer detailed and can be viewed in the Help menu. The FFmpeg class library obtained in this step can be used for the development of the Windows APP store program.
PS: The DLL generated here is not the same as the DLL used in the Console or MFC program. The DLL here is a DLL with the flag Appcontainer. If you use a normal console program to call the DLL generated here, you will get an error "0xc000a200":
Error 0xc000a200:shows up when regular process (not inside a appcontainer) tries to load DLL that is marked with Appcon Tainer flag.
(8) Open the SLN solution under the Samples folder [optional]. This step of the SLN solution includes the Ffmpeginterop Library source code project as well as some sample programs. This part of the source code has not been studied (this article does not involve the content of this part of the code).

2. Writing programs under the Windows Phone platform

(1) Create a new Windows Store program. a blank application (XAML), new project->visual c++->windows store, file

(2) Copy the compiled class library to the project directory (note that x86, x64, and so on are the corresponding platforms). create a new include folder store header file (*.h), the Lib folder stores the import library file (*.lib), and copy the dynamic library file (*.dll) directly to the directory.

(3) Configure the class library. Divided into the following 3 steps:
A) header file configuration
Property panel, right-click Project, Solution Explorer
Properties panel->c/c++-> General, additional include directories, enter "include" (the directory where the header file was just copied)
b) Import library configuration
Add-on library directory, general--, linker, properties panel, type "Lib" (the directory where you just copied the library file)
Additional dependencies, input, linker, properties panel, input "AVCODEC.LIB; Avformat.lib; Avutil.lib; Avdevice.lib; Avfilter.lib; Swresample.lib; Swscale.lib "(The file name of the import library)
c) Dynamic Library configuration (important and distinctive step)
Solution Explorer, right-click Projects, add existing items, add DLL files in
Select the content, general, properties, right-click for each DLL file, set to Yes
(4) test
a) editing interface
Add a button to the MainPage.xaml and add a "button_clicked ()" Response function.
<page    x:class= "testapp.mainpage"    xmlns= "Http://"    xmlns:x= "Http://"    xmlns:local= "Using:testapp"    xmlns:d= "http :// "    xmlns:mc=" markup-compatibility/2006 "    mc:ignorable=" D ">    <stackpanel  margin=" 120,30,0,0 ">        < TextBlock horizontalalignment= "left" text= "My FFmpeg test" fontsize= ""/> <button content=        "Configure Info "click=" button_clicked "/>        <textblock x:name=" Greetingoutput "/>    </stackpanel></page >
B) Edit the code
Add a button_clicked () code in MainPage.xaml.cpp, as shown below.
void mainpage::button_clicked (platform::object^ sender, windows::ui::xaml::routedeventargs^ e) {//greetingOutput- >text = "Hello, Lei"; Uses_conversion; String ^info = Ref new String (A2W (Avcodec_configuration ())); Windows::ui::P Opups::messagedialog (info). Showasync ();}
The code calls Avcodec_configuration () to get the configuration information for the FFmpeg class library, and then calls Messagedialog () to pop up a dialog box to display the information. Note that a macro that uses a a2w () in atlconv.h is used to convert char * to platform::string.
Add the header file to the MainPage.xaml.cpp header, as shown below.
#include <atlconv.h>extern "C" {#include "libavcodec/avcodec.h"}
Add the declaration of the response function in Mainpage.xaml.h, as shown below.
Public ref class MainPage sealed{public:mainpage (); void button_clicked (platform::object^ sender, Windows::ui::xaml:: routedeventargs^ e);};
If all of the
configuration is not a problem, the Windows app will run as shown in the results. Clicking the button in the upper-left corner pops up the configuration information for the FFmpeg class library.

(5) Other resources
For more resources on Windows app C + + development, you can refer to the article on MSDN, "Creating your first universal Windows app using C + +".


Simplest FFmpeg winphone HelloWorld The directory structure of the project. The C + + source code is located in MainPage.xaml.cpp, and the interface layout file is MainPage.xaml.

MainPage.xaml is the interface layout file, as shown in the following.
<!--simplest FFmpeg winphone HelloWorld--><page x:class= "Simplest_ffmpeg_winphone_helloworld. MainPage "xmlns=" "xmlns:x="/HTTP/ "xmlns:local=" Using:simplest_ffmpeg_winphone_helloworld "xmlns:d="/HTTP/ "xmlns:mc=" 2006 "mc:ignorable=" D "> <stackpanel margin=" 120,30,0,0 "> <textblock horizontalalignment=" left "T ext= "simplest FFmpeg winphone HelloWorld" fontsize= ""/> <textblock text= "click button to see FFmpeg Lib ' s I Nformation "/> <stackpanel orientation=" Horizontal "margin=" 0,20,0,20 "> <button Content=" Prot Ocol "click=" Click_protocol "width=" "horizontalalignment=" left "/> <button content=" Avformat "Click=" C Lick_avformat "width=" horizontalalignment= "left"/> <button content= "Avcodec" click= "Click_avcodec" width= "+" horizontalalignment= "left"/> <button Content= "AVF Ilter "click=" Click_avfilter "width=" "horizontalalignment=" left "/> <button content=" Configuration "Cl ick= "Click_configuration" width= "horizontalalignment=" "left"/> </StackPanel> <textblock X:na Me= "Information" margin= "0,20,0,20"/> </StackPanel></Page>

MainPage.xaml.cpp is a C + + function implementation file, as shown in the following.

/** * Simplest Windows Phone platform under FFmpeg HelloWorld example * simplest FFmpeg winphone HelloWorld * * Lei hua Lei xiaohua * [Email prot   Ected] * Communication University/Digital TV Technology * Communication University of China/digital TV technology * * * This program is the simplest program for porting FFmpeg to the Windows app platform. It can print out the following information for the FFmpeg class library: * Protocols supported by the Protocol:ffmpeg class library * Avformat:ffmpeg supported packaging formats for class libraries * Avcodec:ffmpeg codec supported by Class library * AVFILTER:FFM Supported filters for PEG class Library * Configure:ffmpeg class Library configuration information * * This is the simplest program based on FFmpeg in Windows App Platform. It can show following * informations about FFmpeg library: * Protocol:protocols supported by FFmpeg. * Avformat:container format supported by FFmpeg. * Avcodec:encoder/decoder supported by FFmpeg. * Avfilter:filters supported by FFmpeg. * Configure:configure information of FFmpeg. * */#include "pch.h" #include "mainpage.xaml.h" #include <atlconv.h> #define __stdc_constant_macrosextern "C" {# Include "Libavcodec/avcodec.h" #include "libavformat/avformat.h" #include "libavfIlter/avfilter.h "};using namespace simplest_ffmpeg_winphone_helloworld;using namespace platform;using namespace Windows::foundation;using namespace Windows::foundation::collections;using namespace windows::ui::xaml;using Namespace Windows::ui::xaml::controls;using namespace Windows::ui::xaml::controls::P rimitives;using namespace Windows::ui::xaml::D ata;using namespace windows::ui::xaml::input;using namespace windows::ui::xaml::media;using Namespace Windows::ui::xaml::navigation;using namespace Windows::ui::P opups; Mainpage::mainpage () {InitializeComponent ();} /*** Protocol Support information*/void mainpage::click_protocol (platform::object^ sender, Windows::ui::xaml:: routedeventargs^ e) {//fixstruct Urlprotocol;char info[40000] = {0};av_register_all (); struct Urlprotocol *pup = NULL;// Inputstruct Urlprotocol **p_temp = &pup;avio_enum_protocols ((void * *) p_temp, 0); while ((*p_temp)! = NULL) {sprintf_s (info, sizeof (info), "%s[in][%10s]\n", info, avio_enum_protocols (void * *) p_temp, 0)); Pup = null;//outputavio_enum_protocols ((void * *) p_temp, 1); while ((*p_temp)! = NULL) {sprintf_s (info, sizeof (info), "%s[ out][%10s]\n ", Info, Avio_enum_protocols ((void * *) p_temp, 1)); Uses_conversion; String ^infostr = ref new String (A2W (info)); information->text = Infostr;} /*** Avformat Support information*/void Mainpage::click_avformat (platform::object^ sender, Windows::ui::xaml:: routedeventargs^ e) {char info[40000] = {0};av_register_all (); Avinputformat *if_temp = Av_iformat_next (NULL); Avoutputformat *of_temp = Av_oformat_next (null);//inputwhile (if_temp! = null) {sprintf_s (info, sizeof (info), "%s[in]% 10s\n ", info, if_temp->name); if_temp = If_temp->next;} Outputwhile (of_temp! = NULL) {sprintf_s (info, sizeof (info), "%s[out]%10s\n", info, of_temp->name); of_temp = Of_ Temp->next;} Uses_conversion; String ^infostr = ref new String (A2W (info)); information->text = Infostr;} /*** Avcodec Support information*/void mainpage::click_avcodec (platform::object^ sender, Windows::ui::xaml::routedeventargs^ e) {char info[40000] = {0};av_register_all (); Avcodec *c_temp = Av_codec_next (null), while (c_temp! = null) {if (C_temp->decode! = null) {sprintf_s (info, sizeof (info) , "%s[dec]", info);} else{sprintf_s (info, sizeof (info), "%s[enc]", info);} Switch (c_temp->type) {case avmedia_type_video:sprintf_s (info, sizeof (info), "%s[video]", info); Break;case Avmedia _type_audio:sprintf_s (info, sizeof (info), "%s[audio]", info), break;default:sprintf_s (info, sizeof (info), "%s[other" ", info); break;} sprintf_s (info, sizeof (info), "%s%10s\n", info, c_temp->name); c_temp = C_temp->next;} Uses_conversion; String ^infostr = ref new String (A2W (info)); information->text = Infostr;} /*** avfilter Support information*/void mainpage::click_avfilter (platform::object^ sender, Windows::ui::xaml:: routedeventargs^ e) {char info[40000] = {0};av_register_all (); Avfilter *f_temp = (Avfilter *) avfilter_next (NULL), while (f_temp! = NULL) {sprintf_s (info, sizeof (info), "%s[%10s]\n", info, F_temp->naMe);} Uses_conversion; String ^infostr = ref new String (A2W (info)); information->text = Infostr;} /*** Configuration information*/void mainpage::click_configuration (platform::object^ sender, Windows::ui::xaml:: routedeventargs^ e) {char info[10000] = {0};av_register_all (); sprintf_s (info, sizeof (info), "%s\n", avcodec_ Configuration ()); Uses_conversion; String ^infostr = ref new String (A2W (Avcodec_configuration ()));//information->text = Infostr; Messagedialog (INFOSTR). Showasync ();}

Run results

The program runs after the interface as shown in. Clicking a different button displays information about the different aspects of the FFmpeg class library.

When you click the Configure button, the configuration information is printed as a message box.

simplest ffmpeg mobile

Project Home


Open source China:

This solution contains various examples of using FFMPEG to process multimedia on the mobile side:
Simplest_android_player: Android interface-based video player
Simplest_ffmpeg_android_helloworld: ffmpeg-based HelloWorld program under Android platform
Simplest_ffmpeg_android_ Decoder: The simplest ffmpeg-based video decoder on the Android platform
Simplest_ffmpeg_android_decoder_onelib: The simplest ffmpeg-based video decoder on the Android Platform-Library edition
Simplest_ffmpeg_android_streamer: The simplest ffmpeg based on the Android platform
Simplest_ffmpeg_android_transcoder: FFmpeg command-line tool ported under Android platform
Simplest_sdl_android_helloworld: The simplest program to migrate SDL to the Android platform
Simplest_ios_player: Video player based on iOS interface
FFmpeg-based HelloWorld program under the Simplest_ffmpeg_ios_helloworld:ios platform
Simplest_ffmpeg_ios_decoder: The simplest ffmpeg-based video decoder on the iOS platform
The simplest ffmpeg-based Simplest_ffmpeg_ios_streamer:ios under the platform Simplest_ffmpeg_ios_ FFMPEG.C command-line tool migrated under Transcoder:ios platform
Simplest_sdl_ios_helloworld: The simplest program to migrate SDL to the iOS platform
simplest_ffmpeg_windowsphone_helloworld:windows phone platform

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The simplest mobile-based FFmpeg example: Windows Phone HelloWorld

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.