Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • ffmpeg dshow - Getting duplicate/dropped frames, I'm not doing anything

    30 juin, par ENunn

    I'm messing around with recording my capture card with ffmpeg. No matter what I do I get duplicate and dropped frames. d

    I'm not even doing anything on my computer. Is there a fix for this at all? Here's my command.

    ffmpeg -hide_banner -rtbufsize 2G -f dshow -video_size 2560x1440 -framerate 60.0002 -pix_fmt bgr24 -video_pin_name 0 -audio_pin_name 1 -i video="AVerMedia HD Capture GC573 1":audio="AVerMedia HD Capture GC573 1" -async 1 -rtbufsize 1M -f dshow -sample_rate 48000 -i audio="Digital Audio (S/PDIF) (Sound Blaster X-Fi Xtreme Audio)" -map 0 -map 1 -colorspace:v "bt709" -color_primaries:v "bt709" -color_trc:v "bt709" -color_range:v "tv" -c:v hevc_nvenc -pix_fmt yuv444p16le -gpu any -g 30 -rc vbr -cq 16 -qmin 16 -qmax 16 -b:v 0K -b_ref_mode 1 -spatial_aq 1 -temporal_aq 1 -preset p7 -c:a copy -f segment -segment_time 9999999999 -strftime 1 "F:\ffmpeg recordings%%Y-%%m-%%d_%%H-%%M-%%S.mkv"

  • C++/FFmpeg VLC doesn't play 5.1 audio output

    30 juin, par widgg

    I'm trying to convert audio streams to AAC in C++. FFplay plays everything fine (now) but VLC still has problems with one particular situation: 5.1(side). FFplay only plays it if I filter 5.1(side) to 5.1. Filtering to stereo or mono works well and as expected.

    My setup right now is:

    • send packet
    • receive audio AVFrame
    • apply filter
    • resample to produce output AVFrame with 1024 samples (required by AAC)
    • send new audio frame
    • receive audio packet

    Weirdly enough, using FFmpeg's CLI converts my file properly.

    ffmpeg -i  test.mp4
    

    But FFprobe tells me that the audio stream is now 6 channels instead of 5.1(side) or 5.1. I did try to set AAC to 6 channels in both the AVStream and the AVCodecContext. Setting it in the AVStream doesn't change anything in FFprobe and the AVCodecContext for AAC doesn't allow it.

    FFprobe of the audio stream in the source is:

    ac3 (AC-3 / 0x332D4341), 48000 Hz, 5.1(side), fltp, 384 kb/s
    

    FFprobe of the file created with FFmpeg's CLI:

    aac (LC) (mp4a / 0x6134706D), 48000 Hz, 6 channels, fltp, 395 kb/s (default)
    

    FFprobe of my current version:

    aac (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 321 kb/s (default)
    

    Update 1

    Here's how the filter is created (removed error handling code to make it shorter and more compact):

    struct FilterInfo {
        const AVCodecContext *srcContext, *sinkContext;
    };
    
    struct Filter {
        AVFilterGraph* graph = avfilter_graph_alloc();
        AVFilterContext* src, sink;
    };
    
    std::string getLayoutName(const AVChannelLayout* layout) {
        char layoutName[256];
        auto ret = av_channel_layout_describe(layout, layoutName, 256);
        return std::string(layoutName, ret);
    }
    
    std::string getFilterArgs(const FilterInfo& info) {
        const auto layout = &info.sinkContext->ch_layout;
        std::string dstLayout = getLayoutName(layout);
    
        std::string chans("0"sv);
        for (int c = 1; c < layout->nb_channels; ++c) {
            chans = std::format("{}|{}"sv, chans, c);
        }
        return std::format("channelmap={}:{}"sv, chans, dstLayout);
    }
    
    AVFilterContext* createSrcFilterContext(
        const AVCodecContext* cctx, AVFilterGraph* graph) {
        //
        std::string layout=getLayoutName(&cctx->ch_layout);
    
        const auto args = std::format("time_base={}/{}:sample_rate={}:sample_fmt={}:channel_layout={}"sv,
            cctx->time_base.num, cctx->time_base.den, cctx->sample_rate,
            av_get_sample_fmt_name(cctx->sample_fmt), layout);
    
        const AVFilter* filt = avfilter_get_by_name("abuffer");
        AVFilterContext* fctx = nullptr;
        avfilter_graph_create_filter(&fctx, filt, "in", args.c_str(), nullptr, graph);
        return fctx;
    }
    
    AVFilterContext* createSinkFilterContext(
        const AVCodecContext* cctx, AVFilterGraph* graph) {
        //
        std::string layout = getLayoutName(&cctx->ch_layout));
    
        const AVFilter* filt = avfilter_get_by_name("abuffersink");
        AVFilterContext* fctx = nullptr;
        avfilter_graph_create_filter(&fctx, filt, "out", nullptr, nullptr, graph);
        av_opt_set(fctx, "ch_layouts", layout.c_str(), AV_OPT_SEARCH_CHILDREN);
    
        const AVSampleFormat sampleFmts[] = {cctx->sample_fmt, AV_SAMPLE_FMT_NONE};
        av_opt_set_int_list(fctx, "sample_fmts", sampleFmts, AV_SAMPLE_FMT_NONE, AV_OPT_SEARCH_CHILDREN);
    
        const int sampleRates[] = {cctx->sample_rate, -1};
        av_opt_set_int_list(fctx, "sample_rates", sampleRates, -1, AV_OPT_SEARCH_CHILDREN);
        return fctx;
    }
    
    Filter create(const FilterInfo& info) {
        std::string filterArgs = getFilterArgs(info);
    
        filter.graph = avfilter_graph_alloc();
        filter.src, createSrcFilterContext(info.srcContext, filter.graph);
        filter.sink, createSinkFilterContext(info.sinkContext, filter.graph);
    
        AVFilterInOut* inputs = avfilter_inout_alloc();
        AVFilterInOut* outputs = avfilter_inout_alloc();
    
        outputs->name = av_strdup("in");
        outputs->filter_ctx = filter.src.get();
        outputs->pad_idx = 0;
        outputs->next = nullptr;
    
        inputs->name = av_strdup("out");
        inputs->filter_ctx = filter.sink.get();
        inputs->pad_idx = 0;
        inputs->next = nullptr;
    
        avfilter_graph_parse_ptr(filter.graph, filterArgs.c_str(), &inputs, &outputs, nullptr);
        avfilter_inout_free(&inputs);
        avfilter_inout_free(&outputs);
    
        avfilter_graph_config(filter.graph, nullptr);
        return filter; // didn't fail, but not needed
    }
    

    This is how it gets executed:

    
    AVFrame* receiveFrame(Filter& f) {
        AVFrame* frm = av_frame_alloc();
        if (int ret = av_buffersink_get_frame(f.sink, frm); ret < 0) {
            if (ret == AVERROR(EAGAIN)) {
                return nullptr;
            }
            else {
                // throw error
            }
        }
        return frm;
    }
    
    void filteredFrameToProcess(Filter& f, SomeFrameQueue& queue) {
        while (true) {
            if (auto frm = receiveFrame(f); frm) {
                queue.emplace_back(frm);
            }
            else {
                break;
            }
        }
    }
    
    void filter(Filter& f, SomeFrameQueue& dst, SomeFrameQueue& src) {
        filteredFrameToProcess(f, dst); 
        if (!src.empty()) {
            av_buffersrc_write_frame(f.src, src.front());
            src.pop_front();
        }
        filteredFrameToProcess(f, dst);
    }
    
  • Flutter ffmpeg_kit_flutter_new can't build Android app in any version

    30 juin, 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 ?

  • FFMPEG HLS stream for Android and IOS

    30 juin, par Poda

    I'm trying to stream to mobile devices with ffmpeg and apache2.2 but I haven't been successful.

    I used this command to create the segments and the playlist:

    ffmpeg -i http://x.x.x.x:8080 -codec:v libx264 -r 25 -pix_fmt yuv420p -profile:v baseline -level 3 -b:v 500k -s 640x480 -codec:a aac -strict experimental -ac 2 -b:a 128k -movflags faststart -flags -global_header -map 0 -f hls  -hls_time 10 -hls_list_size 5 -hls_allow_cache 0 -sc_threshold 0 -hls_flags delete_segments -hls_segment_filename out%05d.ts list.m3u8
    

    The source is a http stream which is streamed by VLC media player.

    Example content of the list.m3u8 file:

    #EXTM3U
    #EXT-X-VERSION:3
    #EXT-X-ALLOW-CACHE:NO
    #EXT-X-TARGETDURATION:10
    #EXT-X-MEDIA-SEQUENCE:89
    #EXTINF:10.000000,
    out00089.ts
    #EXTINF:10.000000,
    out00090.ts
    #EXTINF:10.000000,
    out00091.ts
    #EXTINF:10.000000,
    out00092.ts
    #EXTINF:9.000000,
    out00093.ts
    #EXT-X-ENDLIST
    

    I created another playlist file - playlist.m3u8:

    #EXTM3U
    #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=512000
    http://x.x.x.x/list.m3u8
    

    If I open this (playlist.m3u8) file in VLC media player then it plays. It also works in desktop chrome and desktop firefox browsers with Video-js plugin flash fallback.

    I set the correct MIME types to the .ts and .m3u8 files in .htaccess file:

    AddType application/x-mpegURL .m3u8
    AddType video/MP2T .ts
    

    FFprobe output for playlist.m3u8:

    Input #0, hls,applehttp, from 'playlist.m3u8':
        Duration: N/A, start: 1.400000, bitrate: N/A
        Program 0
        Metadata: variant_bitrate : 512000
    Stream #0:0: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Metadata: variant_bitrate : 512000
    Stream #0:1: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 128 kb/s
    Metadata: variant_bitrate : 512000
    

    What should I do to make it work?

    UPDATE

    It works if I provide a link to list.m3u8 file (created by ffmpeg).

  • Where to download avcodec.dll ? [closed]

    29 juin, par Олег Ю.

    I see in the folder of some application FFMPEG files avcodec.dll, avformat.dll, avutil.dll, etc. They are all old version of FFMPEG. I wanted to update them, but I did not find where to download them on the FFMPEG website. Are these complete libraries available for download? Or do they exist only in development files and the authors of some application create FFMPEG .dll files themselves? In other words, avcodec.dll files from different applications are not interchangeable? Help me figure it out.