Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • FFMPEG - speed up/slow down video, add jitter etc

    27 septembre 2019, par Darrell

    I'm trying to put together a Windows script that will process short videos in a folder. The videos will be shot at a high frame rate 60+ fps and be about 4-5 secs long.

    Basically I am looking to make various style clips, using fast/slow effects, back and forth etc. So, the script might process a video, make it start normal speed, then slow motion. Next video might be normal speed, slomo, normal speed slomo. Next video might be forwards,back, forwards back, slomo.

    See example: (this is a compliation, I'm looking at processing individual videos in a folder.)

    http://www.youtube.com/watch?v=K03IBQZu8SQ

    I'm guessing there is no way to do this, other than splitting a clip using FFMPEG, processing the bits, then merging back together? I can't seem to find a way to do it as one clip.

  • avformat_open_input for 24-bit audio fails intermittently with avfoundation due to "audio format is not supported"

    27 septembre 2019, par NaderNader

    My application uses the ffmpeg APIs (avformat, avdevice, etc) to open a selected audio input for encoding. For audio inputs configured for 24-bit I can reliably open them the first time, but when I close and reopen that input later, the avformat_open_input() call fails due to "audio format is not supported". My testing shows that it never fails the first time after starting my, and has only about a 50% chance of success when reopening.

    The failure only occurs when I configure my "Built-in Microphone" audio input for 24-bit integer. 16-bit integer and 32-bit float work reliably. Changing the number of channels and sample rate has no effect.

    I have read the documentation and see that the proper way to free the resources after opening is to call avformat_close_input. The only way I have found to guarantee success is to only open the input once.

    I have written a test program to recreate these failures.

    int main() {
    
        avdevice_register_all();
    
        cout << "Running open audio test" << endl;
    
    
        int i;
        for(i = 0; i< 10; i++) {
    
            AVDictionary* options = NULL;
            AVInputFormat* inputFormat = av_find_input_format("avfoundation");
            if (!inputFormat) {
                cout << "avfoundation inputFormat=null" << endl;
            }
    
            AVFormatContext* formatContext = avformat_alloc_context();
            int result = avformat_open_input(&formatContext, ":1", inputFormat, &options);
            if (result < 0) {
                char error[256];
                av_strerror(result, error, sizeof(error));
                cout << "result=" << result << " " << error << endl;
            } else {
                cout << "input opened successfully" << endl;
            }
    
            sleep(1);
    
            avformat_close_input(&formatContext);
    
            sleep(1);
    
        }
    
        return 0;
    }
    

    I would expect the main loop to succeed each time but a typical output shows a high failure rate:

    Running open audio test

    input opened successfully
    [avfoundation @ 0x7fdeb281de00] audio format is not supported
    result=-5 Input/output error
    [avfoundation @ 0x7fdeb2001400] audio format is not supported
    result=-5 Input/output error
    [avfoundation @ 0x7fdeb2001400] audio format is not supported
    result=-5 Input/output error
    input opened successfully
    input opened successfully
    input opened successfully
    [avfoundation @ 0x7fdeb2068800] audio format is not supported
    result=-5 Input/output error
    input opened successfully
    input opened successfully
    

    I have tried increasing the sleep time between close and open to 5 seconds, but saw no difference in behavior. While this program runs, I can use the MacOS Audio MIDI Setup to change the microphone input configuration and watch the output change from all success to intermittent errors.

    The source of the failure is https://github.com/FFmpeg/FFmpeg/blob/master/libavdevice/avfoundation.m#L672

    It appears avfoundation.m internally is opening an input stream and grabbing an audio frame to determine the format, but the value returned is not valid sometimes, when the process has previously opened and closed that input.

    Am I not closing the resources properly? Do I have a hardware issue specific to my macbook?

    Additional Details:

    Tested MacBook Pro with MacOS Mojave 10.14.6 Tested with Ffmpeg 3.4.1, 4.0, and 4.1

    list_devices:

    [AVFoundation input device @ 0x7f80fff066c0] AVFoundation video devices:
    [AVFoundation input device @ 0x7f80fff066c0] [0] FaceTime HD Camera
    [AVFoundation input device @ 0x7f80fff066c0] [1] Capture screen 0
    [AVFoundation input device @ 0x7f80fff066c0] AVFoundation audio devices:
    [AVFoundation input device @ 0x7f80fff066c0] [0] Behringer Duplex
    [AVFoundation input device @ 0x7f80fff066c0] [1] Built-in Microphone
    [AVFoundation input device @ 0x7f80fff066c0] [2] USB Audio CODEC
    
  • avformat_open_input fails intermittently with avfoundation due to "audio format is not supported"

    27 septembre 2019, par NaderNader

    My application uses the ffmpeg APIs (avformat, avdevice, etc) to open a selected audio input for encoding. For some inputs I can reliably open them the first time, but when I close and reopen that input later, the avformat_open_input() call fails due to "audio format is not supported". My testing shows that it never fails the first time after starting my, and has only about a 50% chance of success when reopening.

    The failure only occurs with my "Built-in Microphone" audio input. I have a USB audio card that reliably opens and closes repeatedly. I have read the documentation and see that the proper way to free the resources after opening is to call avformat_close_input. The only way I have found to guarantee success is to only open the input once.

    I have written a test program to recreate these failures.

    int main() {
    
        avdevice_register_all();
    
        cout << "Running open audio test" << endl;
    
    
        int i;
        for(i = 0; i< 10; i++) {
    
            AVDictionary* options = NULL;
            AVInputFormat* inputFormat = av_find_input_format("avfoundation");
            if (!inputFormat) {
                cout << "avfoundation inputFormat=null" << endl;
            }
    
            AVFormatContext* formatContext = avformat_alloc_context();
            int result = avformat_open_input(&formatContext, ":1", inputFormat, &options);
            if (result < 0) {
                char error[256];
                av_strerror(result, error, sizeof(error));
                cout << "result=" << result << " " << error << endl;
            } else {
                cout << "input opened successfully" << endl;
            }
    
            sleep(1);
    
            avformat_close_input(&formatContext);
    
            sleep(1);
    
        }
    
        return 0;
    }
    

    I would expect the main loop to succeed each time but a typical output shows a high failure rate:

    Running open audio test

    input opened successfully
    [avfoundation @ 0x7fdeb281de00] audio format is not supported
    result=-5 Input/output error
    [avfoundation @ 0x7fdeb2001400] audio format is not supported
    result=-5 Input/output error
    [avfoundation @ 0x7fdeb2001400] audio format is not supported
    result=-5 Input/output error
    input opened successfully
    input opened successfully
    input opened successfully
    [avfoundation @ 0x7fdeb2068800] audio format is not supported
    result=-5 Input/output error
    input opened successfully
    input opened successfully
    

    I have tried increasing the sleep time between close and open to 5 seconds, but saw no difference in behavior.

    The source of the failure is https://github.com/FFmpeg/FFmpeg/blob/master/libavdevice/avfoundation.m#L672

    It appears avfoundation.m internally is opening an input stream and grabbing an audio frame to determine the format, but the value returned is not valid sometimes, when the process has previously opened and closed that input.

    Am I not closing the resources properly? Do I have a hardware issue specific to my macbook?

    Additional Details:

    Tested MacBook Pro with MacOS Mojave 10.14.6 Tested with Ffmpeg 3.4.1, 4.0, and 4.1

    list_devices:

    [AVFoundation input device @ 0x7f80fff066c0] AVFoundation video devices:
    [AVFoundation input device @ 0x7f80fff066c0] [0] FaceTime HD Camera
    [AVFoundation input device @ 0x7f80fff066c0] [1] Capture screen 0
    [AVFoundation input device @ 0x7f80fff066c0] AVFoundation audio devices:
    [AVFoundation input device @ 0x7f80fff066c0] [0] Behringer Duplex
    [AVFoundation input device @ 0x7f80fff066c0] [1] Built-in Microphone
    [AVFoundation input device @ 0x7f80fff066c0] [2] USB Audio CODEC
    
  • ffmpeg include issue - some functions are missing

    27 septembre 2019, par Thomas Ayoub

    I try to follow and adapt this example to convert a video thanks to FFMPEG but some function seems to be missing like :

    int avcodec_open ( AVCodecContext * avctx, AVCodec * codec)     
    

    When I go in the doc to see where it come from, I find it in the file libavcodec/avcodec.h which is included in my program #include "libavcodec/avcodec.h" (in the top of my .h file).

    Given this, I don't understand why Qt throw me this error :

    ../../Dev/Joker/libs/PhVideo/PhVideoEncoder.cpp:360:6: error: use of undeclared identifier 'avcodec_open'
        if (avcodec_open(c, codec) < 0) {
    
  • scale issues when adding images to a video

    27 septembre 2019, par Geo

    When I add two images to a video, the second image added is scaled down for some reason.

    I have two images arrow.png and icon1.png and one background.mp4 video, when I added the two images onto the video, the result is that the first image is added with the right size, but the second image is added with reduced size, probably in half of the specified size.

    this is my command:

    ffmpeg -i background.mp4 -i arrow.png -i icon1.png -filter_complex "[1:v]scale=311:175,setsar=1,format=bgra[img1];
    [img1]rotate=30*PI/180:c=none:ow=rotw(30*PI/180):oh=roth(30*PI/180)[rotate1];[2:v]scale=319:179,setsar=1,format=bgra[img2];
    [img2]rotate=59*PI/180:c=none:ow=rotw(59*PI/180):oh=roth(59*PI/180)[rotate2];[0][rotate1]overlay=242:-22:enable='between(t,0,6)',scale=hd720[overlay1];
    [overlay1][rotate2]overlay=34:13:enable='between(t,0,6)',scale=hd720" -c:a copy -c:v libx264 -preset ultrafast -y test01.mp4
    

    I am expecting the same size as the specified