FFmpeg4.2.1 series
- [-ffMPEG4.2.1 -] CLion integration, Xcode integration, Android integration
- [-iFFmPEG4.2.1 -] Decode – extract video data H264 and YUV
My ultimate goal is mobile. But in order to facilitate the cognition and debugging of FFmpeg, first digest it on the desktop, after all, in Android to modify, debugging are more difficult. Knowledge runs all the way to the same destination. It’s not where it is, it’s what it does, what you want with it. FFmpeg is written in C and needs to be dynamically linked to the corresponding library when used. While you can rip code by hand with a text editor and command line, an IDE can make it easier to tune your hair. Here’s how Xcode and CLion desktop and Android integrate FFmpeg. This post has only one goal: to run
1. Install and configure FFMPEG
1.1: install ffmpeg
Brew can install FFMPEG, which is fully equipped with FFMPEG and enables a lot of things, so downloading can be time-consuming. You can also download ffMPEG official, according to your own requirements to compile.
- [· brew install ffmpegCopy the code
1.2: View FFMPEG information
Brew info ffmpeg Check the current information and see the installation folder
Brew info ffmpeg ffmpeg: Stable 4.2.1 (Bottler), HEAD Play, record, convert, and stream audio and video https://ffmpeg.org/ /usr/local/Cellar/ ffmPEG / 4.2.2_2 (sailing from bottle on 2019-11-26 at 09:16:29 FROM: https://github.com/Homebrew/homebrew-core/blob/master/Formula/ffmpeg.rb ==> Dependencies Build: - Nasm ➤, PKG-config ➤, texi2HTML Aom stocking, fontconfig stocking, freetype stocking, frei0r stocking, gnutls stocking, lame stocking, libass stocking, libsoxr stocking, libvidstab stocking, Libvorbis stocking, libvpx stocking, opencore stocking, openJPEG stocking, opus stocking, rtmpstocking stocking, rubberband stocking, sdL2 stocking, snappy stocking, speex stocking, Tesseract ➤, theora ➤, x264 ➤, x265 ➤, xvid ➤, xz ➤ ==> Options --HEAD Install HEAD versionCopy the code
1.3: Configure the FFMPEG environment variable
Add the bin path to the environment variable file to facilitate global access to internal self-contained files.
export PATH=$PATH:/usr/local/ Cellar/ffmpeg / 2 _2 / binCopy the code
1.4: Check whether the FFMPEG environment is OK
Add the bin path to the environment variable file to facilitate global access to internal self-contained files.
--[· FFMPEG FFMPEG Version 4.2.1 Copyright (C) 2000-2019 The FFMPEG developers built with Apple Clang Version 11.0.0 (clang - 1100.0.33.8) configuration: -- prefix = / usr /local/Cellar/ffmpeg/4.2.1_2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include/darwin -fno-stack-check'--host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr -- enable-videoToolbox --disable-libjack --disable-indev= Jack libavUtil 56.31.100/56.31.100 libavCodec 58.54.100 / Libavformat 58.29.100/58.29.100 libavDevice 58.8.100/58.8.100 libavFilter 7.57.100/7.57.100 Libavresample 4. 0/0/4. 0 libswScale 5. 5.100/5. 5.100 libswresample 3. 5.100/3 55. 5.100 Hyper Fast Audio and Video Encoder Usage: ffmPEG [options] [[Infile options] -I Infile]... {[outfile options] outfile}...Copy the code
2. Ffmpeg related content
- [·cd /usr/local/Cellar/ffmpeg/ 4.2._2 --[· ls Changelog readme. md lib INSTALL_RECEIPT. Json bin share license. md includeCopy the code
2.1 Resource Library Lib
This is where the dynamic link library, the soul of FFMPEG, resides
- [·cdLib - [ls, libavcodec. 58.54.100. Dylib libavresample. Dylib libavcodec. 58. Dylib libavutil. 56.31.100. Dylib libavcodec. A Libavutil. 56. Dylib libavcodec. Dylib libavutil. A libavdevice 58.8.100. Dylib libavutil. Dylib libavdevice. 58. Dylib Libpostproc. 55.5.100. Dylib libavdevice. A libpostproc. 55. The dylib libavdevice. Dylib libpostproc. A libavfilter 7.57.100. Dylib Libpostproc. Dylib libavfilter. 7. Dylib libswresample. 3.5.100. Dylib libavfilter. A libswresample. 3. The dylib libavfilter. Dylib Libswresample. A libavformat. 58.29.100. Dylib libswresample. Dylib libavformat. 58. Dylib libswscale. 5.5.100. Dylib Libavformat. A libswscale. 5. Dylib libavformat. Dylib libswscale. A libavresample 4.0.0. Dylib libswscale. Dylib libavresample.4.dylib pkgconfig libavresample.aCopy the code
2.2 Header File include
Header files, which are indexes of all functions, need to be used with related header files
- [·cd. - [·cdInclude --[· ls libavcodec libavfilter libavresample libpostproc libswscale libavdevice libavformat libavutil include --[· ls libavcodec libavfilter libavresample libpostproc libswscale libavdevice libavformat libavutil Libswresample - [·cdLibavutil --[· ls adler32.h hwContext_vapi.h aes.h hwContext_vdPau. H aes_ctr.h hwContext_VideoToolbox.h attributes Imgutils. h audio_fifo.h intfloat. H...Copy the code
2.3 Storing the executable file bin
Can directly through ffMPEG through the command line operation of audio and video, FFplay play audio and video
- [· 2 _2%cd /usr/local/Cellar/ffmpeg/ 4.2._2 /bin --[· bin % ls... ffmpeg normalize.py zmqshell.py ffplay patcheckCopy the code
In addition, the share folder has some small demos, which are very valuable for reference.
3. Clion integrated FFmpeg
3.1 Creating a Project
It doesn’t matter if you choose C++ or C. If you want to use C++ features, choose C++, otherwise you can just write C.
3.2 CMakeLists configuration
Note the corresponding FFmpeg directory instead. Add the required link libraries to the target_link_libraries. There are eight green Onions in total. You can add them as required. Green Onions live in the lib folder above and are eaten with their heads pinched to keep them healthy.
- [CMakeLists. TXT] - cmake_minimum_required (VERSION 3.15) project (TolyFF)set(CMAKE_CXX_STANDARD 14)
set(FFMPEG_DIR /usr/local/Cellar/ffmpeg/4.2.1_2) # FFmpeg installation directory
include_directories(${FFMPEG_DIR}/include/) # header file path
link_directories(${FFMPEG_DIR}/lib/) Link library path
add_executable(TolyFF main.cpp)
target_link_libraries(TolyFF
avutil # link avutil
avcodec # link avcodec
)
Copy the code
3.3 Simply use FFmpeg
Ffmpeg has its own logging system, defined in libavutil#log.h, used as follows. Here you can see the configuration parameters at compile time using avcodec_configuration()
#include <iostream>
extern "C"{// special processing in C++#include "libavutil/log.h"
#include "libavcodec/avcodec.h"
}
int main() {
std::cout << "Hello, World!"<< std::endl; av_log_set_level(AV_LOG_DEBUG); // Set the log level av_log(nullptr,AV_LOG_INFO,"hello ffmpeg\n"); Auto info= AVCOdec_configuration (); Av_log (nullptr,AV_LOG_DEBUG,"Configuration: % s",info);
return 0;
}
Copy the code
OK, it’s that simple. The gates of hell are open. Go in, kid.
4. The Xcode integrated FFmpeg
If you’re more comfortable with Xcode, here’s a look at it
4.1 Creating a Project
4.2 Configuring a Link Library
Configure the Build Settings and Build Phases as follows
4.3 Writing code and crashing
#include <iostream>
extern "C"{// special processing in C++#include "libavutil/log.h"
#include "libavcodec/avcodec.h"
}
int main() {
std::cout << "Hello, World!"<< std::endl; av_log_set_level(AV_LOG_DEBUG); // Set the log level av_log(nullptr,AV_LOG_INFO,"hello ffmpeg\n"); Auto info= AVCOdec_configuration (); Av_log (nullptr,AV_LOG_DEBUG,"Configuration: % s",info);
return 0;
}
Copy the code
No accident will collapse: can not find the library, see the log shows, is the signature of the pot.
4.4 Signing a Library
View your certificate in keychain (no new one to create)
- [codesign-f -s "Apple Development: [email protected]" /usr/local/ Cellar/ffmpeg / 2 _2 / lib / *. Dylib - [codesign-f -s "Apple Development: [email protected]" /usr/local/opt/*/lib/*.dylib
Copy the code
OK, the gates of hell are open. Have fun.
4. The Android integration FFmpeg
Compilation of C/C++ library compilation of C/C++ library compilation
4.1 New Native project
Step by step to create no nonsense
4.2 introduction of ffmpeg
Cmakelists. TXT and CLion are similar to those in cmakelists. TXT and CLion to help build and link to the dynamic library. The Internet is basically a bunch of fully configured, but remember that each library has its own function, you don’t need to take out an ICBM to shoot a mosquito. Here is a look at the compiled configuration information using only AVCodec. Other libraries can be added as needed.
- [CMakeLists. TXT] - cmake_minimum_required (VERSION 3.4.1 track) include_directories (include)# import header files
add_library(TolyFF SHARED native-lib.cpp)
set(distribution_DIR ${CMAKE_SOURCE_DIR}/.. /jniLibs/${ANDROID_ABI})
add_library(avcodec SHARED IMPORTED)
set_target_properties(avcodec PROPERTIES IMPORTED_LOCATION ${distribution_DIR}/libavcodec.so)
find_library(log-lib log)
target_link_libraries(
TolyFF
avcodec
${log-lib})
Copy the code
4.3 c + + code
We started with a helloWorld method, so let’s go back to avcodec_configuration
#include <jni.h>
#include <string>
extern "C"{
#include <libavcodec/avcodec.h>
}
extern "C"
JNIEXPORT jstring JNICALL
Java_com_toly1994_tolyff_TolyFF_getConfiguration(JNIEnv *env, jclass clazz) {
return env->NewStringUTF(avcodec_configuration());
}
Copy the code
It’s not about where it is, it’s about what it does, what you want to do with it, and desktop features can be easily ported to mobile, they’re all-in-one. The platform is all paper tiger, the key and difficult is to understand the flow and audio and video nature.
@zhang Fengjie Special strength 2019.11.26 not allowed to transfer my public number: king of programming ~ END ~