-1

I am using this command to add time stamp in video:

ffmpeg -y -i input.mp4 -vf "drawtext=fontfile=roboto.ttf:fontsize=36:fontcolor=yellow:text='%{pts\:gmtime\:1575526882\:%d %b, %Y %I\\\:%M %p}'" -preset ultrafast -f mp4 output.mp4

this command generate date & time: 05 Dec, 2019 06:21 AM

but i want to add day suffix after day in date like this : 05th Dec, 2019 06:21 AM

//like 1st,2nd,3rd,4th,5th.... etc

what changes i have to do to achieve this?

Praful Korat
  • 374
  • 4
  • 22
Milan Tejani
  • 372
  • 5
  • 21
  • 1
    [My modern answer to the suggested original question](https://stackoverflow.com/a/50369812/5772882) requires that you *either* code for Android API level 26 or higher *or* you use [ThreeTenABP](https://github.com/JakeWharton/ThreeTenABP). In the latter case add that library to your Android project and make sure you import the date and time classes from `org.threeten.bp` with subpackages. [The long explanation is here](https://stackoverflow.com/questions/38922754/how-to-use-threetenabp-in-android-project). – Ole V.V. Dec 16 '19 at 16:41
  • i want ffmpeg command not java code bro – Milan Tejani Dec 17 '19 at 04:07
  • It will help me partially i don't get satisfied solution – Milan Tejani Dec 17 '19 at 05:32
  • i put bounty on this question for 7 days no one is answering and last day someone is ans and i get little help or you can say little help so i accepted as ans – Milan Tejani Dec 17 '19 at 05:40
  • 1
    and also your ans come after that also i updated my code with your ans – Milan Tejani Dec 17 '19 at 05:41

1 Answers1

0

you can format your date before you call ffmpeg command

private String addExtention(String format) {
    Calendar c = Calendar.getInstance();
    String df[] = format.split("th");
    String result;
    SimpleDateFormat df1 = new SimpleDateFormat(df[0], Locale.getDefault());
    result = df1.format(c.getTime());
    char lastChar = result.charAt(result.length() - 1);
    char secondlastChar = result.charAt(result.length() - 2);

    Log.e("::MG::", "addExtention: " + lastChar);
    Log.e("::MG::", "addExtention: " + secondlastChar);
    if (lastChar == '1' && (secondlastChar == '0' || secondlastChar == '2' || secondlastChar == '3'))
        result += "st";
    else if (lastChar == '2' && (secondlastChar == '0' || secondlastChar == '2'))
        result += "nd";
    else if (lastChar == '3' && (secondlastChar == '0' || secondlastChar == '2'))
        result += "rd";
    else
        result += "th";

    SimpleDateFormat df2 = new SimpleDateFormat(df[1], Locale.getDefault());
    result += df2.format(c.getTime());
    return result;
}

// Call Function

String strDate=addExtention("05 Dec, 2019 06:21 AM");

now you can pass strDate to ffmpeg command

Mahendra Gohil
  • 380
  • 1
  • 3
  • 21
  • This ans is not perfect but it helped me lot. – Milan Tejani Dec 16 '19 at 07:18
  • Please don’t teach the young ones to use the long outdated and notoriously troublesome `SimpleDateFormat` class. At least not as the first option. And not without any reservation. Today we have so much better in [`java.time`, the modern Java date and time API,](https://docs.oracle.com/javase/tutorial/datetime/) and its `DateTimeFormatter`. Yes, you can use it on Android. For older Android see [How to use ThreeTenABP in Android Project](https://stackoverflow.com/questions/38922754/how-to-use-threetenabp-in-android-project). – Ole V.V. Dec 16 '19 at 16:42