0
When I execute ffmpeg command through java code then It is not executing properly 
Example-:

I want to draw text in video through java code

My code in java is

String cmd="ffmpeg -i 12213blob.mp4 -vf \"drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf:text='Text to write':fontsize=20:fontcolor=black:x=250:y=430\" output.mp4";
            System.out.println(cmd);
            Process p4 = Runtime.getRuntime().exec(cmd);
            p4.waitFor();

        BufferedReader stdInput = new BufferedReader(new
             InputStreamReader(p4.getInputStream()));

        BufferedReader stdError = new BufferedReader(new
             InputStreamReader(p4.getErrorStream()));

        // read the output from the command
        System.out.println("Here is the standard output of the command:\n");
        while ((s = stdInput.readLine()) != null) {
            System.out.println(s);
        }

        // read any errors from the attempted command
        System.out.println("Here is the standard error of the command (if any):\n");
        while ((s = stdError.readLine()) != null) {
            System.out.println(s);
        }


    }
    catch (IOException e) {
        System.out.println("exception happened - here's what I know: ");
        e.printStackTrace();

    }
}

When I execute this code it me error like this Here is the standard output of the command:

Here is the standard error of the command (if any):

ffmpeg version 2.4.git Copyright (c) 2000-2014 the FFmpeg developers
  built on Sep 16 2014 18:19:21 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
  configuration: --prefix=/home/deepak/ffmpeg_build --extra-cflags=-I/home/deepak/ffmpeg_build/include --extra-ldflags=-L/home/deepak/ffmpeg_build/lib --bindir=/home/deepak/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-x11grab
  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
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '12213blob.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.48.100
  Duration: 00:00:09.94, start: 0.046440, bitrate: 593 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 660x500 [SAR 1:1 DAR 33:25], 493 kb/s, 42.83 fps, 42.83 tbr, 16448 tbn, 85.67 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 96 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
**[NULL @ 0x302bd40] Unable to find a suitable output format for 'to'
to: Invalid argument**

But when I execute this command directly on terminal then it is executing correctly

4
  • Issues specific to programming and software development are off topic, see What topics can I ask about here?. Try StackOverflow, but please first read How do I ask a good question?.
    – DavidPostill
    Commented Sep 17, 2014 at 6:17
  • 1
    Having said that, your section 'Text to Write' seems the culprit.
    – Rajib
    Commented Sep 17, 2014 at 19:23
  • @fixer1234 why would you close the question instead of moving it to SO?
    – user264232
    Commented Apr 9, 2015 at 14:44
  • 1
    @Grant: Only moderators can migrate a question. The mechanism to do that is closure votes where the reason selected is that it belongs on another site. Apparently, not enough people agreed with me that it should be migrated so any votes just expired, or enough people voted not to migrate it so it wasn't (which is why it's still here, with no closure votes).
    – fixer1234
    Commented Apr 10, 2015 at 0:15

1 Answer 1

0
String cmd="ffmpeg -i 12213blob.mp4 -vf drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf:text=Text-to-write:fontsize=20:fontcolor=black:x=250:y=430 output.mp4";

@user2511474: Try this above command, this will work. I recently came across similar issue are resolved it by removing 'escaping quotes' and spaces.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .