Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
Handling spaces in filenames of ffmpeg command when i don't know the exact path
3 août 2015, par Bhuvnesh VarmaI am using below ffmpeg command to cut videos.It works fine for video file names which doesn't have spaces but didn't worked for filenames having spaces..
execFFmpegBinary("-i " + path + " -ss " + startMs / 1000 + " -to " + endMs / 1000 + " -strict -2 -async 1 " + dest.getAbsolutePath());
where
path
is the path of original video.startMs
is the initial time of video form where you want to cut(start time of cropped video)endMs
is the time of video upto which you want to cut(end time of cropped video)dest
is the path where you want to save the cut/cropped videoThe problem is with source path(path).I have seen this answer.But here i don't know the complete path since I am fetching paths of all the videos from storage. I need to handle spaces in filenames. For resolving that i tried using string formatter as shown in below code .But with that it didn't worked in both cases.Where am i going wrong and how can i resolve the issue?
String command = String.format("-i \"%s\" -ss %d -to %d -strict -2 -async 1 \"%s\" ",path,startMs / 1000 , endMs / 1000, dest.getAbsolutePath()); execFFmpegBinary(command);
-
FFMpeg convert avi video to the format in HTML5 standard
2 août 2015, par karoluchI try to convert an avi file to mp4 format which is supported by the most known browsers eg. : (IE, Firefox, Chrome). I use for that ffmpeg tool. I noticed that video after conversion works on my Ubuntu 14.04 but on the Windows 8.1 it does not work. Which options for ffmpeg should I use to get working mp4 format on the Windows?
I use following command to conversion:
ffmpeg -i example.avi -vcodec libx264 -cpu-used 16 -threads 8 -deadline realtime -acodec libvo_aacenc -y example.mp4
For the example I convert files from : http://www.mysticfractal.com/video/avi1.html
-
ffmpeg conversion - keep audio bitrate
2 août 2015, par clausvdbI'm using ffmpeg to extract the audio from different video formats (flv, mp4) and convert it to mp3.
%~dp0ffmpeg.exe -i %1 -ar 44100 -ac 2 -ab 128k "%~dpn1.mp3"
This works just fine. However, in my input files, the audio bitrate varies, and I want to adjust the output bitrate accordingly. Even by extensive Google searching, I didn't find any hint how to just keep the original bitrate.
What I would need would be something like:
-ab copy
Which, of course, does not work.
Is there anything that will work?
P.S: As you might have figured from the formatting above, I'm using a windows batch file. There would be the hack to use %~dp0ffmpeg.exe -i, get the audio bitrate by grep and insert it in the command line. I just think there has to be an easier and more elegant way.
-
Handling commands with spaces in filenames
2 août 2015, par Bhuvnesh VarmaI am using below ffmpeg command to cut videos.It works fine for video file names which doesn't have spaces but didn't worked for filenames having spaces..
execFFmpegBinary("-i " + path + " -ss " + startMs / 1000 + " -to " + endMs / 1000 + " -strict -2 -async 1 " + dest.getAbsolutePath());
For resolving that i tried using string formatter as shown in below code .But with that it didn't worked in both cases.Where am i going wrong and how can i resolve the issue?
String command = String.format("-i \"%s\" -ss %d -to %d -strict -2 -async 1 \"%s\" ",path,startMs / 1000 , endMs / 1000, dest.getAbsolutePath()); execFFmpegBinary(command); private void execFFmpegBinary(final String command) { try { ffmpeg.execute(command, new ExecuteBinaryResponseHandler() { @Override public void onFailure(String s) { Log.e("Previewragment", "FAILED with output : " + s); } @Override public void onSuccess(String s) { Log.e("Previewragment", "SUCCESS with output : " + s); } @Override public void onProgress(String s) { Log.e("Previewragment", "Started command : ffmpeg " + command); Log.e("Previewragment", "progress : " + s); } @Override public void onStart() { Log.e("Previewragment", "Started command : ffmpeg " + command); } @Override public void onFinish() { Log.e("Previewragment", "Finished command : ffmpeg " + command); path = dest.getAbsolutePath(); } }); } catch (FFmpegCommandAlreadyRunningException e) { // do nothing for now } }
-
Can i programmatically rename a file on removable sd card
2 août 2015, par Bhuvnesh VarmaI tried below codes for renaming file.It works fine for internal storage but is not working for removable sd card file.I need to rename file on removable sd card to remove spaces and special characters from filename as I am using fmpeg command to cut videos.
File from = new File(originalpath); String rename=originalpath.replace(" ", "").replace("-","").replace(",","").trim(); File to = new File(rename); Boolean result= from.renameTo(to);
OR
File from = new File(originalpath); File to=new File((Environment.getExternalStorageDirectory()),"gvideo.mp4"); Boolean result2= from.renameTo(to);
Both of them gives result false
Adding details about command-
execFFmpegBinary("-i " + from.getAbsolutePath() + " -ss " + startMs / 1000 + " -to " + endMs / 1000 + " -strict -2 -async 1 " + dest.getAbsolutePath()); private void execFFmpegBinary(final String command) { try { ffmpeg.execute(command, new ExecuteBinaryResponseHandler() { @Override public void onFailure(String s) { Log.e("Previewragment", "FAILED with output : " + s); } @Override public void onSuccess(String s) { Log.e("Previewragment", "SUCCESS with output : " + s); } @Override public void onProgress(String s) { Log.e("Previewragment", "Started command : ffmpeg " + command); Log.e("Previewragment", "progress : " + s); } @Override public void onStart() { Log.e("Previewragment", "Started command : ffmpeg " + command); } @Override public void onFinish() { Log.e("Previewragment", "Finished command : ffmpeg " + command); } }); } catch (FFmpegCommandAlreadyRunningException e) { // do nothing for now } }
Failure message-
FAILED with output : WARNING: linker: /data/data/xyz/files/ffmpeg has text relocations. This is wasting memory and prevents security hardening. Please fix. ffmpeg version n2.4.2 Copyright (c) 2000-2014 the FFmpeg developers built on Oct 7 2014 15:11:41 with gcc 4.8 (GCC) configuration: --target-os=linux --cross-prefix=/home/sb/Source-Code/ffmpeg-android/toolchain-android/bin/i686-linux-android- --arch=x86 --cpu=i686 --enable-runtime-cpudetect --sysroot=/home/sb/Source-Code/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/sb/Source-Code/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/sb/Source-Code/ffmpeg-android/build/x86 --extra-cflags='-I/home/sb/Source-Code/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all -march=i686' --extra-ldflags='-L/home/sb/Source-Code/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags= libavutil 54. 7.100 / 54. 7.100 libavcodec 56. 1.100 / 56. 1.100 libavformat 56. 4.101 / 56. 4.101 libavdevice 56. 0.100 / 56. 0.100 libavfilter 5. 1.100 / 5. 1.100 libswscale 3. 0.100 / 3. 0.100 libswresample 1. 1.100 / 1. 1.100 libpostproc 53. 0.100 / 53. 0.100 "/storage/emulated/0/Movies/m_ASUS_Display_Demo.mp4": No such file or directory
Added complete method-
private void executeTrimCommand(int startMs, int endMs) { File moviesDir = Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_MOVIES ); String filePrefix = "guggu"; String fileExtn = ".mp4"; String fileName = filePrefix + fileExtn; File from = new File(path); try { dest = new File(moviesDir, filePrefix + "_1" + fileExtn); if (dest.exists()) { dest.delete(); } String command = String.format("-i \"%s\" -ss %d -to %d -strict -2 -async 1 \"%s\" ",path,startMs / 1000 , endMs / 1000, dest.getAbsolutePath()); execFFmpegBinary(command); } catch (Exception e) { Log.e("Previewragment", e.toString()); e.printStackTrace(); } }