Recherche avancée

Médias (91)

Sur d’autres sites (139)

  • FFmpeg (Thumbnail from video) works in command line, but not in PHP script

    2 mars 2017, par Jun Kim

    I looked at the similar questions, and the solutions there do not work in my case. Anyone has any idea ? I am trying to capture a thumbnail from a given video file.

    Later, my goal is to capture a thumbnail from live streaming video file.

    Below is my current set up.

    Linux Ubuntu 16.04

    PHP version 7.0

    Nginx Version 1.10.3

    FFmpeg Version FFmpeg 2.8.11

    I installed FFmpeg through below commands in my Ubuntu server.

    apt-get update
    apt-get install ffmpeg

    When I type the below command line in the terminal, it does the conversion fine.

    ffmpeg -i /etc/nginx/html/test.mp4 -ss 00:00:01 -vframes 1 -vf scale=240:120 /etc/nginx/html/Share/ffmpeg/thumbnails/test.png;

    In order to use it in php file, I confirmed the location of ffmpeg binaries by I typing in the terminal, which ffmpeg, and it returns /usr/bin/ffmpeg

    I also gave permission to the directory by using chmod 755 command line.

    Here is what I have in my ffmpeg.php file.
    I included the full path to my ffmpeg as you can see.

    <?php
    header("Content-Type: text/html;charset=UTF-8");

    $ffmpeg = "/usr/bin/ffmpeg";
    $videoFile="/etc/nginx/html/test.mp4";
    $thumbnail= "/etc/nginx/html/Share/ffmpeg/thumbnails/thumbnail1.jpg";

    $cmd = "$ffmpeg -i $videoFile -ss 00:00:01 -vframes 1 -vf scale=240:120 $thumbnail 2>&1 &";

    $output = shell_exec($cmd);
    echo "<pre>".$output."</pre>";
    ?>

    This returns the message like below.

    ffmpeg version 2.8.11-0ubuntu0.16.04.1 Copyright (c) 2000-2017 the FFmpeg developers
     built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
     configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv
     libavutil      54. 31.100 / 54. 31.100
     libavcodec     56. 60.100 / 56. 60.100
     libavformat    56. 40.101 / 56. 40.101
     libavdevice    56.  4.100 / 56.  4.100
     libavfilter     5. 40.101 /  5. 40.101
     libavresample   2.  1.  0 /  2.  1.  0
     libswscale      3.  1.101 /  3.  1.101
     libswresample   1.  2.101 /  1.  2.101
     libpostproc    53.  3.100 / 53.  3.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/etc/nginx/html/Share/test.mp4':
     Metadata:
       major_brand     : isom
       minor_version   : 512
       compatible_brands: isomiso2mp41
       creation_time   : 1970-01-01 00:00:00
       encoder         : Lavf53.24.2
     Duration: 00:00:06.40, start: 0.000000, bitrate: 1321 kb/s
       Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 640x368 [SAR 1:1 DAR 40:23], 932 kb/s, 25 fps, 25 tbr, 12800 tbn, 25 tbc (default)
       Metadata:
         creation_time   : 1970-01-01 00:00:00
         handler_name    : VideoHandler
       Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 383 kb/s (default)
       Metadata:
         creation_time   : 1970-01-01 00:00:00
         handler_name    : SoundHandler
    [swscaler @ 0x1621be0] deprecated pixel format used, make sure you did set range correctly
    Output #0, image2, to '/etc/nginx/html/Share/ffmpeg/thumbnails/thumbnail1.jpg':
     Metadata:
       major_brand     : isom
       minor_version   : 512
       compatible_brands: isomiso2mp41
       encoder         : Lavf56.40.101
       Stream #0:0(und): Video: mjpeg, yuvj420p(pc), 240x120 [SAR 20:23 DAR 40:23], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc (default)
       Metadata:
         creation_time   : 1970-01-01 00:00:00
         handler_name    : VideoHandler
         encoder         : Lavc56.60.100 mjpeg
    Stream mapping:
     Stream #0:0 -> #0:0 (mpeg4 (native) -> mjpeg (native))
    Press [q] to stop, [?] for help
    [image2 @ 0x16165a0] Could not open file : /etc/nginx/html/Share/ffmpeg/thumbnails/thumbnail1.jpg
    av_interleaved_write_frame(): Input/output error
    frame=    1 fps=0.0 q=3.9 Lsize=N/A time=00:00:00.04 bitrate=N/A    
    video:8kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
    Conversion failed!

    UPDATED : I also gave permission to ffmpeg by chmod +x $(which ffmpeg)

    I tried php /etc/nginx/html/Share/ffmpeg/ffmpeg.php in the terminal, and it also does conversion fine.

     libavutil      54. 31.100 / 54. 31.100
     libavcodec     56. 60.100 / 56. 60.100
     libavformat    56. 40.101 / 56. 40.101
     libavdevice    56.  4.100 / 56.  4.100
     libavfilter     5. 40.101 /  5. 40.101
     libavresample   2.  1.  0 /  2.  1.  0
     libswscale      3.  1.101 /  3.  1.101
     libswresample   1.  2.101 /  1.  2.101
     libpostproc    53.  3.100 / 53.  3.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/etc/nginx/html/Share/test.mp4':
     Metadata:
       major_brand     : isom
       minor_version   : 512
       compatible_brands: isomiso2mp41
       creation_time   : 1970-01-01 00:00:00
       encoder         : Lavf53.24.2
     Duration: 00:00:06.40, start: 0.000000, bitrate: 1321 kb/s
       Stream #0:0(und): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 640x368 [SAR 1:1 DAR 40:23], 932 kb/s, 25 fps, 25 tbr, 12800 tbn, 25 tbc (default)
       Metadata:
         creation_time   : 1970-01-01 00:00:00
         handler_name    : VideoHandler
       Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 383 kb/s (default)
       Metadata:
         creation_time   : 1970-01-01 00:00:00
         handler_name    : SoundHandler
    [swscaler @ 0x72dbe0] deprecated pixel format used, make sure you did set range correctly
    Output #0, image2, to '/etc/nginx/html/Share/ffmpeg/thumbnails/thumbnail.jpg':
     Metadata:
       major_brand     : isom
       minor_version   : 512
       compatible_brands: isomiso2mp41
       encoder         : Lavf56.40.101
       Stream #0:0(und): Video: mjpeg, yuvj420p(pc), 240x120 [SAR 20:23 DAR 40:23], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc (default)
       Metadata:
         creation_time   : 1970-01-01 00:00:00
         handler_name    : VideoHandler
         encoder         : Lavc56.60.100 mjpeg
    Stream mapping:
     Stream #0:0 -> #0:0 (mpeg4 (native) -> mjpeg (native))
    Press [q] to stop, [?] for help
    frame=    1 fps=0.0 q=3.9 Lsize=N/A time=00:00:00.04 bitrate=N/A    
    video:8kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
  • ffmpeg : Combine/merge multiple mp4 videos not working, output only contains the first video

    22 janvier 2017, par dtbaker

    Here is the command I am using to combine multiple videos :

    ffmpeg -i 75_540_38HQ2.mp4 -i 76_70_20.mp4 -i 76_173_80.mp4 -i 81_186_35.mp4 -vcodec copy -acodec copy Mux1.mp4

    The resulting Mux1.mp4 does not contain all videos. Only the first video (75_540_38HQ2.mp4). The file size of the source and resulting video is below (as you can see, resulting video is slightly larger than first vid) :

    $ ls -lh
    
    - rw-r—r— 1 dbaker dbaker 42M 2011-03-24 11:59 75_540_38HQ2.mp4
    - rw-r—r— 1 dbaker dbaker 236M 2011-03-24 12:09 76_173_80.mp4
    - rw-r—r— 1 dbaker dbaker 26M 2011-03-24 12:05 76_70_20.mp4
    - rw-r—r— 1 dbaker dbaker 54M 2011-03-24 12:15 81_186_35.mp4
    - rw-r—r— 1 dbaker dbaker 44M 2011-03-24 14:48 Mux1.mp4

    Here is the output of the ffmpeg command. To me it looks ok, showing the multiple source inputs and the single output.

    FFmpeg version SVN-r26402, Copyright (c) 2000-2011 the FFmpeg developers
      built on Mar 21 2011 18:05:32 with gcc 4.4.5
      configuration : —enable-gpl —enable-version3 —enable-nonfree —enable-postproc —enable-libfaac —enable-libmp3lame —enable-libopencore-amrnb —enable-libopencore-amrwb —enable-libtheora —enable-libvorbis —enable-libvpx —enable-libx264 —enable-libxvid —enable-x11grab
      libavutil     50.36. 0 / 50.36. 0
      libavcore      0.16. 1 /  0.16. 1
      libavcodec    52.108. 0 / 52.108. 0
      libavformat   52.93. 0 / 52.93. 0
      libavdevice   52. 2. 3 / 52. 2. 3
      libavfilter    1.74. 0 /  1.74. 0
      libswscale     0.12. 0 /  0.12. 0
      libpostproc   51. 2. 0 / 51. 2. 0
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from ’75_540_38HQ2.mp4’ :
      Metadata :
        major_brand : isom
        minor_version : 512
        compatible_brands : isomiso2avc1mp41
        creation_time : 1970-01-01 00:00:00
        encoder : Lavf52.93.0
      Duration : 00:00:29.99, start : 0.000000, bitrate : 11517 kb/s
        Stream #0.0(eng) : Video : h264, yuv420p, 1280x960 [PAR 1:1 DAR 4:3], 11575 kb/s, 29.94 fps, 29.97 tbr, 30k tbn, 59.94 tbc
        Metadata :
          creation_time : 1970-01-01 00:00:00
        Stream #0.1(eng) : Audio : aac, 48000 Hz, stereo, s16, 127 kb/s
        Metadata :
          creation_time : 1970-01-01 00:00:00
    Input #1, mov,mp4,m4a,3gp,3g2,mj2, from ’76_70_20.mp4’ :
      Metadata :
        major_brand : isom
        minor_version : 512
        compatible_brands : isomiso2avc1mp41
        creation_time : 1970-01-01 00:00:00
        encoder : Lavf52.93.0
      Duration : 00:00:19.98, start : 0.000000, bitrate : 10901 kb/s
        Stream #1.0(eng) : Video : h264, yuv420p, 1280x960 [PAR 1:1 DAR 4:3], 10804 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc
        Metadata :
          creation_time : 1970-01-01 00:00:00
        Stream #1.1(eng) : Audio : aac, 48000 Hz, stereo, s16, 128 kb/s
        Metadata :
          creation_time : 1970-01-01 00:00:00
    Input #2, mov,mp4,m4a,3gp,3g2,mj2, from ’76_173_80.mp4’ :
      Metadata :
        major_brand : isom
        minor_version : 512
        compatible_brands : isomiso2avc1mp41
        creation_time : 1970-01-01 00:00:00
        encoder : Lavf52.93.0
      Duration : 00:03:09.99, start : 0.000000, bitrate : 10393 kb/s
        Stream #2.0(eng) : Video : h264, yuv420p, 1280x960 [PAR 1:1 DAR 4:3], 10321 kb/s, 29.96 fps, 29.97 tbr, 30k tbn, 59.94 tbc
        Metadata :
          creation_time : 1970-01-01 00:00:00
        Stream #2.1(eng) : Audio : aac, 48000 Hz, stereo, s16, 128 kb/s
        Metadata :
          creation_time : 1970-01-01 00:00:00
    

    Seems stream 0 codec frame rate differs from container frame rate : 119.88 (120000/1001) -> 30000.00 (30000/1)
    Input #3, mov,mp4,m4a,3gp,3g2,mj2, from ’81_186_35.mp4’ :
    Metadata :
    major_brand : isom
    minor_version : 512
    compatible_brands : isomiso2avc1mp41
    creation_time : 1970-01-01 00:00:00
    encoder : Lavf52.93.0
    Duration : 00:00:35.00, start : 0.000000, bitrate : 12700 kb/s
    Stream #3.0(eng) : Video : h264, yuv420p, 1280x720 [PAR 1:1 DAR 16:9], 12620 kb/s, 59.91 fps, 30k tbr, 60k tbn, 119.88 tbc
    Metadata :
    creation_time : 1970-01-01 00:00:00
    Stream #3.1(eng) : Audio : aac, 48000 Hz, stereo, s16, 128 kb/s
    Metadata :
    creation_time : 1970-01-01 00:00:00
    Output #0, mp4, to ’Mux1.mp4’ :
    Metadata :
    major_brand : isom
    minor_version : 512
    compatible_brands : isomiso2avc1mp41
    creation_time : 1970-01-01 00:00:00
    encoder : Lavf52.93.0
    Stream #0.0(eng) : Video : libx264, yuv420p, 1280x960 [PAR 1:1 DAR 4:3], q=2-31, 11575 kb/s, 30k tbn, 29.97 tbc
    Metadata :
    creation_time : 1970-01-01 00:00:00
    Stream #0.1(eng) : Audio : libfaac, 48000 Hz, stereo, 128 kb/s
    Metadata :
    creation_time : 1970-01-01 00:00:00
    Stream mapping :
    Stream #0.0 -> #0.0
    Stream #2.1 -> #0.1
    Press [q] to stop encoding
    frame= 883 fps=632 q=-1.0 Lsize= 44730kB time=29.40 bitrate=12465.1kbits/s
    video:41678kB audio:2969kB global headers:0kB muxing overhead 0.184548%

    Am I doing something blindingly stupid here ?

    The source videos came from a video camera, and are small snippets taken with ffmpeg -i bigfile.mp4 -ss 20 -t 10 -vcodec copy etc..

    Thanks heaps !!
    Dave


    Edit : couldn’t solve it so I just use avidemux GUI tool. It seemed to append the MP4’s just fine.

    Must be a problem with MP4’s or just the ones that come off a gopro camera.

  • Add watermark to video using ffmpeg in php not working

    13 juillet 2017, par Remya

    I need to watermark a mp4 video , Currently i am using this code, but it is not working , please solve this

    &lt;?php $msg = exec('/usr/local/bin/ffmpeg -i uploads/videos/profile/movie.mp4 -vf "movie=logo.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:10 [out]" uploads/videos/profile/output.mp4 2>&amp;1', $output); var_dump($output);?>

    The error shows

    array (size=27)  0 => string 'FFmpeg version SVN-r26402, Copyright (c) 2000-2011 the FFmpeg developers' (length=72)  1 => string '  built on Jan 14 2016 22:33:21 with gcc 4.4.7 20120313 (Red Hat 4.4.7-16)' (length=74)  2 => string '  configuration: --enable-libmp3lame --enable-libvorbis --disable-mmx --enable-shared --enable-libx264 --enable-libtheora --enable-libfaac --enable-avfilter --enable-gpl --enable-nonfree --enable-x11grab --enable-libxvid' (length=220)  3 => string '  libavutil     50.36. 0 / 50.36. 0' (length=35)  4 => string ' libavcore      0.16. 1 /  0.16. 1' (length=35)  5 => string '  libavcodec    52.108. 0 / 52.108. 0' (length=37)  6 => string '  libavformat   52.93. 0 / 52.93. 0' (length=35)  7 => string '  libavdevice   52. 2. 3 / 52. 2. 3' (length=35)  8 => string '  libavfilter    1.74. 0 /  1.74. 0' (length=35)  9 => string '  libswscale     0.12. 0 /  0.12. 0' (length=35)  10 => string 'Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'uploads/videos/profile/movie.mp4':' (length=75)  11 => string '  Metadata:' (length=11)  12 => string '   major_brand     : isom' (length=26)  13 => string '    minor_version   : 512' (length=25)  14 => string '    compatible_brands: isomiso2avc1mp41' (length=39)  15 => string '    creation_time   : 1970-01-01 00:00:00' (length=41)  16 => tring '    encoder         : Lavf53.24.2' (length=33)  17 => string '  Duration: 00:00:05.31, start: 0.000000, bitrate: 1589 kb/s' (length=60)  18 => string '    Stream #0.0(und): Video: h264, yuv420p, 1280x720 [PAR 1:1 DAR 16:9], 1205 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc' (length=117)  19 => string '    Metadata:' (length=13)  20 => string '      creation_time   : 1970-01-01 00:00:00' (length=43)  21 => string '    Stream #0.1(und): Audio: aac, 48000 Hz, 5.1, s16, 384 kb/s' (length=62)  22 => string '    Metadata:' (length=13)  23 => string '      creation_time   : 1970-01-01 00:00:00' (length=43)  24 => string '[buffer @ 0x1e95f70] w:1280 h:720 pixfmt:yuv420p' (length=48)  25 => string 'No such filter: 'movie'' (length=23)  26 => string 'Error opening filters!' (length=22)