Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • FFmpeg adds its own metadata - encoder : Lavf58.20.100

    5 juillet, par NarūnasK

    I've tried to apply the following advice on the flac files:

    for x in *.flac; do
      ffmpeg -i "$x" -map 0:a -codec:a copy -map_metadata -1 clean_"$x";
    done
    

    But it seems, that ffmpeg though removes most metadata, it also adds its own fingerprint.

    Why does it add this tag? What is the best way to get rid of it?

    VLC reveals encoder metadata tag

  • How to remove ffmpeg metadata "software lavf55.7.100"

    5 juillet, par Joeedomi

    I'm using ffmpeg to extract audio from video files, then process the audio and cut it into smaller clip. But when i use ffmpeg to do the extraction, it adds a metadata "software lavf55.7.100" into my audio file, which screws my indexing of cutting. How can i get rid of this?
    In attached picture, in the middle "Metadata: ISFT : Lavf55.7.100"
    The string that i'm using is: ffmpeg -i steve.mp4 -map_metadata -1 steve14.wav

    enter image description here

  • ffmpeg try to open output file but fail [closed]

    5 juillet, par Lyhourt Te

    In my Windows 11, I use this code to use ffmpeg to convert video from one type to another type. The code is simple, it just loops and finds the target file extension and runs ffmpeg to convert the video This code used to work just fine, but now it's not working anymore. I think it maybe because of the Windows 11 security update.

    import os
    import subprocess
    
    def convert_ts_to_mp4(folder_path):
        # Ensure the folder exists
        if not os.path.isdir(folder_path):
            print(f"Folder '{folder_path}' does not exist.")
            return
        
        # Loop through files in the folder
        for filename in os.listdir(folder_path):
            if filename.endswith(".ts"):  # Check if the file is a .ts file
                print("read file:", filename)
                ts_file = os.path.join(folder_path, filename)
                mp4_file = os.path.join(folder_path, filename.replace(".ts", ".mp4"))
                
                print("ts file:", ts_file)
                print("mp4 file:", mp4_file)
                
                # Run ffmpeg command
                command = ["ffmpeg", "-i", ts_file, mp4_file]
                subprocess.run(command, check=True)
                print(f"Converted: {filename} -> {os.path.basename(mp4_file)}")
    
    if __name__ == "__main__":
        folder_path = os.path.dirname(os.path.abspath(__file__)) # Change this to your actual folder path
        convert_ts_to_mp4(folder_path)
    

    The error:

    Input #0, mpegts, from 'C:\Users\chhor\Downloads\Video\script\python-script-for-automation\1.ts':
      Duration: 00:44:25.20, start: 1.440000, bitrate: 3095 kb/s
      Program 1
        Metadata:
          service_name    : Service01
          service_provider: FFmpeg
      Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, progressive), 1920x872 [SAR 959:960 DAR 959:436], 25 fps, 25 tbr, 90k tbn, start 1.480000
      Stream #0:1[0x101](und): Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 130 kb/s, start 1.440000
    [out#0/mp4 @ 0000014f60d66d80] Error opening output C:\Users\chhor\Downloads\Video\script\python-script-for-automation\new.mp4: No such file or directory
    Error opening output file C:\Users\chhor\Downloads\Video\script\python-script-for-automation\new.mp4.
    Error opening output files: No such file or directory
    Traceback (most recent call last):
      File "C:\Users\chhor\Downloads\Video\script\python-script-for-automation\ts.py", line 27, in 
        convert_ts_to_mp4(folder_path)
      File "C:\Users\chhor\Downloads\Video\script\python-script-for-automation\ts.py", line 22, in convert_ts_to_mp4
        subprocess.run(command, check=True)
      File "C:\ProgramData\anaconda3\Lib\subprocess.py", line 571, in run
        raise CalledProcessError(retcode, process.args,
    subprocess.CalledProcessError: Command '['ffmpeg', '-i', 'C:\\Users\\chhor\\Downloads\\Video\\script\\python-script-for-automation\\1.ts', 'C:\\Users\\chhor\\Downloads\\Video\\script\\python-script-for-automation\\new.mp4']' returned non-zero exit status 4294967294.
    
  • Video generation and ffmpeg and locally stored images [closed]

    3 juillet, par Rahul Patil

    I am facing issue in ffmpeg while running the below code

    I'm working on a Flask application that generates a video by combining a sequence of images from a folder and a synthesized audio track using Bark (suno/bark-small). The idea is to use FFmpeg to stitch the images into a video, apply padding and scaling, and then merge it with the generated audio. I'm triggering the /generate-video endpoint with a simple curl POST request, passing a script that gets converted to audio. While the image and audio processing work as expected, FFmpeg fails during execution, and the server returns a 500 error. I've added error logging to capture FFmpeg’s stderr output, which suggests something is going wrong either with the generated input.txt file or the format of the inputs passed to FFmpeg. I'm not sure if the issue is related to file paths, the concat demuxer formatting, or possibly audio/video duration mismatch. Any insights on how to debug or correct the FFmpeg command would be appreciated.

    the curl request is

    curl -X POST http://localhost:5000/generate-video \
         -H "Content-Type: application/json" \
         -d '{"script": "Hello, this is a test script to generate a video."}' \
         --output output_video.mp4
    
    import os
    import uuid
    import subprocess
    from pathlib import Path
    import numpy as np
    from flask import Flask, request, jsonify, send_file
    from transformers import AutoProcessor, AutoModelForTextToWaveform
    from scipy.io.wavfile import write as write_wav
    import torch
    
    # ========== CONFIG ==========
    IMAGE_FOLDER = "./images"
    OUTPUT_FOLDER = "./output"
    RESOLUTION = (1280, 720)
    IMAGE_DURATION = 3  # seconds per image
    SAMPLE_RATE = 24000
    
    app = Flask(__name__)
    os.makedirs(OUTPUT_FOLDER, exist_ok=True)
    
    # Load Bark-small model and processor
    device = "cuda" if torch.cuda.is_available() else "cpu"
    processor = AutoProcessor.from_pretrained("suno/bark-small")
    model = AutoModelForTextToWaveform.from_pretrained("suno/bark-small").to(device)
    
    
    # ========== UTILS ==========
    def run_ffmpeg(cmd):
        result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        if result.returncode != 0:
            print("[FFmpeg ERROR]\n", result.stderr.decode())
            raise RuntimeError("FFmpeg failed.")
        else:
            print("[FFmpeg] Success.")
    
    
    def find_images(folder):
        return sorted([
            f for f in Path(folder).glob("*")
            if f.suffix.lower() in {".jpg", ".jpeg", ".png"}
        ])
    
    
    def create_ffmpeg_input_list(images, list_file_path):
        with open(list_file_path, "w") as f:
            for img in images:
                f.write(f"file '{img.resolve()}'\n")
                f.write(f"duration {IMAGE_DURATION}\n")
            # Repeat last image to avoid cutoff
            f.write(f"file '{images[-1].resolve()}'\n")
    
    
    # ========== FLASK ROUTE ==========
    @app.route('/generate-video', methods=['POST'])
    def generate_video():
        data = request.get_json()
        script = data.get("script")
        if not script:
            return jsonify({"error": "No script provided"}), 400
    
        images = find_images(IMAGE_FOLDER)
        if not images:
            return jsonify({"error": "No images found in ./images"}), 400
    
        # Generate audio
        print("[1/3] Generating audio with Bark...")
        inputs = processor(script, return_tensors="pt").to(device)
        with torch.no_grad():
            audio_values = model.generate(**inputs)
    
        audio_np = audio_values[0].cpu().numpy().squeeze()
        audio_np = np.clip(audio_np, -1.0, 1.0)
        audio_int16 = (audio_np * 32767).astype(np.int16)
    
        audio_path = os.path.join(OUTPUT_FOLDER, f"{uuid.uuid4()}.wav")
        write_wav(audio_path, SAMPLE_RATE, audio_int16)
    
        # Create FFmpeg concat file
        print("[2/3] Preparing image list for FFmpeg...")
        list_file = os.path.join(OUTPUT_FOLDER, "input.txt")
        create_ffmpeg_input_list(images, list_file)
    
        # Final video path
        final_video_path = os.path.join(OUTPUT_FOLDER, f"{uuid.uuid4()}.mp4")
    
        # Run FFmpeg
        print("[3/3] Running FFmpeg to create video...")
        ffmpeg_cmd = [
            "ffmpeg", "-y",
            "-f", "concat", "-safe", "0", "-i", list_file,
            "-i", audio_path,
            "-vf", f"scale={RESOLUTION[0]}:{RESOLUTION[1]}:force_original_aspect_ratio=decrease,"
                   f"pad={RESOLUTION[0]}:{RESOLUTION[1]}:(ow-iw)/2:(oh-ih)/2:color=black",
            "-c:v", "libx264", "-pix_fmt", "yuv420p",
            "-c:a", "aac", "-b:a", "192k",
            "-shortest", "-movflags", "+faststart",
            final_video_path
        ]
    
        try:
            run_ffmpeg(ffmpeg_cmd)
        except RuntimeError:
            return jsonify({"error": "FFmpeg failed. Check server logs."}), 500
    
        return send_file(final_video_path, as_attachment=True)
    
    
    # ========== RUN APP ==========
    if __name__ == '__main__':
        app.run(debug=True)
    
  • Flutter ffmpeg_kit_flutter_new can't build Android app in any version

    3 juillet, par user31929

    I can't build my project on Android ( on Ios it works and the project itself without ffmpeg_kit_flutter_new builds without problems ) This is the error i obtain:

    /GeneratedPluginRegistrant.java:51: error: cannot find symbol
          com.antonkarpenko.ffmpegkit.MainActivity.registerWith(shimPluginRegistry.registrarFor("com.antonkarpenko.ffmpegkit.MainActivity"));
                                     ^
      symbol:   class MainActivity
      location: package com.antonkarpenko.ffmpegkit
    

    This is my flutter doctor :

    [✓] Flutter (Channel stable, 3.19.4, on macOS 15.4.1 24E263 darwin-x64, locale it-IT)
        • Flutter version 3.19.4 on channel stable at ….
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 68bfaea224 (1 year, 2 months ago), 2024-03-20 15:36:31 -0700
        • Engine revision a5c24f538d
        • Dart version 3.3.2
        • DevTools version 2.31.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at …..
        • Platform android-35, build-tools 34.0.0
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 16.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 16E140
        • CocoaPods version 1.16.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2023.1)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    
    [✓] VS Code (version 1.99.3)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.110.0
    
    [✓] Connected device (5 available)
        • SM A135F (mobile)              • RF8T40TMS6Z               • android-arm    • Android 12 (API 31)
        • cri SE 128 (mobile)      • 00008030-001268303E38402E • ios            • iOS 18.4.1 22E252
        • iPhone di WacMini (mobile) • 00008030-00121D543CE8802E • ios            • iOS 18.4.1 22E252
        • macOS (desktop)                • macos                     • darwin-x64     • macOS 15.4.1 24E263 darwin-x64
        • Chrome (web)                   • chrome                    • web-javascript • Google Chrome 136.0.7103.93
    
    [✓] Network resources
        • All expected network resources are available.
    

    My android/app/build.gradle

    def localProperties = new Properties()
    def localPropertiesFile = rootProject.file('local.properties')
    if (localPropertiesFile.exists()) {
        localPropertiesFile.withReader('UTF-8') { reader ->
            localProperties.load(reader)
        }
    }
    
    def keystoreProperties = new Properties()
    def keystorePropertiesFile = rootProject.file('key.properties')
    if (keystorePropertiesFile.exists()) {
        keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
    }
    
    def flutterRoot = localProperties.getProperty('flutter.sdk')
    if (flutterRoot == null) {
        throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
    }
    
    def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
    if (flutterVersionCode == null) {
        flutterVersionCode = '1'
    }
    
    def flutterVersionName = localProperties.getProperty('flutter.versionName')
    if (flutterVersionName == null) {
        flutterVersionName = '1.0'
    }
    
    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
    apply plugin: 'com.google.gms.google-services'
    apply plugin: 'com.google.firebase.crashlytics'
    apply plugin: 'org.jetbrains.kotlin.android'
    
    
    android {
    
        compileSdkVersion 35
    
        namespace = "com.app.app"
        sourceSets {
            main.java.srcDirs += 'src/main/kotlin'
        }
    
        defaultConfig {
            applicationId "com.appid.appid"
            minSdkVersion 24
            targetSdkVersion 35
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
           
            // insert this line of code in order to manage correct build abi configuration only on supported devices not supported tablet device emulator
           /* ndk {
                abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86_64'
            }*/
        }
    
        signingConfigs {
            release {
                keyAlias keystoreProperties['keyAlias']
                keyPassword keystoreProperties['keyPassword']
                storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
                storePassword keystoreProperties['storePassword']
            }
        }
    
        buildTypes {
            debug {
                debuggable true
            }
    
            release {
                signingConfig signingConfigs.release
                debuggable false
                shrinkResources true
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    
    }
    
    flutter {
        source '../..'
    }
    
    dependencies {
        implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.24"
    }
    

    My android/build.gradle

    buildscript {
        ext.kotlin_version = '1.9.24'
        repositories {
            google()
            mavenCentral()
            jcenter()
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:8.4.0'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath 'com.google.gms:google-services:4.3.14'
            classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'
        }
    }
    
    allprojects {
        repositories {
            google()
            mavenCentral()
            jcenter()
        }
    
        
        subprojects {
            tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
                kotlinOptions.jvmTarget = "1.8"
            }
            afterEvaluate { project ->
                if (project.hasProperty('android')) {
                    project.android {
                        if (namespace == null) {
                            namespace project.group
                        }
                    }
                }
            }
        }
        
    }
    
    
    ext {
        flutterFFmpegPackage = "min-gpl-lts"
    }
    
    
    rootProject.buildDir = '../build'
    subprojects {
        project.buildDir = "${rootProject.buildDir}/${project.name}"
    }
    subprojects {
        project.evaluationDependsOn(':app')
    }
    
    tasks.register("clean", Delete) {
        delete rootProject.buildDir
    }
    

    My gradle.wrapper.properties

    distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
    

    What i have already tried :

    • flutter clean/flutter pub get
    • remove .gradle folder/flutter clean/flutter pub get
    • remove GeneratedPluginRegistrant.java file then remove .gradle/flutter clean/flutter pub get

    I have this issue in every version of the plugin. There is something wrong in my configurations or maybe this is a plugin issue ?