Simplest FFmpeg-based mobile sample: Windows Phone HelloWorld

Source: Internet
Author: User





=====================================================



The simplest example of a ffmpeg-based mobile Sample series article List:



The simplest mobile-based example of FFmpeg: Android HelloWorld



The simplest ffmpeg-based mobile sample: Android Video Decoder



Simplest FFmpeg-based mobile sample: Android Video Decoder-Single library version



Simplest FFmpeg-based mobile sample: Android push-to-stream



The simplest ffmpeg-based mobile sample: Android video transcoding



Simplest FFmpeg-based mobile sample attachment: Android comes with player



Simplest FFmpeg-based mobile sample attachment: SDL Android HelloWorld



The simplest ffmpeg-based mobile sample: IOS HelloWorld



The simplest ffmpeg-based mobile sample: IOS Video Decoder



Simplest FFmpeg-based mobile sample: IOS push-to-stream



The simplest ffmpeg-based mobile sample: IOS video transcoding



Simplest FFmpeg-based mobile sample attachment: iOS comes with player



Simplest FFmpeg-based mobile sample: Windows Phone HelloWorld



=====================================================




This document records the FFmpeg-based HelloWorld program under the Windows Phone platform. The source code for the demo sample C language is from the simplest ffmpeg-based HelloWorld program. The related concepts are no longer recorded repeatedly.






Because there is only Android and iOS combat experience in FFmpeg mobile development. So I just started out with a demo sample program for Android and iOS.



The previous two days to participate in Microsoft's Windows 10 Conference, the pre-visit information when the Windows 10 in AV processing has joined the ffmpeg of native support. At the same time Microsoft also released an open source project Ffmpeginterop. A class library specifically designed to compile the FFmpeg functionality to the Windows? Out of curiosity i downloaded and ffmpeginterop this project and finally summed up a demo sample program that ffmpeg the HelloWorld on the Windows Phone platform.








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


Windows Phone Platform (Windows App Store. Windows Store) The process of using the FFmpeg class library is seen in the following example.





1. Compiling the FFmpeg class library


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






(2) Get Ffmpeginteropproject (the project is on GitHub and the address is Https://github.com/Microsoft/FFmpegInterop).



(3) Add FFmpeg source code.



Download the source code from the official website, extract the source code into the Ffmpeginterop ffmpeg folder.



(4) Start the "VS2013 Developer Command Prompt" console as an administrator. Switch to the Ffmpeginterop folder.


(5) Configure the MSYS2. Execute 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. It is necessary to change the name of the Link.exe in the MSYS2 (one can be changed, such as "Link_msys.exe"). Because the MSYS2 in the Link.exe and VS2013 in the same name, assuming that the names will not change the system will mistakenly use MSYS2 link.exe (rather than VS2013 link.exe). This causes the compilation to fail. Do not know is not all of 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" folder.


Buildffmpeg win8.1 x86
Executing the following statement compiles the class library for 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. Assume that the DLL generated here is called using a normal console program. 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 project and some demo sample programs. This part of the source has not been carefully 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 folder (note that x86, x64, and so on are the appropriate platforms).



Create a new include folder store header file (*.h). The Lib folder stores the import library file (*.lib) and copies the dynamic library file (*.dll) directly to the folder.





(3) Configure the class library. Divided into the following 3 steps:
A) header file configuration
Solution Explorer, right-click Project, Properties panel
The Properties panel->c/c++-> general, add-ons include folders. Enter "include" (the folder where you just copied the header file)
b) Import library configuration
Add-in library folder, general--, linker, properties panel, type "Lib" (the folder 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 Project, join the existing item, add the DLL file in
Select each DLL file, right-click Properties, General--, set to Yes
(4) test
a) editing interface
Add a Buttonbutton to the MainPage.xaml and add a "button_clicked ()" Response function.
<page    x:class= "testapp.mainpage"    xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:local= "Using:testapp"    xmlns:d= "http ://schemas.microsoft.com/expression/blend/2008 "    xmlns:mc=" http://schemas.openxmlformats.org/ 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 to the MainPage.xaml.cpp. For example, see 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 configuration information for the FFmpeg class library. Then call Messagedialog () to pop up a dialog box to display the information. Note that a macro that uses a a2w () in Atlconv.h is used. Used to convert char * to platform::string.



Add the header file used to the MainPage.xaml.cpp header, as seen below.


#include <atlconv.h>extern "C" {#include "libavcodec/avcodec.h"}
in mainpage.xaml.h, add the declaration of the response function, as seen below.
Public ref class MainPage sealed{public:mainpage (); void button_clicked (platform::object^ sender, Windows::ui::xaml:: routedeventargs^ e);};
Let's say everything is in the wrong configuration. The results of the Windows app execution are as seen. Clicking the button in the upper-left corner pops up the configuration information for the FFmpeg class library.






(5) Other resources
Specific resources for Windows app C + + development are available in the article on MSDN, "Creating your first universal Windows app using C + +".








Source



Simplest FFmpeg winphone HelloWorld the folder structure of the project is seen. C + + source is located in MainPage.xaml.cpp. The interface layout file is MainPage.xaml.





MainPage.xaml is the interface layout file. The contents are as seen below.







<!--simplest FFmpeg winphone HelloWorld--><page x:class= "Simplest_ffmpeg_winphone_helloworld. MainPage "xmlns=" http://schemas.microsoft.com/winfx/2006/xaml/presentation "xmlns:x="/HTTP/ Schemas.microsoft.com/winfx/2006/xaml "xmlns:local=" Using:simplest_ffmpeg_winphone_helloworld "xmlns:d="/HTTP/ schemas.microsoft.com/expression/blend/2008 "xmlns:mc=" http://schemas.openxmlformats.org/markup-compatibility/ 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. The contents are as seen below.




/** * Simplest Windows Phone platform under FFmpeg HelloWorld sample * simplest FFmpeg winphone HelloWorld * * Lei hua Lei xiaohua * [Email prot   Ected] * Communication University/Digital TV Technology * Communication University of China/digital TV technology * http://blog.csdn.net/leixiaohua1020 * * 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  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};avfilter_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 ();}







Execution results


After the program executes the interface for example as seen. 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.







Download
simplest ffmpeg mobile




Project Home


Github:https://github.com/leixiaohua1020/simplest_ffmpeg_mobile


Open source China: https://git.oschina.net/leixiaohua1020/simplest_ffmpeg_mobile


sourceforge:https://sourceforge.net/projects/simplestffmpegmobile/





This solution includes various examples of using to process multimedia on the mobile side:
[Android]
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
[IOS]
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_ C command-line tool migrated under Transcoder:ios platform
Simplest_sdl_ios_helloworld: The simplest program to migrate SDL to the iOS platform
[Windows]
simplest_ffmpeg_windowsphone_helloworld:windows phone platform



Simplest FFmpeg-based mobile sample: Windows Phone HelloWorld


Related Article

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.