Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • ffmpeg transcoding reset the start time of file

    12 août 2013, par diousk

    I use a segmenter to segment my MPEG 2 Ts file into a series of media segment for HTTP live streaming

    and each segment's start time following the previous one (ex:start time of segments: 00:00,00:10,00:20,00:30,...)

    (In Ubuntu)

    The Question is:

    When I use ffmpeg to transcode one of the media segment (ex 800k bps to 200k bps)

    the start time of transcoded media segment will be reset to 0

    ex:As I transcode the third segement,

    start time of segments changing to : 00:00,00:10,00:00,00:30,...

    It cause my player freezing once play the transcoded media segment

    Is there any solution to transcode media file with the same start time?

    I guess it's the ffmpeg reset the PTS(presentation timestamp) of segment

    But I don't know how to fix it...

    here is my ffmpeg command (transcode to 250k bps)

    ============================

    ffmpeg -y -i sample-03.ts -f mpegts -acodec libfaac -ar 48000 -ab 64k -vcodec libx264 -b 250k -flags +loop -cmp +chroma \
     -partitions +parti4x4+partp8x8+partb8x8 -subq 7 -trellis 0 -refs 0 -coder 0 -me_range 16 -keyint_min 25 \
     -sc_threshold 40 -i_qfactor 0.71 -maxrate 250k -bufsize 250k -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 \
     -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 320:240 -g 30 -async 2 sample.ts
    

    ============================

    Help!

    thanks

  • Setting up OpenCV 2.4.6.1 on Ubuntu 12.04.02

    12 août 2013, par Damilola

    I had previously used OpenCV 2.4.5 with some certain configs and packages on Ubuntu 12.04.1 but had issues upgrading to OpenCV 2.4.6.1 on Ubuntu 12.04.2

    I would like to share some ideas (a compilation of noteworthy information gathered from several sources including SO, ubuntu.org, asklinux.org and many other; and of course by trying several procedures)

    Below is what eventually got me through.

    NOTE: ensure you uninstall any previous installation of OpenCV, FFMpeg and other dependencies previously installed.

    STEP 1 (install ffmpeg and dependencies)


    # goto http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/
    # download the latest stable opencv such as 2.4.6.1 (http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.5/opencv-2.4.5.1.tar.gz/download) to current directory (such as home or ~/Document)
    # cd /opt
    # tar -xvf /OpenCV-2.4.6.1.tar.gz
    # cd OpenCV-2.4.6.1
    # create a foler under current dir (following previous step, this should be ), called prepare
    # cd prepare
    # Copy the following script to gedit and save as install.sh to current dir, this should be /prepare
    # Check corresponding url used in the script for latest versions of the package and replace as required
    # Open terminal and navigate to location used above
    # sudo chmod +x install.sh
    # ./install
    

    echo "Removing any pre-installed ffmpeg, x264, and other dependencies (not all the previously installed dependecies)"
    sudo apt-get remove ffmpeg x264 libx264-dev libvpx-dev librtmp0 librtmp-dev libopencv-dev
    sudo apt-get update
    
    arch=$(uname -m)
    if [ "$arch" == "i686" -o "$arch" == "i386" -o "$arch" == "i486" -o "$arch" == "i586" ]; then
    flag=0
    else
    flag=1
    fi
    
    echo "Installing Dependenices"
    sudo apt-get install autoconf automake make g++ curl cmake bzip2 python unzip \
      build-essential checkinstall git git-core libass-dev libgpac-dev \
      libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libx11-dev \
      libxext-dev libxfixes-dev pkg-config texi2html zlib1g-dev
    
    echo "downloading yasm (assembler used by x264 and FFmpeg)"
    # use git or tarball (not both)
    wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
    tar xzvf yasm-1.2.0.tar.gz
    cd yasm-1.2.0
    
    echo "installing yasm"
    ./configure
    make
    sudo make install
    cd ..
    
    echo 'READ NOTE BELOW which was extracted from http://wiki.serviio.org/doku.php?id=build_ffmpeg_linux'
    echo 'New version of x264 contains by default support of OpenCL. If not installed or without sense (example Ubuntu 12.04LTS on VMWare) add to configure additional option --disable-opencl. Without this option ffmpeg could not be configured (ERROR: libx264 not found).'
    
    echo "downloading x264 (H.264 video encoder)"
    # use git or tarball (not both)
    # git clone http://repo.or.cz/r/x264.git or
    git clone git://git.videolan.org/x264.git
    cd x264
    # wget ftp://ftp.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20130801-2245-stable.tar.bz2
    # tar -xvjf x264-snapshot-20130801-2245-stable.tar.bz2
    # cd x264-snapshot-20130801-2245-stable/
    
    echo "Installing x264"
    if [ $flag -eq 0 ]; then
    ./configure --enable-static --disable-opencl
    else
    ./configure --enable-shared --enable-pic --disable-opencl
    fi
    make
    sudo make install
    cd ..
    
    echo "downloading fdk-aac (AAC audio encoder)"
    # use git or tarball (not both)
    git clone --depth 1 git://github.com/mstorsjo/fdk-aac.git
    cd fdk-aac
    
    echo "installing fdk-aac"
    autoreconf -fiv
    ./configure --disable-shared
    make
    sudo make install
    cd ..
    
    echo "installing libmp3lame-dev (MP3 audio encoder.)"
    sudo apt-get install libmp3lame-dev
    
    echo "downloading libopus (Opus audio decoder and encoder.)
    wget http://downloads.xiph.org/releases/opus/opus-1.0.3.tar.gz
    tar xzvf opus-1.0.3.tar.gz
    cd opus-1.0.3
    
    echo "installing libopus"
    ./configure --disable-shared
    make
    sudo make install
    cd ..
    
    echo "downloading libvpx VP8/VP9 video encoder and decoder)
    # use git or tarball (not both)
    git clone --depth 1 http://git.chromium.org/webm/libvpx.git
    cd libvpx
    # wget http://webm.googlecode.com/files/libvpx-v1.1.0.tar.bz2 (this seems not to be update, but can still be used if the fedoraproject link below is not available))
    # wget http://pkgs.fedoraproject.org/repo/pkgs/libvpx/libvpx-v1.2.0.tar.bz2/400d7c940c5f9d394893d42ae5f463e6/libvpx-v1.2.0.tar.bz2
    # tar xvjf libvpx-v1.2.0.tar.bz2
    # cd libvpx-v1.2.0
    
    echo "installing libvpx"
    ./configure --disable-examples
    make
    sudo make install
    cd ..
    
    sudo ldconfig
    
    echo "downloading ffmpeg"
    # git clone http://repo.or.cz/r/ffmpeg.git
    git clone git://source.ffmpeg.org/ffmpeg.git
    cd ffmpeg/
    # wget http://ffmpeg.org/releases/ffmpeg-2.0.tar.bz2
    # tar -xvjf ffmpeg-2.0.tar.bz2
    # cd ffmpeg-2.0/
    
    echo "installing ffmpeg" 
    if [ $flag -eq 0 ]; then
    ./configure --enable-gpl --enable-libass --enable-libfdk-aac --enable-libopus --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab --enable-libvpx
    else
    ./configure --enable-gpl --enable-libass --enable-libfdk-aac --enable-libopus --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab --enable-libvpx --enable-shared
    fi
    
    make
    sudo make install
    hash -r
    
    cd .. # move up one level to prepare folder
    cd .. # move up one level to opencv folder
    
    echo "Checking to see if you're using your new ffmpeg"
    ffmpeg 2>&1 | head -n1
    
    sudo ldconfig
    

    STEP 2 (Install OpenCV and necessary packages)

    echo "Installing Dependenices"
    sudo apt-get install libopencv-dev
    sudo apt-get install libtiff4-dev libjpeg-dev libjasper-dev
    
    echo "installing Video I/O libraries, support for Firewire video cameras and video streaming libraries"
    sudo apt-get install libav-tools libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev v4l-utils v4l-conf
    
    echo "installing the Python development environment and the Python Numerical library"
    sudo apt-get install python-dev python-numpy
    
    echo "installing the parallel code processing library (the Intel tbb library)"
    sudo apt-get install libtbb-dev
    
    echo "installing the Qt dev library"
    sudo apt-get install libqt4-dev libgtk2.0-dev
    
    echo "installing other dependencies (if need be it would upgrade current version of the packages)"
    sudo apt-get install patch subversion ruby librtmp0 librtmp-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libvpx-dev libxvidcore-dev
    
    echo installing optional packages"
    sudo apt-get install libdc1394-utils libdc1394-22-dev libdc1394-22 libjpeg-dev libpng-dev libtiff-dev libjasper-dev
    

    STEP 3 (run ldconfig)

    # Open a new terminal window
    # Open /etc/ld.so.conf and check, 
    # if the paths "/usr/lib" and "/usr/local/lib" including the quote exist in the file. If not, add them manually or by
        sudo echo "/usr/local/lib" >> /etc/ld.so.conf
        sudo echo "/usr/lib" >> /etc/ld.so.conf
    # execute the following
        sudo ldconfig
    

    STEP 4

    # still ensure you haven't close the new terminal window open in STEP 3
    # execute the following
        mkdir build
        cd build
        cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_SHARED_LIBS=OFF -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
    
        make
        sudo make install
    
    # add the following to user environment variable ~/.bashrc
        export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib
        export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig
    # execute the following
        sudo ldconfig
    # start to use and enjoy opencv, it should have been install into these locations
    #   /usr/local/include/, /usr/local/share/, /usr/local/lib/
    

    STEP 5 (install v4l: Note: installing v4l-utils after opencv installation works for Ubuntu 12.04.2 & OpenCV 2.4.6.1)

    # still ensure you haven't close the new terminal window open in STEP 3
    # goto http://www.linuxtv.org/downloads/v4l-utils
    # download the latest v4l such as v4l-utils-0.9.5.tar.bz2
    # copy the downloaded file to the current terminal dir (following previous step, this should be /prepare)
    # execute the following
        tar -xvjf v4l-utils-0.9.5.tar.bz2
        cd v4l-utils-0.9.5/
        ./configure
        make
        sudo make install
        cd ..
        cd .. # (to go to )
        sudo ldconfig
    

    Worth Noting

    # To check the path where opencv & other lib files are stored, do:
    
    
    pkg-config --cflags opencv
    
        (output will come as)
        -I/usr/include/opencv
    
    
    
    pkg-config --libs opencv
    
        (output will come as)
        -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ --ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
    
    # The above paths are needed to compile your opencv programs, as given in the next illustration.
    
    # write a simple C program to test, by saving below program in a file named DisplayImage.c
    
    #include 
        #include highgui/highgui.hpp>
    
        int main(int argc, char *argv[]) {
            IplImage* img=0; /* pointer to an image */
            printf("Hello\n");
    
            if(argv[1] != 0)
                img = cvLoadImage(argv[1], 0); // 1 for color
            else
                printf("Enter filename\n");
    
            if(img != 0) {
                cvNamedWindow("Display", CV_WINDOW_AUTOSIZE); // create a window
                cvShowImage("Display", img); // show image in window
                cvWaitKey(0); // wait until user hits a key
                cvDestroyWindow("Display");
            }
            else
                printf("File not found\n");
    
            return 0;
        }
    
    # write a simple C++ program to test, by saving below program in a file named DisplayImage.cpp
    
    #include 
    #include opencv.hpp>
    #include highgui/highgui.hpp>
    
    using namespace cv;
    
    int main( int argc, char** argv )
    {
      Mat image;
      image = imread( argv[1], 1 );
    
      if( argc != 2 || !image.data )
        {
          printf( "No image data \n" );
          return -1;
        }
    
      namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
      imshow( "Display Image", image );
    
      waitKey(0);
    
      return 0;
    }
    
    # To compile & run :
    
    
    
    g++  `pkg-config --cflags --libs opencv` && ./a.out img
    
    or
    
    
    
    g++ -I/usr/include/opencv -I/usr/local/include -lopencv_core -lopencv_highgui -lopencv_ml -lopencv_imgproc -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -lopencv_nonfree  && ./a.out img
    
    where “img” is the name of any image with extension within the same folder .
    You should be able to see “Hello” and the image in a different window.
    
    If this runs, Congrats! now you can run any C/C++ program with opencv lib.
    
    
    # Now lets simplify the above big command by making a shortcut for it:
    go to your local home directory(cd /home/) and open the .bashrc file using gedit(the file will be hidden). Append the following to the file:
    
    
    
    alias gcv="g++ -I/usr/include/opencv -I/usr/local/include -lopencv_core -lopencv_highgui -lopencv_ml -lopencv_imgproc -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -lopencv_nonfree"
    
    and save. Close the terminal and open it again.(as this process requires relogin of the terminal)
    
    # Now, go to directory containing a sample program & do
    
    
    
    gcv  && ./a.out
    
    or
    
    
    
    gcv 
        ./a.out input_img.jpg
    

    As you can see the commands now become similar to $cc filename.c, $./a.out which are used normally for compiling and executing C/C++ programs.


    Some ways to check whether all lib files are installed-

    apt-cache search opencv
    

    returns:

    libcv-dev - Translation package for libcv-dev
    libcv2.3 - computer vision library - libcv* translation package
    libcvaux-dev - Translation package for libcvaux-dev
    libcvaux2.3 - computer vision library - libcvaux translation package
    libhighgui-dev - Translation package for libhighgui-dev
    libhighgui2.3 - computer vision library - libhighgui translation package
    libopencv-calib3d-dev - development files for libopencv-calib3d
    libopencv-calib3d2.3 - computer vision Camera Calibration library
    libopencv-contrib-dev - development files for libopencv-contrib
    libopencv-contrib2.3 - computer vision contrib library
    libopencv-core-dev - development files for libopencv-core
    libopencv-core2.3 - computer vision core library
    libopencv-dev - development files for opencv
    libopencv-features2d-dev - development files for libopencv-features2d
    libopencv-features2d2.3 - computer vision Feature Detection and Descriptor Extraction library
    libopencv-flann-dev - development files for libopencv-flann
    libopencv-flann2.3 - computer vision Clustering and Search in Multi-Dimensional spaces library
    libopencv-gpu-dev - development files for libopencv-gpu
    libopencv-gpu2.3 - computer vision GPU Processing library
    libopencv-highgui-dev - development files for libopencv-highgui
    libopencv-highgui2.3 - computer vision High-level GUI and Media I/O library
    libopencv-imgproc-dev - development files for libopencv-imgproc
    libopencv-imgproc2.3 - computer vision Image Processing library
    libopencv-legacy-dev - development files for libopencv-legacy
    libopencv-legacy2.3 - computer vision legacy library
    libopencv-ml-dev - development files for libopencv-ml
    libopencv-ml2.3 - computer vision Machine Learning library
    libopencv-objdetect-dev - development files for libopencv-objdetect
    libopencv-objdetect2.3 - computer vision Object Detection library
    libopencv-video-dev - development files for libopencv-video
    libopencv-video2.3 - computer vision Video analysis library
    opencv-doc - OpenCV documentation and examples
    python-opencv - Python bindings for the computer vision library
    
  • Use FFMPEG on tmp files in PHP

    12 août 2013, par Ronnie

    I am trying to use FFMPEG on some files that are in the PHP TMP directory during an upload process via $_FILES['videos']['tmp_name']

    Is this not possible with a tmp file? The command I do is

    //-- Probably something like C:\wamp\tmp\*some temp name*
    $inputFile = $_FILES['videos']['tmp_name'];
    
    //-- array("myvideo","mp4");
    $outputFile = explode(".", $_FILES['videos']['name']);
    
    //-- myvideo.jpg
    $outputFile = $outputFile[0] . ".jpg";
    
    //run ffmpeg
    $thumbnail = exec('ffmpeg -loglevel fatal -y -i ' . escapeshellarg($inputFile) . ' -f mjpeg -ss 1 -vframes 1 -s 220x124 ' . escapeshellarg($outputFile));
    

    When running this, I get nothing, no error (or thumbnail image). If I change the path names to absolute paths, the ffmpeg exec works so I know that part of it is correct. Any ideas on the tmp thing? I am guessing not possible.

  • ffmpeg rtmp streaming process exit

    12 août 2013, par Samson

    I'm using ffmpeg to capture jpeg images from an rtmp stream. Here is the command I use:

    /usr/local/bin/ffmpeg -threads 4 -i rtmp://..../chat/mp4:.mp4 
    -q:v 0.6 -r 15 -s 320x240 /frames/10021237_data/frame-%0999d.jpg
    
    ffmpeg version N-55388-g9386f33 Copyright (c) 2000-2013 the FFmpeg developers
      built on Aug  8 2013 14:07:38 with gcc 4.7 (Ubuntu/Linaro 4.7.2-2ubuntu1)
      configuration: 
      libavutil      52. 41.100 / 52. 41.100
      libavcodec     55. 24.100 / 55. 24.100
      libavformat    55. 13.102 / 55. 13.102
      libavdevice    55.  3.100 / 55.  3.100
      libavfilter     3. 82.100 /  3. 82.100
      libswscale      2.  4.100 /  2.  4.100
      libswresample   0. 17.103 /  0. 17.103
    Input #0, flv, from 'rtmp://......./mp4:10021237.mp4':
      Duration: N/A, start: 0.000000, bitrate: N/A
        Stream #0:0: Video: h264 (Main), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 1.92 tbr, 1k tbn, 40 tbc
        Stream #0:1: Audio: nellymoser, 44100 Hz, mono, flt
    [swscaler @ 0x1910000] deprecated pixel format used, make sure you did set range correctly
    Output #0, image2, to '/frames/10021237_data/frame-%0999d.jpg':
      Metadata:
        encoder         : Lavf55.13.102
        Stream #0:0: Video: mjpeg, yuvj420p, 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 90k tbn, 15 tbc
    Stream mapping:
      Stream #0:0 -> #0:0 (h264 -> mjpeg)
    Press [q] to stop, [?] for help
    

    However after a few minutes I get this line (before the process exits):

    video:5264kB audio:0kB subtitle:0 global headers:0kB muxing overhead -100.000408%
    

    What exactly is the "muxing overhead" and why is it causing a crash? Can I solve this or get it some other way (by restarting the process when it exits) ?

    EDIT:

    Actually it's not a crash. I'm running this command from a PHP CLI when a stream starts:

     $command = "/usr/local/bin/ffmpeg -i ".$rtmp." -q:v 0.6 -r 12 -s 320x240 ".__DIR__."/".$dir."/".$naming." >/dev/null 2>/dev/null &";
    shell_exec($command);
    

    but when one stops streaming all the ffmpeg processes end. Is there a way to make them independent?

    Even opening 2 terminals and running the command (with different rtmp s)in each (for different streams), killing one of them closes the other one also.

    Bottom line is: How can I make 2 ffmpeg instances independent so as killing one does not kill the other. Is this behaviour expected?

  • how to create video file with image and audio using ffmpeg library

    12 août 2013, par BlueG

    I want to merge IMAGE + AUDIO and convert them into video using FFMPEG library. I also tried with some code snippet but it's not working properly.
    Please help.

    File mf = Environment.getExternalStorageDirectory();
       String livestream = mf+"/neutral.jpg";
       String folderpth = mf+"/navya.mp3";
       //String output="/home/saicomputer/game.mp4";
       String output = new File(Environment.getExternalStorageDirectory(),"video.mp4").getAbsolutePath();
       Log.i("Test", "Let's set output to " + output);
       String cmd="ffmpeg -i "+ livestream +" -i "+ folderpth +" -acodec copy "+ output;
        Log.e("chck plzzzzz", "after "+ cmd);
       //String jaiho="ffmpeg -i image8.jpg -i file.m4a -acodec copy test.mp4";
    
       try{
        //Process p =
         Runtime.getRuntime().exec(cmd);
    
       }
       catch(Exception e)
       {
           System.out.println("exception"+e);
       }