Newest 'ffmpeg' Questions - Stack Overflow

http://stackoverflow.com/questions/tagged/ffmpeg

Les articles publiés sur le site

  • FFmpeg video from image plus audio length issue

    1er juin, par blackbrayn

    I'm having issues regarding the output video length when using the following code which seems to work for everybody else.

    On a input mp3 of 04:56 I get a 05:09, the last part is only the image, no sound, for a longer mp3 input file I get more silent video at the end.

    I'm using the "-shortest" option just before the output file as an argument , as suggested in other threads around stackoverflow/superuser.

       ffmpeg -loop 1 -i image.jpg -i audio.mp3 -c:v libx264 -tune stillimage -c:a aac -strict experimental -b:a 192k -shortest out.mp4
    

    I already changed the input file type - wav , and the image - png, jpg, same silent "overhead" at the end of the video.

  • How to Ensure UTF-8 Kurdish (Sorani) Subtitles Render Correctly in FFmpeg ? [closed]

    30 mai, par Kurdi Bashur

    I’m trying to burn or embed Kurdish (Sorani, ckb) subtitles into an MP4 video using FFmpeg, but the text (e.g., characters like ێ, ڵ, ڵا) sometimes appears garbled or incorrect. I want to ensure proper UTF-8 encoding for the subtitles. Here’s what I’ve tried:

    ffmpeg -i input.mp4 -vf "subtitles=subtitles.srt:force_style='Fontname=Noto Sans Arabic,Fontsize=24'" -c:v libx264 -c:a aac output.mp4
    
    How can I ensure FFmpeg correctly handles UTF-8 Kurdish subtitles?
    
    Should I use -sub_charenc for UTF-8 files, or is it only for non-UTF-8 (e.g., Windows-1256)?
    
    Are there specific force_style parameters or filters (e.g., libass) needed for Kurdish RTL text?
    
    Could the issue be font-related, despite using Noto Sans Arabic?
    
  • Using FFMPEG : How to do a Scene Change Detection ? with timecode ?

    30 mai, par Mozart

    Based on this article it seems that it is possible to use FFMPEG to detect scene change in videos: http://www.luckydinosaur.com/u/ffmpeg-scene-change-detector

    Now I have a video that displays a book text and when the text (word or sentence) is spoken it gets highlighted. Something like this audio book: https://youtu.be/lA7L6ZNVKjc

    I need to know the timestamp when the text gets highlighted (hence scene change), this will allow me to add timestamp tags on my youtube video, so it becomes easier for listeners to navigate through the audiobook.

    What is the magic command line that would do this?

    Thank you very much!

  • How to import FFmpeg into Android project

    30 mai, par Vyacheslav Parinov

    I'm trying to convert series of images into video. For that I'm adding FFmpeg into my Android project. However it is not adding properly, so I can't import class FFmpeg into the code. in the statement "int rc = FFmpeg.execute(command);" FFmpeg is highlighted in red.

    I think something wrong with libraries. Could you please give suggestion how import libraries correctly?

    My Manifest file below

    <?xml version="1.0" encoding="utf-8"?>
    

    
    
    
    
        
            
                
    
                
            
        
    
    

    My settings.gradle file

    pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
    

    }

    dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
    

    } rootProject.name = "TimelapseLite" include ':app'

    My build.gradle file

    plugins {
        id 'com.android.application'
    }
    
    android {
        namespace 'ae.vpdev.timelapselite'
        compileSdk 33
    
    defaultConfig {
        applicationId "ae.vpdev.timelapselite"
        minSdk 26
        targetSdk 33
        versionCode 1
        versionName "1.0"
    
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    

    }

    dependencies {

    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.arthenica:mobile-ffmpeg-full:4.5.LTS'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    

    }

    My code in MainActivity

    private void convertImagesToVideo() {
        StringBuilder imageListFileContent = new StringBuilder();
        for (Uri imageUri : selectedImages) {
            imageListFileContent.append("file '").append(imageUri.getPath()).append("'\n");
        }
    
        try {
            File imageListFile = new File(getCacheDir(), "image_list.txt");
            FileWriter writer = new FileWriter(imageListFile);
            writer.append(imageListFileContent.toString());
            writer.flush();
            writer.close();
    
            File outputFile = new File(getExternalFilesDir(null), "output_video.mp4");
            String outputFilePath = outputFile.getAbsolutePath();
    
            String command = "-f concat -safe 0 -i " + imageListFile.getAbsolutePath() +
                    " -vf \"scale=-2:720\" -r 30 -c:v libx264 -pix_fmt yuv420p " + outputFilePath;
    
            int rc = FFmpeg.execute(command);
    
            if (rc == RETURN_CODE_SUCCESS) {
                Log.d("FFmpeg", "Video conversion completed successfully");
                // Now you can use the outputFilePath to play or share the video
            } else {
                Log.d("FFmpeg", "Video conversion failed");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
  • How to implement spring animation (mass, tension, friction) in FFmpeg zoompan filter instead of linear interpolation ?

    29 mai, par Mykyta Manuilenko

    I'm trying to create a zoom-in and zoom-out animation using FFmpeg's zoompan filter, but I want to replace the linear interpolation with a spring animation that uses physics parameters (mass, tension, friction).

    My input parameters:

    "zoompan": {
      "focusRect": {
        "x": 1086.36,
        "y": 641.87,
        "width": 613,
        "height": 345
      },            
      "easing": {
        "mass": 1,
        "tension": 120,
        "friction": 20
      }
    }
    

    Current working linear animation:

    ffmpeg -framerate 25 -loop 1 -i input.png \
      -filter_complex "\
        [0:v]scale=6010:3380,setsar=1,split=3[zoomin_input][hold_input][zoomout_input]; \
        [zoomin_input]zoompan= \
          z='iw/(iw/zoom + (ow - iw)/duration)': \
          x='x + (3400 - 0)/duration': \
          y='y + (2009 - 0)/duration': \
          d=25:fps=25:s=1920x1080, \
          trim=duration=1,setpts=PTS-STARTPTS[zoomin]; \
        [hold_input]crop=1920:1080:3400:2009,trim=duration=4,setpts=PTS-STARTPTS[hold]; \
        [zoomout_input]zoompan=\
          zoom='if(eq(on,0),iw/ow,iw/(iw/zoom + (iw-ow)/duration))':\
          x='if(eq(on,0),3400,x + (0-3400)/duration)':\
          y='if(eq(on,0),2009,y + (0-2009)/duration)':\
          d=25:fps=25:s=1920x1080, \
          trim=duration=1,setpts=PTS-STARTPTS[zoomout];
        [zoomin][hold][zoomout]concat=n=3:v=1:a=0[outv]" \
      -map "[outv]" \
      -crf 23 \
      -preset medium \
      -c:v libx264 \
      -pix_fmt yuv420p \
      output.mp4
    

    Notes:

    • It creates a perfectly straight zoom path to the specific point on the screen (similar to pinch-zooming on a smartphone - straight zooming to the center of the focus rectangle)

    • To improve the quality of the output, I upscale it beforehand

    What I want to achieve:

    Instead of linear interpolation, I want to implement a spring function with these physics parameters:

    • mass: 1
    • tension: 120
    • friction: 20

    Note that these params can be changed.

    Also, I want to preserve a perfectly straight zoom path to the specific point on the screen (similar to pinch-zooming on a smartphone).

    Question:

    How can I properly implement a spring animation function in FFmpeg's zoompan filter?