0

I am stuck on my code.
This is my command of ffmpeg through which I am pasting texts on particular video.

Code in Java:

try {
    char double_quote = '\"';
    String devajuserif_font = "DejaVuSerif.ttf";
    Date date1 = new Date(Long.parseLong(date));
    SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yy");
    date = df2.format(date1);
    String videoEditingCommand = "ffmpeg -i " + file.getAbsolutePath() + " -vf " + double_quote
                + "[in]drawtext=fontsize=10:fontcolor=Red:fontfile=" + devajuserif_font + ":text=Latitude-'" + latitude
                + "':x=0:y=0, drawtext=fontsize=10:fontcolor=Red:fontfile=" + devajuserif_font + ":text=Longitude-'"
                + longitude + "':x=0:y=10, drawtext=fontsize=10:fontcolor=Red:fontfile=" + devajuserif_font
                + ":text=Accuracy-'" + accuracy + " m':x=0:y=20, drawtext=fontsize=10:fontcolor=Red:fontfile="
                + devajuserif_font + ":text=Date-'" + date + "':x=0:y=30[out]" + double_quote + " -y "
                + file.getAbsolutePath();
        ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c", videoEditingCommand);  //for windows
        builder.redirectErrorStream(true);
        Process p = builder.start();
        BufferedReader r = new BufferedReader(new 
        InputStreamReader(p.getInputStream()));
        String line;
        while (true) {
            line = r.readLine();
            if (line == null) {
                break;
            }
            log.info(line);
        }
    } 

My video length is 1 minute. But after conversion, When I download video after pasting text on video, It's length reduces to 1 second. It is getting error. says:

Invalid NAL unit size (755 > 249). D:\test\upload21-3Aug2017061732GMT_1501741052377.mp4: Invalid data found when processing input

Can someone help me?

ItamarG3
  • 3,846
  • 6
  • 28
  • 42
  • 2
    A ffmpeg expert can have no idea about java, a Suggestion: extract the ffmpeg command from your java code and try to simplify your question. This can be a good example https://stackoverflow.com/questions/45462731/using-ffmpeg-to-change-framerate – David Pérez Cabrera Aug 03 '17 at 06:33
  • ffmpeg -i D:\test\upload21-3Aug2017063541GMT_1501742141262.mp4 -vf "[in]drawtext=fontsize=10:fontcolor=Red:fontfile=DejaVuSerif.ttf:text=Latitude-'28.49994010':x=0:y=0, drawtext=fontsize=10:fontcolor=Red:fontfile=DejaVuSerif.ttf:text=Longitude-'77.08348350':x=0:y=10, drawtext=fontsize=10:fontcolor=Red:fontfile=DejaVuSerif.ttf:text=Accuracy-'25.89 m':x=0:y=20, drawtext=fontsize=10:fontcolor=Red:fontfile=DejaVuSerif.ttf:text=Date-'03/08/17':x=0:y=30[out]" -y D:\test\upload21-3Aug2017063541GMT_1501742141262.mp4 – Prashant Sharma Aug 03 '17 at 06:36
  • 2
    From your code above, source file = destination file. – OldC Aug 03 '17 at 06:36
  • This is the command which I am using to paste text on video – Prashant Sharma Aug 03 '17 at 06:36
  • I am just editing source file and sending it after editing video. This works on image so well. – Prashant Sharma Aug 03 '17 at 06:38
  • 1
    For image it is fine because ffmpeg will decode single frame to memory then output file is free to be overwritten. For video, you cannot overwrite the source file until ffmpeg decode the last frame. – OldC Aug 03 '17 at 06:42
  • Thanks @OldC. I will look into this matter. I think It will work. – Prashant Sharma Aug 03 '17 at 06:58
  • 1
    No. You'll have to write to a new destination. – Gyan Aug 03 '17 at 07:00
  • It is working @OldC. Your idea works like a charm. Just writing new destination works. :) – Prashant Sharma Aug 03 '17 at 07:12

0 Answers0