3

First off, in the long run I want to implement a speedometer for a MP4 file using Android. I did some research and apparently the best way to do that is through FFmpeg. I decided on using this library: https://github.com/WritingMinds/ffmpeg-android-java . It implements FFmpeg for Android. It was quite simple to include into my project. (Instructions: http://writingminds.github.io/ffmpeg-android-java/)

I use the following method. As cmd I am using a String in Quotations marks

    ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
    ...
    };

Now I was trying to overlay some dynamic text over an MP4 file. I thought I would start trying it with a timestamp. For a timestamp something like this is needed: ... timecode='02:36:17\;00' ...

My Problem is I am getting this error " Unable to find a suitable output format for '''. It doesn't matter if i try to use "\" (escaping) or if i try to use regular quotes. Whenever I use some kind of quotation mark I am getting an error. That makes it impossible to use an dynamic timestamp. I think.

Does anyone have an idea as to how I can fix this? Keep in mind the timecode is within a String in an Android(Java) class.

Thanks in advance for your help

EDIT:

Can someone provide me with a working command? The cmd 1-3 work, but 4 and 5 don't work (even as String[]).

    String cmd1 = "-i /storage/emulated/0/dir1/dir2/TestVideo.MP4 -i /storage/emulated/0/dir1/dir2/logo.png -preset ultrafast -filter_complex overlay=10:main_h-overlay_h-10 -acodec: copy /storage/emulated/0/dir1/dir2/LogoOverlay1.mp4";// working PNG overlay

    String cmd2 = "-i /storage/emulated/0/dir1/dir2/TestVideo.MP4 -i /storage/emulated/0/dir1/dir2/logo.png -preset ultrafast -filter_complex overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 -acodec: copy /storage/emulated/0/dir1/dir2/LogoOverlay2.mp4";// working PNG overlay

    String cmd3 = "-i /storage/emulated/0/dir1/dir2/TestVideo.MP4 -i /storage/emulated/0/dir1/dir2/logo.png -preset ultrafast -filter_complex [0:v][1:v]overlay=main_w-overlay_w-10:main_h-overlay_h-10[out] -map [out] -map 0:a -acodec: copy /storage/emulated/0/dir1/dir2/LogoOverlay3.mp4";// working PNG overlay

    String cmd4 = "-i /storage/emulated/0/dir1/dir2/TestVideo2.MP4 -vf drawtext=fontfile=/usr/share/fonts/TTF/Vera.ttf: text=\'Stack Overflow\': fontcolor=white: fontsize=24: box=1: boxcolor=black: x=(w-text_w)/2: y=(h-text_h-line_h)/2\"  -acodec: copy /storage/emulated/0/dir1/dir2/TextOverlay.mp4";

    String cmd5 = "-i /storage/emulated/0/dir1/dir2/TestVideo2.MP4 -vf \'transpose=1\' /storage/emulated/0/dir1/dir2/rotated.mp4"; //rotate video

    String[] cmd4arr = new String[]{"-i", "/storage/emulated/0/dir1/dir2/TestVideo.MP4", "-vf", "drawtext=fontfile=/usr/share/fonts/TTF/Vera.ttf: text='Stack Overflow': fontcolor=white: fontsize=24: box=1: boxcolor=black: x=(w-text_w)/2: y=(h-text_h-line_h)/2", "-acodec:", "copy /storage/emulated/0/dir1/dir2/TextOverlay.mp4"};

    String[] cmd5arr = new String[]{"-i", "/storage/emulated/0/dir1/dir2/TestVideo2.MP4","-preset","ultrafast", "-vf", "\'transpose=1\'", "/storage/emulated/0/dir1/dir2/rotated.mp4"};


    String[] cmd4ArrAlt = new String[]{"-i", "/storage/extSdCard/DCIM/Camera/Test.MP4", "-vf", "drawtext=fontfile=/usr/share/fonts/TTF/Vera.ttf:", "text=\'Stack Overflow\':", "fontcolor=white:", "fontsize=24:", "box=1:", "boxcolor=black:", "x=(w-text_w)/2:", "y=(h-text_h-line_h)/2", "-acodec:", "copy", "/storage/emulated/0/dir/TextOverlay.mp4"};

cmd4arr produces this Log:

    .../MainActivity﹕ onProgress ffmpeg version n2.4.2 Copyright (c) 2000-2014 the FFmpeg developers
    .../MainActivity﹕ onProgress   built on Oct  7 2014 15:08:46 with gcc 4.8 (GCC)
    .../MainActivity﹕ onProgress   configuration: --target-os=linux --cross-prefix=/home/sb/Source-Code/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --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/armeabi-v7a-neon --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 -mfpu=neon' --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=
    .../MainActivity﹕ onProgress   libavutil      54.  7.100 / 54.  7.100
    .../MainActivity﹕ onProgress   libavcodec     56.  1.100 / 56.  1.100
    .../MainActivity﹕ onProgress   libavformat    56.  4.101 / 56.  4.101
    .../MainActivity﹕ onProgress   libavdevice    56.  0.100 / 56.  0.100
    .../MainActivity﹕ onProgress   libavfilter     5.  1.100 /  5.  1.100
    .../MainActivity﹕ onProgress   libswscale      3.  0.100 /  3.  0.100
    .../MainActivity﹕ onProgress   libswresample   1.  1.100 /  1.  1.100
    .../MainActivity﹕ onProgress   libpostproc    53.  0.100 / 53.  0.100
    .../MainActivity﹕ onProgress Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/dir1/dir2/TestVideo2.MP4':
    .../MainActivity﹕ onProgress   Metadata:
    .../MainActivity﹕ onProgress     major_brand     : isom
    .../MainActivity﹕ onProgress     minor_version   : 512
    .../MainActivity﹕ onProgress     compatible_brands: isomiso2mp41
    .../MainActivity﹕ onProgress     creation_time   : 1970-01-01 00:00:00
    .../MainActivity﹕ onProgress     encoder         : Lavf53.24.2
    .../MainActivity﹕ onProgress   Duration: 00:00:06.40, start: 0.000000, bitrate: 1321 kb/s
    .../MainActivity﹕ onProgress     Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 640x368 [SAR 1:1 DAR 40:23], 932 kb/s, 25 fps, 25 tbr, 12800 tbn, 25 tbc (default)
    .../MainActivity﹕ onProgress     Metadata:
    .../MainActivity﹕ onProgress       creation_time   : 1970-01-01 00:00:00
    .../MainActivity﹕ onProgress       handler_name    : VideoHandler
    .../MainActivity﹕ onProgress     Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 383 kb/s (default)
    .../MainActivity﹕ onProgress     Metadata:
    .../MainActivity﹕ onProgress       creation_time   : 1970-01-01 00:00:00
    .../MainActivity﹕ onProgress       handler_name    : SoundHandler

cmd4ArrAlt produces this Log:

    .
    .
    .
    /MainA: onProgress:       handler_name    : SoundHandle
    /MainA: onProgress: [NULL @ 0xb5ec4a00] Unable to find a suitable output format for 'text='Stack Overflow':'
    /MainA: onProgress: text='Stack Overflow':: Invalid argument

cmd4arr and cmd5arr create an new MP4 file. But it has a size of 0KB. The commands seem not to process the frames at all. It always stops with this last line of the Log posted above.

Edit:

Answered question: "What how can I use a String [ ] with this Library? Information on that might fix the other issues."

Answer: I imported the project as arr before. When it is imported as a regular library you can't use a normal String anymore but it is implemented as an String[].

