The simplest mobile terminal example based on FFmpeg: Windows Phone HelloWorld and ffmpeghelloworld

Source: Internet
Author: User

The simplest mobile terminal example based on FFmpeg: Windows Phone HelloWorld and ffmpeghelloworld

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

List of the simplest FFmpeg-based mobile-end example series:

The simplest Mobile End example based on FFmpeg: Android HelloWorld

The simplest example of mobile terminal based on FFmpeg: Android Video Decoder

The simplest example of mobile terminal based on FFmpeg: Android video decoder-single library version

The simplest Mobile End example based on FFmpeg: Android streamer

The simplest example of a mobile terminal based on FFmpeg: Android video Transcoder

The simplest Mobile End example based on FFmpeg attachment: built-in player for Android

The simplest example of FFmpeg-based mobile terminal attachment: SDL Android HelloWorld

The simplest Mobile End example based on FFmpeg: IOS HelloWorld

The simplest example of mobile terminal based on FFmpeg: IOS Video Decoder

The simplest example of Mobile End Based on FFmpeg: IOS streamer

The simplest example of a mobile terminal based on FFmpeg: IOS video Transcoder

The simplest example of a mobile terminal based on FFmpeg attachment: built-in player for IOS

The simplest example of FFmpeg-based mobile terminal: Windows Phone HelloWorld

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


This document records the FFmpeg-based HelloWorld program on Windows Phone. The source code of the C language in this example is from the simplest FFMPEG-based Helloworld program. The related concepts are no longer repeated.

As FFmpeg mobile development only has hands-on experience in Android and IOS, I only used Android and IOS sample programs at the beginning. Two days ago, I attended Microsoft's Windows 10 press conference. When I browsed the information before the conference, I found that Windows 10 had added native support for FFmpeg in video and audio processing. Microsoft also announced an open-source project FFmpegInterop, which is used to compile a class library containing the FFmpeg function for Windows 8.1/10 App. Out of curiosity, I downloaded and played the FFmpegInterop project, and finally summarized a FFmpeg HelloWorld sample program on the Windows Phone platform.



Description of using FFmpeg class library on Windows Phone

The process for using the FFmpeg class library on Windows Phone platform (Windows App Store) is as follows.

1. Compile the FFmpeg class library

(1) install VS2013 and MSYS2 (it is better to use these two tools to compile FFmpeg on PC ).

(2) Get the FFmpegInterop project (the project is located on Github and the address is https://github.com/Microsoft/FFmpegInterop ).

(3) Add the FFmpeg source code. After downloading the source code from the official website, decompress the source code to the ffmpeg directory of FFmpegInterop.

(4) Start the "VS2013 developer command prompt" console as an administrator and switch to the FFmpegInterop directory.

(5) Configure MSYS2 and run the following command to set the MSYS2_BIN environment variable (depending on the installation path of MSYS2 ):
set MSYS2_BIN="E:\msys64\usr\bin\bash.exe"

(6) handle a small Bug. Modify the name of link.exein msys2(can be changed at will, for example, “link_msys.exe "). Compilation fails. I don't know if all the machines have this problem. At that time, I was stuck for a while.

(7) execute the command to compile the class library. Run BuildFFmpeg. bat to print the Help menu. Execute the following statement to compile the class library on the Windows 8.1 x86 platform. The compiled class library is located in the "ffmpeg \ Build \ Windows8.1 \ x86" directory.
BuildFFmpeg win8.1 x86
Execute the following statement to compile the class libraries on the Windows 8.1 x86 and x64 platforms at the same time.
BuildFFmpeg win8.1 x86 x64
Other compilation commands are not described in detail. You can view 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 generated dll is different from the dll used in the console or MFC program. The dll here is the dll with the flag of AppContainer. If you use a common console program to call the dll generated here, the error "0xc000a200" will be reported ":
Error 0xc000a200: shows up when regular process (not inside an AppContainer) tries to load DLL that was marked with AppContainer flag.
(8) Open the sln solution in the samples folder [Optional]. This sln solution contains the FFmpegInterop Library source code project and some sample programs. This part of the source code has not been carefully read (this article does not involve the content of this part of the Code ).

2. Compile a program on the Windows Phone platform

(1) create a "Windows App Store" program.Choose File> New> Project> Visual C ++> Windows App Store> blank application (XAML )".

(2) copy the compiled class library to the project directory (note that x86, x64, and other platforms must correspond to each other ).Create an include folder to store the header file (*. h); lib folder to store the imported file (*. lib); and copy the dynamic library file (*. dll) directly to the directory.

(3) configure the class library.Perform the following three steps:
A) header file configuration
Solution Explorer-> right-click Project-> properties panel
Property panel-> C/C ++-> General-> Add the include directory and enter "include" (the directory where the header file was copied just now)
B) import to Database Configuration
Property panel-> linker-> General-> additional library directory, enter "lib" (directory of the library file just copied)
Property panel-> linker-> input-> additional dependencies, enter "avcodec. lib; avformat. lib; avutil. lib; avdevice. lib; avfilter. lib; swresample. lib; swscale. lib "(Imported file name)
C) dynamic library configuration (an important and distinctive step)
Solution Explorer-> right-click Project-> Add-> existing item to add the dll file
Right-click each dll file and choose Properties> General> content to set it to yes"
(4) test
A) Editing page
Add a Button in 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="36"/>        <Button Content="Configure Info" Click="Button_Clicked"/>        <TextBlock x:Name="greetingOutput"/>    </StackPanel></Page>
B) edit the code
Add a Button_Clicked () code to 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::Popups::MessageDialog(info).ShowAsync();}
This Code calls avcodec_configuration () to obtain the configuration information of the FFmpeg class library, and then calls MessageDialog () to display the information in a dialog box. Note that a A2W () macro in atlconv. h is used to convert char * to Platform: String.
Add the header file used in 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 the configurations are correct, the running result of the Windows App is shown in. Click the button in the upper left corner to display the configuration information of the FFmpeg class library.

 

