Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
Save Slow motion video with ffmpeg on android devices
25 mars 2017, par nkalra0123I want to save videos in slow motion through my android app.I tried to convert videos into slow motion by changing frame rate.
I used the following commands,first command is dumping 30 frames per second from videos to a temp directory, and then second command is using these images to create a video with reduced or faster frame rate and then i am deleting all the images from temp directory.
ffmpeg -i input_file.mp4 -r 30/1 img%03d.png ffmpeg -framerate 15/1 -i img%03d.png -r 30 -pix_fmt yuv420p out4.mp4
But this is a very slow operation. It is taking like forever even for small videos.
I even tried to change PTS(presentation time stamp) of videos, but it is not working properly on android phones using this command:
ffmpeg -i input.mkv -filter:v "setpts=2.0*PTS" output.mkv
as suggested here: https://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video
Can anybody suggest me how can i make it fast. Is it necessary to save frames to a temp directory, can i pass the output of ffmpeg process to another ffmpeg process executing concurrently through some method.
Is there any other ffmpeg command to save the videos in slow motion?
-
"Invalid data found when processing input" no matter the FFMPEG configuration
25 mars 2017, par Jamie BonnettI've been stumped on this for a while now, no matter the configuration if use in NodeJS I always get the same error "Error: ffmpeg exited with code 1".
Here's my code:
var http = require('http'); var fs = require('fs'); var ffmpeg = require('fluent-ffmpeg'); var server = http.createServer(function(req, res) { var seektime = 100; var pathToMovie = __dirname + '/src/video.mp4'; var stat = fs.statSync(pathToMovie); res.writeHead(200, { 'Content-Type': 'video/mp4', 'Content-Length': stat.size }); var proc = new ffmpeg(pathToMovie) .seekInput(seektime) .withVideoBitrate(1024) .withVideoCodec('libx264') .withAspect('16:9') .withFps(24) .toFormat('mp4'); var ffstream = proc.pipe(res, {end:true}); ffstream.on('data', function(chunk) { console.log('ffmpeg just wrote ' + chunk.length + ' bytes'); }); }); server.listen(8000);
I have no idea what to do now. Any ideas?
Thanks, Jamie
-
Cant link against ffmpeg with openssl using cmake
24 mars 2017, par David BarishevI have build ffmpeg libraries statically for x86 android using a custom configuration.Now i wanted to add them in my android project.
Im using ffmpeg 3.2.git, android studio 2.3.
I created a folder named distribution which had my binaries, and the minimum headers i needed for it to not tell me about missing header (Except for the avutil- i just included them all), located the root of my project.
I edited my cmake to include the libraries:add_library( native-lib SHARED src/main/cpp/native-lib.cpp ) set(distribution_DIR ${CMAKE_SOURCE_DIR}/../distribution) add_library(lib_avcodec STATIC IMPORTED) set_target_properties(lib_avcodec PROPERTIES IMPORTED_LOCATION ${distribution_DIR}/libavcodec/lib/${ANDROID_ABI}/libavcodec.a) add_library(lib_avfilter STATIC IMPORTED) set_target_properties(lib_avfilter PROPERTIES IMPORTED_LOCATION ${distribution_DIR}/libavfilter/lib/${ANDROID_ABI}/libavfilter.a) add_library(lib_avformat STATIC IMPORTED) set_target_properties(lib_avformat PROPERTIES IMPORTED_LOCATION ${distribution_DIR}/libavformat/lib/${ANDROID_ABI}/libavformat.a) add_library(lib_avutil STATIC IMPORTED) set_target_properties(lib_avutil PROPERTIES IMPORTED_LOCATION ${distribution_DIR}/libavutil/lib/${ANDROID_ABI}/libavutil.a) add_library(lib_swresample STATIC IMPORTED) set_target_properties(lib_swresample PROPERTIES IMPORTED_LOCATION ${distribution_DIR}/libswresample/lib/${ANDROID_ABI}/libswresample.a) include_directories( ${distribution_DIR} ) find_library( # Sets the name of the path variable. z-lib # Specifies the name of the NDK library that # you want CMake to locate. z ) target_link_libraries( native-lib ${z-lib} lib_crypto lib_ssl lib_avfilter lib_avformat lib_avcodec lib_swresample lib_avutil )
I also restricted the build to only x86, in my app build.gradle :
ndk { // Specifies the ABI configurations of your native // libraries Gradle should build and package with your APK. abiFilters 'x86' }
The project gradle sync worked successfully.
I wrote the following code in my cpp file :#include extern "C"{ #include "libavformat/avformat.h" } JNIEXPORT void JNICALL Java_com_example_david_testffmpegcpp_MainActivity_stringFromJNI( JNIEnv *env, jobject /* this */) { av_register_all (); avformat_network_init (); }
Just to check if the library works, but i cant seem to link against the libraries correctly. It complains about undefined symbols. What did i do wrong ?
EDIT:
I changed the order of the linked libraries, and was able to remove all error for ffmpeg's library functions not found, and i added zlib,that removed some more.
The only error left are those how are related to openssl, its logical since i compiled my ffmpeg libraries with openssl.
I tried linking my openssl static libraries that i used for compiling ffmpeg like this :
set(ssl_dir ${CMAKE_SOURCE_DIR}/../../../FFmpegBuild/Openssl/output_19/android) add_library(lib_ssl STATIC IMPORTED) set_target_properties(lib_ssl PROPERTIES IMPORTED_LOCATION ${ssl_dir}/openssl-${ANDROID_ABI}/lib/libssl.a) add_library(lib_crypto STATIC IMPORTED) set_target_properties(lib_crypto PROPERTIES IMPORTED_LOCATION ${ssl_dir}/openssl-${ANDROID_ABI}/lib/libcrypto.a) include_directories( ${ssl_dir}/openssl-${ANDROID_ABI}/include ${distribution_DIR} )
And linked against them :
target_link_libraries( # Specifies the target library. native-lib ${z-lib} lib_ssl lib_crypto lib_avfilter lib_avformat lib_avcodec lib_swresample lib_avutil )
But i'm still getting the error that i state below. My question is why ? Also if i already built ffmpeg in static mode, how come i need to relink openssl again ?
Error :
Error while executing process D:\AndroidSDK\cmake\3.6.3155560\bin\cmake.exe with arguments {--build D:\AndroidApps\TestFFmpegCpp\app\.externalNativeBuild\cmake\debug\x86 --target native-lib} [1/1] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\x86\libnative-lib.so FAILED: cmd.exe /C "cd . && D:\AndroidSDK\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=i686-none-linux-android --gcc-toolchain=D:/AndroidSDK/ndk-bundle/toolchains/x86-4.9/prebuilt/windows-x86_64 --sysroot=D:/AndroidSDK/ndk-bundle/platforms/android-19/arch-x86 -fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -Wa,--noexecstack -Wformat -Werror=format-security -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -Wa,--noexecstack -Wformat -Werror=format-security -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\x86\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -lz ../../../../../../../FFmpegBuild/Openssl/output_19/android/openssl-x86/lib/libcrypto.a ../../../../../../../FFmpegBuild/Openssl/output_19/android/openssl-x86/lib/libssl.a ../../../../../distribution/libavfilter/lib/x86/libavfilter.a ../../../../../distribution/libavformat/lib/x86/libavformat.a ../../../../../distribution/libavcodec/lib/x86/libavcodec.a ../../../../../distribution/libswresample/lib/x86/libswresample.a ../../../../../distribution/libavutil/lib/x86/libavutil.a -lm "D:/AndroidSDK/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/libgnustl_static.a" && cd ." src/libavformat/tls_openssl.c:125: error: undefined reference to 'BIO_clear_flags' src/libavformat/tls_openssl.c:102: error: undefined reference to 'BIO_clear_flags' src/libavformat/tls_openssl.c:116: error: undefined reference to 'BIO_clear_flags' src/libavformat/tls_openssl.c:116: error: undefined reference to 'BIO_clear_flags' src/libavformat/tls_openssl.c:309: error: undefined reference to 'SSL_read' src/libavformat/tls_openssl.c:200: error: undefined reference to 'ERR_get_error' src/libavformat/tls_openssl.c:200: error: undefined reference to 'ERR_error_string' src/libavformat/tls_openssl.c:320: error: undefined reference to 'SSL_write' src/libavformat/tls_openssl.c:200: error: undefined reference to 'ERR_get_error' src/libavformat/tls_openssl.c:200: error: undefined reference to 'ERR_error_string' src/libavformat/tls_openssl.c:154: error: undefined reference to 'SSL_library_init' src/libavformat/tls_openssl.c:155: error: undefined reference to 'SSL_load_error_strings' src/libavformat/tls_openssl.c:157: error: undefined reference to 'CRYPTO_get_locking_callback' src/libavformat/tls_openssl.c:159: error: undefined reference to 'CRYPTO_num_locks' src/libavformat/tls_openssl.c:165: error: undefined reference to 'CRYPTO_num_locks' src/libavformat/tls_openssl.c:167: error: undefined reference to 'CRYPTO_set_locking_callback' src/libavformat/tls_openssl.c:186: error: undefined reference to 'CRYPTO_get_locking_callback' src/libavformat/tls_openssl.c:188: error: undefined reference to 'CRYPTO_set_locking_callback' src/libavformat/tls_openssl.c:189: error: undefined reference to 'CRYPTO_num_locks' src/libavformat/tls_openssl.c:208: error: undefined reference to 'SSL_shutdown' src/libavformat/tls_openssl.c:209: error: undefined reference to 'SSL_free' src/libavformat/tls_openssl.c:212: error: undefined reference to 'SSL_CTX_free' src/libavformat/tls_openssl.c:240: error: undefined reference to 'SSLv23_client_method' src/libavformat/tls_openssl.c:240: error: undefined reference to 'SSL_CTX_new' src/libavformat/tls_openssl.c:246: error: undefined reference to 'SSL_CTX_ctrl' src/libavformat/tls_openssl.c:248: error: undefined reference to 'SSL_CTX_load_verify_locations' src/libavformat/tls_openssl.c:251: error: undefined reference to 'SSL_CTX_use_certificate_chain_file' src/libavformat/tls_openssl.c:257: error: undefined reference to 'SSL_CTX_use_PrivateKey_file' src/libavformat/tls_openssl.c:267: error: undefined reference to 'SSL_new' src/libavformat/tls_openssl.c:284: error: undefined reference to 'BIO_new' src/libavformat/tls_openssl.c:287: error: undefined reference to 'SSL_set_bio' src/libavformat/tls_openssl.c:290: error: undefined reference to 'SSL_accept' src/libavformat/tls_openssl.c:240: error: undefined reference to 'SSLv23_server_method' src/libavformat/tls_openssl.c:258: error: undefined reference to 'ERR_get_error' src/libavformat/tls_openssl.c:258: error: undefined reference to 'ERR_error_string' src/libavformat/tls_openssl.c:208: error: undefined reference to 'SSL_shutdown' src/libavformat/tls_openssl.c:209: error: undefined reference to 'SSL_free' src/libavformat/tls_openssl.c:212: error: undefined reference to 'SSL_CTX_free' src/libavformat/tls_openssl.c:290: error: undefined reference to 'SSL_connect' src/libavformat/tls_openssl.c:200: error: undefined reference to 'ERR_get_error' src/libavformat/tls_openssl.c:200: error: undefined reference to 'ERR_error_string' src/libavformat/tls_openssl.c:266: error: undefined reference to 'SSL_CTX_set_verify' src/libavformat/tls_openssl.c:289: error: undefined reference to 'SSL_ctrl' clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed.
-
Could not load or assembly or one of its dependencies
24 mars 2017, par Prathibha ChiranthanaI am using Aforge.net frame work for doing image processing work. I have add 'AForge.Video.FFMPEG.dll' as a referance to my project. I am using VS2012 and 32 bit build target. When Buiding i get
System.IO.FileNotFoundException was unhandled HResult=-2147024770 Message=Could not load file or assembly 'AForge.Video.FFMPEG.dll' or one of its dependencies. The specified module could not be found. Source=VideoReadere FileName=AForge.Video.FFMPEG.dll FusionLog="" StackTrace: at VideoReadere.Form1..ctor() at VideoReadere.Program.Main() in c:\Users\Prabad\Documents\Visual Studio 2012\Projects\VideoReadere\VideoReadere\Program.cs:line 19 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:
my code for that is occur exception
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; namespace VideoReadere { static class Program { ///
/// The main entry point for the application. /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //here below line give exception Application.Run(new Form1()); } } } -
Convert an h264 byte string to OpenCV images
24 mars 2017, par Fred DufresneIn Python, how do I convert an h264 byte string to images OpenCV can read, only keeping the latest image?
Long version:
Hi everyone.
Working in Python, I'm trying to get the output from adb screenrecord piped in a way that allows me to capture a frame whenever I need it and use it with OpenCV. As I understand, I need to constantly read the stream because it's h264.
I've tried multiple things to get it working and concluded that I needed to ask for specific help.
The following gets me the stream I need and works very well when I print stream.stdout.read(n).
import subprocess as sp adbCmd = ['adb', 'exec-out', 'screenrecord', '--output-format=h264', '-'] stream = sp.Popen(adbCmd, stdout = sp.PIPE, universal_newlines = True)
Universal newlines was necessary to get it to work on Windows.
Doing:
sp.call(['ffplay', '-'], stdin = stream.stdout, universal_newlines = True)
Works.
The problem is I am now trying to use ffmpeg to take the input h264 stream and output as many frames as possible, overwriting the last frame if needed.
ffmpegCmd = ['ffmpeg', '-f', 'image2pipe', '-pix_fmt', 'bgr24', '-vcodec', 'h264', 'fps=30', '-'] ffmpeg = sp.Popen(ffmpegCmd, stdin = stream.stdout, stdout = sp.PIPE, universal_newlines = True)
This is what I think should be used, but I always get the error "Output file #0 does not contain any stream".
Edit:
Final Answer
Turns out the universal_newlines option was ruining the line endings and gradually corrupting the output. Also, the ffmpeg command was wrong, see LordNeckbeard's answer.
Here's the correct ffmpeg command to achieve what was used:
ffmpegCmd = ['ffmpeg', '-i', '-', '-f', 'rawvideo', '-vcodec', 'bmp', '-vf', 'fps=5', '-'] ffmpeg = sp.Popen(ffmpegCmd, stdin = stream.stdout, stdout = sp.PIPE)
And then to convert the result into an OpenCV image, you do the following:
fileSizeBytes = ffmpeg.stdout.read(6) fileSize = 0 for i in xrange(4): fileSize += fileSizeBytes[i + 2] * 256 ** i bmpData = fileSizeBytes + ffmpeg.stdout.read(fileSize - 6) image = cv2.imdecode(np.fromstring(bmpData, dtype = np.uint8), 1)
This will get every single frame of a stream as an OpenCV image.