MalusDarkb
  • 153
  • 1
  • 10
  • please post what ffmpeg command are you trying to achieve – Gueorgui Obregon Jan 25 '16 at 21:36
  • One example of an not working command is: `ffmpeg -i input.mp4 -vf drawtext="fontfile=/usr/share/fonts/TTF/Vera.ttf: text='Stack Overflow': fontcolor=white: fontsize=24: box=1: boxcolor=black: x=(w-text_w)/2: y=(h-text_h-line_h)/2" -codec:a copy output.flv ` It gives me an error at : `text='Stack Overflow'`. I can provide you with more examples but I think this is the most basic one ( It is from [http://stackoverflow.com/questions/17623676/text-on-video-ffmpeg]. – MalusDarkb Jan 25 '16 at 21:41
  • I tried using a Stringarray but the FFmpeg command seems not to work. Can you tell me what is wrong with it? `String[] complexCommand = {"ffmpeg", "-y" ,"-i", "/storage/emulated/0/dir1/dir2/input.MP4", "-strict","experimental", "-vf", "drawtext=fontfile=/usr/share/fonts/TTF/Vera.ttf: text='Stack Overflow': fontcolor=white: fontsize=24: box=1: boxcolor=black: x=(w-text_w)/2: y=(h-text_h-line_h)/2", "-acodec:","copy", "/storage/emulated/0/dir1/dir2/overput.mp4"};` – MalusDarkb Jan 26 '16 at 21:14
  • HI @MalusDarkb use text=\'Stack Overflow\' – Gueorgui Obregon Jan 26 '16 at 21:19
  • Is this command overwise good? – MalusDarkb Jan 26 '16 at 21:42
  • And do u have a recommendation on which library i should use or how I should implement FFmpeg. Maybe there is something better out there – MalusDarkb Jan 26 '16 at 21:46
  • 1
    This library work for me, by i test at least 10 commands until i achieve my goal...what i'm try to say is that to make the command work i've to scape single quote...so element of array : "drawtext=fontfile=/usr/share/fonts/TTF/Vera.ttf: text='Stack Overflow': fontcolor=white: fontsize=24: box=1: boxcolor=black: x=(w-text_w)/2: y=(h-text_h-line_h)/2" ...should be "drawtext=fontfile=/usr/share/fonts/TTF/Vera.ttf: text=\'Stack Overflow\': fontcolor=white: fontsize=24: box=1: boxcolor=black: x=(w-text_w)/2: y=(h-text_h-line_h)/2" – Gueorgui Obregon Jan 26 '16 at 21:58
  • I tried that with a normal string, that did not work out. Can you provide me with information as how to insert String [ ] commands in this library? That would help a lot :) thanks – MalusDarkb Jan 27 '16 at 13:18
  • Hi i edited my answer for the cmd5... – Gueorgui Obregon Feb 14 '16 at 05:13

1 Answers1

1

I have the same issue, and the problem was that complex ffmpeg command at most android-ffmpeg-java wrapper should be pass as array and not as simple string.

EDIT:

Try this:

String[] cmd4arr = new String[]{
            "-i", 
            "/storage/emulated/0/dir1/dir2/TestVideo.MP4", 
            "-vf", 
            "drawtext=fontfile=/usr/share/fonts/TTF/Vera.ttf: text=\'Stack Overflow\': fontcolor=white: fontsize=24: box=1: boxcolor=black: x=(w-text_w)/2: y=(h-text_h-line_h)/2", 
            "-acodec:", 
            "copy",
            "/storage/emulated/0/dir1/dir2/TextOverlay.mp4"};

Change the transpose in cmd5 single quote should be in before = like this "transpose=\'1\'"

 String[] cmd5arr = new String[]{"-i", 
            "/storage/emulated/0/dir1/dir2/TestVideo2.MP4",
            "-preset",
            "ultrafast", 
            "-vf", 
            "transpose=\'1\'",
            "/storage/emulated/0/dir1/dir2/rotated.mp4"};
Gueorgui Obregon
  • 5,077
  • 3
  • 33
  • 57
  • I actually tried that, but I did not find a way to but a string[] into this method: `execute(String cmd, FFmpegExecuteResponseHandler ffmpegExecuteResponseHandler) throws FFmpegCommandAlreadyRunningException`. Can u give me an example as to how I would do that with this library. The methods you could alternatively use is `execute(Map environvenmentVars, String cmd, FFmpegExecuteResponseHandler ffmpegExecuteResponseHandler) throws FFmpegCommandAlreadyRunningException`. But I still don't know how I would successfully use an Array in this Method – MalusDarkb Jan 25 '16 at 21:50
  • I changed WritingMinds/ffmpeg-android-java to accept String[] cmd.. sorry right now i don't have the changes, later i will post the code. – Gueorgui Obregon Jan 25 '16 at 21:53
  • 1
    Thanks you. That would be of great help for me if you could provide me the code. And it is great to see that I was not the only one with this problem. – MalusDarkb Jan 25 '16 at 21:55
  • Look at this post, http://stackoverflow.com/a/23708382/4848308. This is the way that should be call ffmpeg command – Gueorgui Obregon Jan 25 '16 at 22:00
  • Yes, I habe tried that. But I could not find a methode in this library which would accept that as an input. Is there a workaround for that? Or do I need to use a different library? Which library should I use than? – MalusDarkb Jan 26 '16 at 07:34
  • Thank you. I edited the question earlier today, so you have some more informations:) – MalusDarkb Jan 27 '16 at 20:43
  • cmd4 definetly should be excecute as an array and not as simple string – Gueorgui Obregon Jan 27 '16 at 21:34
  • sorry I don´t have much time :(, I'm fighting with another monster...reversing android wav ;) – Gueorgui Obregon Jan 27 '16 at 21:37
  • Yes I know, but how do i execute it as an array with this library? – MalusDarkb Jan 27 '16 at 22:47
  • OK, I used the arr, now I have the library code. With the library I am even using the String[] (so that is no issue anymore) but the command still does't succeed. It returns no Error but no progress as well, I assume it doesn't do anything. I updated the Log, it is basically the same as before just stops earlier. Always at the same point ( for cmd4 and cmd 5, updated them as well). – MalusDarkb Jan 28 '16 at 08:11
  • try with String[] cmd4arr = new String[]{"-i", "/storage/emulated/0/dir1/dir2/TestVideo.MP4", "-vf", "drawtext=fontfile=/usr/share/fonts/TTF/Vera.ttf: text=\'Stack Overflow\': fontcolor=white: fontsize=24: box=1: boxcolor=black: x=(w-text_w)/2: y=(h-text_h-line_h)/2", "-acodec:", "copy /storage/emulated/0/dir1/dir2/TextOverlay.mp4"}; – Gueorgui Obregon Jan 28 '16 at 14:03
  • oh I wrote the command slightly different, than how I used it. It was: `String[] cmd4arr = new String[]{"-i", "/storage/emulated/0/dir1/dir2/TestVideo.MP4", "-vf", "drawtext=fontfile=/usr/share/fonts/TTF/Vera.ttf: text='\Stack Overflow\': fontcolor=white: fontsize=24: box=1: boxcolor=black: x=(w-text_w)/2: y=(h-text_h-line_h)/2", "-acodec:", "copy /storage/emulated/0/dir1/dir2/TextOverlay.mp4"};` So you seperated the last two "parts". Does it work on your implementation? And did my version work? Or did u get the same mistake as I did? – MalusDarkb Jan 28 '16 at 19:17
  • sorry i didnt test your command in my case all spaces must be separated by an independent item array, even the last two parts...as I change in my answer. the posted command didnt work for you? – Gueorgui Obregon Jan 28 '16 at 19:28
  • No it is nor working. the same problem. What if I would separate all whitespaces following the drawtext as well? – MalusDarkb Jan 28 '16 at 20:24
  • So I tried that. I updated the question. take a look at cmd4ArrAlt. I also posted the Log that changed. – MalusDarkb Jan 28 '16 at 20:31
  • Hey, could you create a project where this is working and give me access to that? Might be a good solution for my problem :) – MalusDarkb Jan 31 '16 at 18:11
  • @GueorguiObregon Thank you for your library! – Inoy Jul 18 '16 at 22:53