Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • I use the bramp/ffmpeg-cli-wrapper of java. How to terminate the execution in the thread ?

    8 mars, par Hao Tan

    I want to use ffmpeg to achieve streaming function

    First I created a thread pool

     private final Map taskThreads = new ConcurrentHashMap<>();
    Thread taskThread = new Thread(() -> {
                try {
                    private void startTask(Device task) {
            Thread taskThread = new Thread(() -> {
    
                FFmpegBuilder builder = new FFmpegBuilder()
                        .setInput(source) 
                        .overrideOutputFiles(true)
                        .addOutput(destination) 
                        .setFormat("flv")
                        .addExtraArgs("-c", "copy") 
                        .done();
    
                FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
                executor.createJob(builder).run();
            });
            taskThreads.put(task.getId(), taskThread);
            taskThread.start();
        }
    

    stop code

    public void stopTask(Integer taskId) {
            Thread taskThread = taskThreads.get(taskId);
            if (taskThread != null) {
                taskThread.interrupt(); 
                taskThreads.remove(taskId);
                
                DeviceDto task = deviceService.findById(taskId);
                if (task != null) {
                    task.setIsOnline(0);
                    Device device = new Device();
                    BeanUtils.copyProperties(task,device);
                    deviceService.update(device);
                }
            }
        }
    

    I call stopTask and cannot terminate the ffmpeg thread

    It should be executor.createJob(builder).run(); blocked

    How to solve

  • Undefined reference to FFMPEG function despite linking via CMake

    8 mars, par MysticTortoise

    I am attempting to integrate FFMPEG's libav library into my project. I use CMake and want to build FFmpeg from source since I want to configure things specifically for my use case. I have compiled the files into .a archive static libraries which are included in my project, but i continually get an error:

    CMakeFiles/ffmpegtest.dir/main.cpp.obj:main.cpp:(.text+0xc): undefined reference to avformat_alloc_context

    I've tried a variety of solutions online but none seem to work. I've stripped the project down to the bare minimum and yet it continues to produce this error.

    Here is my main.cpp

    extern "C" {
        #include frame.h>
        #include mem.h>
        #include avcodec.h>
        #include avformat.h>
    }
    
    int main(){
        avformat_alloc_context();
        return 0;
    }
    

    And my CMakeLists.txt

    cmake_minimum_required(VERSION 3.24)
    project(ffmpegtest)
    
    add_executable(ffmpegtest main.cpp)
    
    find_library(AVCODEC_LIB avcodec PATHS lib/ffmpeg/lib)
    find_library(AVFORMAT_LIB avformat PATHS lib/ffmpeg/lib)
    find_library(AVUTIL_LIB avutil PATHS lib/ffmpeg/lib)
    find_library(AVDEVICE_LIB avdevice PATHS lib/ffmpeg/lib)
    
    target_include_directories(ffmpegtest PRIVATE
       lib/ffmpeg/include
    )
    
    
    target_link_libraries(ffmpegtest
     ${AVCODEC_LIB}  ${AVFORMAT_LIB}  ${AVUTIL_LIB}  ${AVDEVICE_LIB}
    )
    

    And finally, the configure script I have setup to build FFmpeg (stripped down)

    ./configure \
    --disable-doc \
    --enable-static \
    --prefix=${ffmpegBuildDir}
    

    (where ffmpegBuildDir is set elsewhere in the script. I have copied the .a files from that ffmpegBuildDir and into the corresponding directory into my stripped down test case.)

    I don't know what could be causing issues here. What am I doing wrong?

    For additional info, here is the command that CMake spits out:

    C:\WINDOWS\system32\cmd.exe /C "cd . && C:\devkitPro\msys2\mingw32\bin\c++.exe   CMakeFiles/ffmpegtest.dir/main.cpp.obj -o ffmpegtest.exe -Wl,--out-implib,libffmpegtest.dll.a -Wl,--major-image-version,0,--minor-image-version,0  D:/Programming/ffmpegtest/lib/ffmpeg/lib/libavcodec.a  D:/Programming/ffmpegtest/lib/ffmpeg/lib/libavformat.a  D:/Programming/ffmpegtest/lib/ffmpeg/lib/libavutil.a  D:/Programming/ffmpegtest/lib/ffmpeg/lib/libavdevice.a  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
    C:/devkitPro/msys2/mingw32/bin/../lib/gcc/i686-w64-mingw32/14.2.0/../../../../i686-w64-mingw32/bin/ld.exe: CMakeFiles/ffmpegtest.dir/main.cpp.obj:main.cpp:(.text+0xc): undefined reference to avformat_alloc_context
    

    EDIT: Here is exactly what i get from doing nm libavformat.a | grep avformat_alloc_context

                     U avformat_alloc_context
                     U avformat_alloc_context
                     U avformat_alloc_context
                     U avformat_alloc_context
                     U avformat_alloc_context
                     U avformat_alloc_context
                     U avformat_alloc_context
                     U avformat_alloc_context
                     U avformat_alloc_context
                     U avformat_alloc_context
    0000000000000390 T avformat_alloc_context
                     U avformat_alloc_context
                     U avformat_alloc_context
                     U avformat_alloc_context
                     U avformat_alloc_context
                     U avformat_alloc_context
                     U avformat_alloc_context
    
  • How to stream frames from ffmpeg to a process ?

    7 mars, par Vorac

    I would like to encrypt camera frames before transmitting. For that purpose the encrypting process needs to get the raw frames through some mode of IPC. I tried reading through the steaming API docs but got lost. This is an "what approach" question instead of a "working solution" one.

  • FFMpeg D3D11 decoded image to OpenCV UMat

    7 mars, par Spuriga

    I would like to copy FFMpeg decoded image data to an UMat WITHOUT copying it to the CPU RAM:

    enter image description here

    Is there any way to do it? What if there are two or more GPU card in the PC?

    I have this code for av_image_copy_to_buffer, works fine:

    int copy_frame_to_buffer(void* handle, void* buffer, int bufferSize) 
    {
        int ret = 0;
        int calculatedBufferSize;
        
        VideoDecoderContext* context = static_cast(handle);
    
        calculatedBufferSize = av_image_get_buffer_size(static_cast(context->frame->format), context->frame->width, context->frame->height, 1);
        if (calculatedBufferSize != bufferSize)
        {
            fprintf(stderr, "Calculated buffer (%d) is not equal to bufferSize (%d).\n", calculatedBufferSize, bufferSize);
            return -1;
        }
    
        uint8_t* byte_buffer = static_cast(buffer);
    
        ret = av_image_copy_to_buffer(byte_buffer, calculatedBufferSize,
            (const uint8_t* const*)context->frame->data,
            (const int*)context->frame->linesize, static_cast(context->frame->format),
            context->frame->width, context->frame->height, 1);
        if (ret < 0) {
            fprintf(stderr, "Can not copy image to buffer\n");
            return ret;
        }
        
        return ret;
    }
    

    ...but if I change the context->frame to context->hwFrame it is not working.

  • ffmpeg command not found but pip list shows ffmpeg

    7 mars, par your_doomsday07

    I have been trying to install ffmpeg using the command pip install ffmpeg and I am doing this in a server where we dont have sudo permissions. On writing ffmpeg I get ffmpeg: command not found. Then I checked with pip list and it showed ffmpeg. Please help me.