Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • How can I programatically escape option strings for ffmpeg ?

    27 mai 2014, par pixelearth

    I'm just using ffmpeg for my first serious project. I was happy until I had a string that needed escaping. Now I want to die.

    I want to put this string into a blank video that will then (later) be appended to a separate video "Tango Milonga 1: The Dance's Music and History"

    When I write it like this, it obviously doesn't work becaues the : and ' chars need escaping and probably others:

    ffmpeg -y -f lavfi -i color=c=black:s=640x362 -t 4 -vf drawtext="fontfile=/Library/Fonts/Arial.ttf: text=Tango Milonga 1: The Dance's Music and History: fontcolor=white: fontsize=24: box=0: x=(w-text_w)/2: y=(h-text_h-line_h)/2","fade=t=out:st=3:d=1"            /Users/user/my_life/sites/2007/idance/videos_in_production/intros/2621.mp4
    

    To make matters more complicated, command and the text option in this example will really be dynamically generated from a DB and will be looped over thousands of times. This currently looks like this in my ruby script (another level of escaping):

      `ffmpeg -y -f lavfi -i color=c=black:s=640x362 -t 4 -vf drawtext="fontfile=/Library/Fonts/Arial.ttf: text=#{@lesson.name}: fontcolor=white: fontsize=24: box=0: x=(w-text_w)/2: y=(h-text_h-line_h)/2","fade=t=out:st=3:d=1" #{@dir}/intros/#{@lesson.id}.mp4`
    

    How can I programatically escape the string @lesson.name above so that this command always works?

  • ffmpeg video to image sequence batch file

    26 mai 2014, par Dale Cooper

    I'm using ffmpeg to convert .avi file into a .png image sequence. This one works just fine:

    @ ECHO OFF
    
    FOR %%A IN (*.avi) DO CALL :avi2png "%%A"
    
    :avi2png
    ffmpeg.exe -y -i %* -sameq -f image2 -c:v png "%%03d.png"
    
    ECHO.
    GOTO :EOF
    

    But I want the script to extract the name without the extension from .avi file that is currently being processed. This is what the image sequence should look like: currentavi001.png, currentavi002.png etc. The script I came up with isn't working:

    @ ECHO OFF
    
    FOR %%A IN (*.avi) DO CALL :avi2png "%%A"
    
    :avi2png
    ffmpeg.exe -y -i %* -sameq -f image2 -c:v png "%%~nA%%03d.png"
    
    ECHO.
    GOTO :EOF
    

    I've tried both %~nA and %%~nA, but to no avail. The script returns this:

    Couldn't open file : 
    av_interleaved_write_frame(): Input/output error.
    

    I'm a complete layman and would welcome every bit of help.

  • Handling 1280 * 720 [ hd version ] size of Frame in SDL2 how to ?

    26 mai 2014, par Whoami

    Is this the right way of creating texture to render 1280*720 [ hd version] image?

    I am receiving the packet from RTSP server through ffmpeg, and decoding and getting frame.

    To render i follow the below steps.

     SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
    
     screen = SDL_CreateWindow("TEST APPLICATION", SDL_WINDOWPOS_UNDEFINED,
                        SDL_WINDOWPOS_UNDEFINED, 0, 0,
                        SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN);
    
    bmp = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, 1280, 720);
    
    SDL_RenderSetLogicalSize(renderer, 1280, 720);
    
    
     while (1)
      {
        Handling SDL Event.    ->
        for (;;)  {
        while ( SDL_PollEvent(&event))
          switch (event.type) {
            case SDL_QUIT:
            case SDL_KEYDOWN:
                    SDL_Quit ();
                    exit (0);
                    break;
            case DISPLAY_IMAGE:
                    SDL_UpdateYUVTexture(bmp, NULL, pFrame->data[0],
                                         pFrame->linesize[0], pFrame->data[1], 
                                         pFrame->linesize[1],
                                         pFrame->data[2], pFrame->linesize[2]);
    
                    SDL_RenderClear(renderer);
                    SDL_RenderCopy(renderer, bmp, NULL, NULL);
                    SDL_RenderPresent(renderer);
                    break;
              }
    
      }
    

    Also, From some other thread, i will push the event like:

    SDL_Event event;
    event.type =  DISPLAY_IMAGE;
    SDL_PushEvent (&event);
    

    Kindly tell me if this is the right practice ?

  • Problems compiling ffmpeg on windows using cygwin

    26 mai 2014, par Papajohn000

    I've been having a lot of trouble recently compiling ffmpeg on windows. I'm currently using the cgywin terminal to run the code. I've tried following many of the most popular tutorials on the web but I can't seem to get it to work. I'm currently using this tutorial as a guide http://www.roman10.net/how-to-build-ffmpeg-for-android/

    Where I'm at:

    I've created a bash script

    #!/bin/bash
    
    NDK=C:/Users/jrblain/Development/adt-bundle-windows-x86_64-20130514/android-ndk-r9
    PLATFORM=$NDK/platforms/android-8/arch-arm/
    PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64
    function build_one
    {
    ./configure --target-os=linux \
        --prefix=$PREFIX \
        --enable-cross-compile \
        --extra-libs="-lgcc" \
        --arch=arm \
        --cc=$PREBUILT/bin/arm-linux-androideabi-gcc \
        --cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
        --nm=$PREBUILT/bin/arm-linux-androideabi-nm \
        --sysroot=$PLATFORM \
        --extra-cflags=" -O3 -fpic -DANDROID -DHAVE_SYS_UIO_H=1 -Dipv6mr_interface=ipv6mr_ifindex -fasm -Wno-psabi -fno-short-enums -fno-strict-aliasing -finline-limit=300 $OPTIMIZE_CFLAGS " \
        --disable-shared \
        --enable-static \
        --extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog" \
        --disable-everything \
        --enable-demuxer=mov \
        --enable-demuxer=h264 \
        --disable-ffplay \
        --enable-protocol=file \
        --enable-avformat \
        --enable-avcodec \
        --enable-decoder=rawvideo \
        --enable-decoder=mjpeg \
        --enable-decoder=h263 \
        --enable-decoder=mpeg4 \
        --enable-decoder=h264 \
        --enable-parser=h264 \
        --disable-network \
        --enable-zlib \
        --disable-avfilter \
        --disable-avdevice \
        $ADDITIONAL_CONFIGURE_FLAG
    
    make clean
    make  -j4 install
    $PREBUILT/bin/arm-linux-androideabi-ar d libavcodec/libavcodec.a inverse.o
    $PREBUILT/bin/arm-linux-androideabi-ld -rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib  -soname libffmpeg.so -shared -nostdlib  -z,noexecstack -Bsymbolic --whole-archive --no-undefined -o $PREFIX/libffmpeg.so libavcodec/libavcodec.a libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a -lc -lm -lz -ldl -llog  --warn-once  --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a
    }
    
    #arm v6
    #CPU=armv6
    #OPTIMIZE_CFLAGS="-marm -march=$CPU"
    #PREFIX=./android/$CPU 
    #ADDITIONAL_CONFIGURE_FLAG=
    #build_one
    
    #arm v7vfpv3
    CPU=armv7-a
    OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=$CPU "
    PREFIX=./android/$CPU
    ADDITIONAL_CONFIGURE_FLAG=
    build_one
    
    #arm v7vfp
    #CPU=armv7-a
    #OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU "
    #PREFIX=./android/$CPU-vfp
    #ADDITIONAL_CONFIGURE_FLAG=
    #build_one
    
    #arm v7n
    #CPU=armv7-a
    #OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=neon -marm -march=$CPU -mtune=cortex-a8"
    #PREFIX=./android/$CPU 
    #ADDITIONAL_CONFIGURE_FLAG=--enable-neon
    #build_one
    
    #arm v6+vfp
    #CPU=armv6
    #OPTIMIZE_CFLAGS="-DCMP_HAVE_VFP -mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU"
    #PREFIX=./android/${CPU}_vfp 
    #ADDITIONAL_CONFIGURE_FLAG=
    #build_one
    

    I then followed steps 4-6 of this post Does anyone find this useful? - Compiling FFMPEG on Windows with Cywin and NDK r5 which consists of

    4 - Open the file 'configure' in the root of the FFMPEG directory in a text editor.
    
    5 - Comment out lines 2073, 2074 and 2075.
    
    6 - Below 2075, add the following line:
    
    TMPDIR=c:/cygwin/tmp
    

    When I ran the script in cgywin I got this result:

        install prefix            ./android/armv7-a
    source path               .
    C compiler                C:/Users/jrblain/Development/adt-bundle-windows-x86_64-20130514/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/arm-linux-androideabi-gcc
    ARCH                      arm (armv7-a)
    big-endian                no
    runtime cpu detection     yes
    ARMv5TE enabled           yes
    ARMv6 enabled             yes
    ARMv6T2 enabled           yes
    VFP enabled               yes
    NEON enabled              yes
    THUMB enabled             no
    debug symbols             yes
    strip symbols             yes
    optimize for size         no
    optimizations             yes
    static                    yes
    shared                    no
    postprocessing support    no
    new filter support        no
    network support           no
    threading support         pthreads
    safe bitstream reader     yes
    SDL support               no
    opencl enabled            no
    texi2html enabled         no
    perl enabled              no
    pod2man enabled           no
    makeinfo enabled          no
    
    External libraries:
    zlib
    
    Enabled decoders:
    h263                    mjpeg                   rawvideo
    h264                    mpeg4
    
    Enabled encoders:
    
    Enabled hwaccels:
    
    Enabled parsers:
    h263                    h264                    mpeg4video
    
    Enabled demuxers:
    h264                    mov
    
    Enabled muxers:
    
    Enabled protocols:
    file
    
    Enabled filters:
    
    Enabled bsfs:
    
    Enabled indevs:
    
    Enabled outdevs:
    
    License: LGPL version 2.1 or later
    Creating config.mak, config.h, and doc/config.texi...
    libavutil/avconfig.h is unchanged
    
    WARNING: C:/Users/jrblain/Development/adt-bundle-windows-x86_64-20130514/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/arm-linux-androideabi-pkg-config not found, library detection may fail.
    library.mak:105: *** missing separator.  Stop.
    library.mak:105: *** missing separator.  Stop.
    C:\Users\jrblain\Development\adt-bundle-windows-x86_64-20130514\android-ndk-r9\toolchains\arm-linux-androideabi-4.6\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.exe: ,noexecstack: unknown -z option
    C:\Users\jrblain\Development\adt-bundle-windows-x86_64-20130514\android-ndk-r9\toolchains\arm-linux-androideabi-4.6\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ld.exe: use the --help option for usage information
    

    After this script runs I get some new files within my ffmpeg folder. They are .config, config(header), config.mak , config.fate. The android folder is never created like it is supposed to. I'm also not sure where the library.mak error is coming from considering that it came with ffmpeg download.

    I'm not sure where this i'm going wrong in all of this. I feel like the fact that I'm using windows will make this build process different.

  • ffmpeg avcodec_encode_video2 to avcodec_decode_video2

    26 mai 2014, par Godspped

    I am completely confused as to why this is not working...

    So I have verified that my mjpg encode is working as I have verified that the jpg image after I wrote it to file. As a test I wanted to decode the data after I encoded it, just for a sanity check, but I keep getting an access violation, and I am completely lost as to why.

    This is how I defined my decode buffer

    AVFrame *pFrameDecoded = avcodec_alloc_frame();
    int num_bytes2 = avpicture_get_size(PIX_FMT_YUVJ422P, 320, 248);
    uint8_t* frame2_buffer2 = (uint8_t *)av_malloc(num_bytes2*sizeof(uint8_t));
    avpicture_fill((AVPicture*)pFrameDecoded, frame2_buffer2, PIX_FMT_YUVJ422P, 320, 240);
    

    This is the code segment that is failing...

    AVPacket packet 
    av_init_packet(&packet);            
    packet.data = NULL;
    packet.size = 0;
    
    
    out_size = avcodec_encode_video2(codecContext, &packet, frame2, &got_output);
    if (got_output && got_output > 0) {
      int finaldone;
      // ERROR OCCURS HERE!!!
      avcodec_decode_video2( codecContext, pFrameDecoded, &finaldone, &packet ); 
    }