(5) Other resources
For more information about Windows App C ++ development, see the article "use C ++ to create your first common Windows application" on MSDN.


Source code

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


MainPage. xaml is an interface layout file with the following content.
<!-- 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" Text="Simplest FFmpeg WinPhone HelloWorld" FontSize="36"/>        <TextBlock Text="Click button to see FFmpeg lib's information"/>        <StackPanel Orientation="Horizontal" Margin="0,20,0,20">            <Button Content="Protocol" Click="click_protocol" Width="120" HorizontalAlignment="Left"/>            <Button Content="AVFormat" Click="click_avformat" Width="120" HorizontalAlignment="Left"/>            <Button Content="AVCodec" Click="click_avcodec" Width="120" HorizontalAlignment="Left"/>            <Button Content="AVFilter" Click="click_avfilter" Width="120" HorizontalAlignment="Left"/>            <Button Content="Configuration" Click="click_configuration" Width="120" HorizontalAlignment="Left"/>        </StackPanel>        <TextBlock x:Name="information" Margin="0,20,0,20"/>    </StackPanel></Page>

MainPage. xaml. cpp is the C ++ function implementation file, the content is as follows.

/*** Example of FFmpeg HelloWorld in Windows Phone ** Simplest FFmpeg WinPhone HelloWorld ** leixiao Lei Xiaohua * leixiaohua1020@126.com * China Media University/Digital TV technology * Communication University of China/Digital TV Technology * http://blog.csdn.net/leixiaohua1020 ** this program is the simplest program to transplant FFmpeg to the Windows App platform. It can print the following information about the FFmpeg Class Library: * Protocol: the Protocol supported by the FFmpeg class library * AVFormat: the Encapsulation Format supported by the FFmpeg class library * AVCodec: the encoding and decoder * AVFilter supported by the FFmpeg Class Library: * Configure: configuration information of the FFmpeg class library ** 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/D Ecoder 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; us Ing namespace Windows: Foundation; using namespace Windows: Foundation: Collections; using namespace Windows: UI: Xaml: Controls; using namespace Windows: UI: Xaml: Controls: Primitives; using namespace Windows: UI: Xaml: Data; using namespace Windows: UI: Xaml :: input; using namespace Windows: UI: Xaml: Media; using namespace Windows: UI: Xaml: Navigation; using namespace Windows: UI: Popups; 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] [% 10 s] \ 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] [% 10 s] \ 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_iforma T_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); w Hile (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 [% 10 s] \ 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 ();}


Running result

Shows the interface after running the program. Click different buttons to display different information about the FFmpeg class library.


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




Download
Simplest ffmpeg mobile


Project Homepage

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 contains various examples of using FFmpeg to process multimedia on mobile terminals:
[Android]
Simplest_android_player: Android-Based Video Player
Simplest_ffmpeg_android_helloworld: The FFmpeg-based HelloWorld program in Android
Simplest_ffmpeg_android_decoder: the simplest FFmpeg-based video decoder on Android
Simplest_ffmpeg_android_decoder_onelib: the simplest FFmpeg-Based Video Decoder for Android-single library
Simplest_ffmpeg_android_streamer: the simplest FFmpeg-based streamer on Android
Simplest_ffmpeg_android_transcoder: The FFmpeg command line tool transplanted on the Android platform
Simplest_sdl_android_helloworld: the simplest program to port SDL to Android.
[IOS]
Simplest_ios_player: A Video Player Based on the IOS Interface
Simplest_ffmpeg_ios_helloworld: The FFmpeg-based HelloWorld program in IOS
Simplest_ffmpeg_ios_decoder: the simplest FFmpeg-based video decoder on IOS
Simplest_ffmpeg_ios_streamer: the simplest FFmpeg-based streamer on IOS
Simplest_ffmpeg_ios_transcoder: The ffmpeg. c command line tool transplanted on the IOS platform
Simplest_sdl_ios_helloworld: the simplest program to port SDL to IOS.
[Windows]
Simplest_ffmpeg_windowsphone_helloworld: The FFmpeg-based HelloWorld program in Windows Phone


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.