Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Statically built FFMPEG binary segmentation fault

    12 février 2020, par stevendesu

    I want to create a custom build of FFMPEG which rips out everything except for the ability to transmux HLS videos to MP4, and I need this build to be 100% static with no external dependencies

    I tried using the following configuration:

    ./configure \
        --extra-cflags='-static -static-libstdc++ -static-libgcc' \
        --extra-cxxflags='-static -static-libstdc++ -static-libgcc' \
        --extra-ldflags='-static -static-libstdc++ -static-libgcc' \
        --pkg-config-flags='--static' \
        --enable-static \
        --disable-shared \
        --disable-runtime-cpudetect \
        --disable-autodetect \
        --disable-ffplay \
        --disable-ffprobe \
        --disable-doc \
        --disable-avdevice \
        --disable-swresample \
        --disable-swscale \
        --disable-postproc \
        --disable-pthreads \
        --disable-w32threads \
        --disable-os2threads \
        --enable-network \
        --disable-dct \
        --disable-dwt \
        --disable-error-resilience \
        --disable-lsp \
        --disable-lzo \
        --disable-mdct \
        --disable-rdft \
        --disable-fft \
        --disable-faan \
        --disable-pixelutils \
        --disable-encoders \
        --disable-decoders \
        --disable-hwaccels \
        --disable-muxers \
        --enable-muxer=mov \
        --enable-muxer=mp4 \
        --disable-demuxers \
        --enable-demuxer=hls \
        --enable-demuxer=mpegts \
        --enable-demuxer=h264 \
        --enable-demuxer=aac \
        --disable-parsers \
        --enable-parser=h264 \
        --enable-parser=aac \
        --disable-bsfs \
        --disable-protocols \
        --enable-protocol=tcp \
        --enable-protocol=tls \
        --enable-protocol=http \
        --enable-protocol=https \
        --enable-protocol=hls \
        --disable-indevs \
        --disable-outdevs \
        --disable-devices \
        --disable-filters \
        --disable-alsa \
        --disable-appkit \
        --disable-avfoundation \
        --disable-bzlib \
        --disable-coreimage \
        --disable-iconv \
        --disable-lzma \
        --enable-openssl \
        --disable-sndio \
        --disable-sdl2 \
        --disable-securetransport \
        --disable-xlib \
        --disable-zlib \
        --disable-amf \
        --disable-audiotoolbox \
        --disable-cuda-llvm \
        --disable-cuvid \
        --disable-d3d11va \
        --disable-dxva2 \
        --disable-ffnvcodec \
        --disable-nvdec \
        --disable-nvenc \
        --disable-v4l2-m2m \
        --disable-vaapi \
        --disable-vdpau \
        --disable-videotoolbox \
        --disable-debug
    

    This looked about like what I wanted:

    install prefix            /usr/local
    source path               .
    C compiler                gcc
    C library                 glibc
    ARCH                      x86 (generic)
    big-endian                no
    runtime cpu detection     no
    standalone assembly       yes
    x86 assembler             nasm
    MMX enabled               yes
    MMXEXT enabled            yes
    3DNow! enabled            yes
    3DNow! extended enabled   yes
    SSE enabled               yes
    SSSE3 enabled             yes
    AESNI enabled             yes
    AVX enabled               yes
    AVX2 enabled              yes
    AVX-512 enabled           yes
    XOP enabled               yes
    FMA3 enabled              yes
    FMA4 enabled              yes
    i686 features enabled     yes
    CMOV is fast              yes
    EBX available             yes
    EBP available             yes
    debug symbols             no
    strip symbols             yes
    optimize for size         no
    optimizations             yes
    static                    yes
    shared                    no
    postprocessing support    no
    network support           yes
    threading support         no
    safe bitstream reader     yes
    texi2html enabled         no
    perl enabled              yes
    pod2man enabled           yes
    makeinfo enabled          no
    makeinfo supports HTML    no
    
    External libraries:
    openssl
    
    External libraries providing hardware acceleration:
    
    Libraries:
    avcodec                 avfilter                avformat                avutil
    
    Programs:
    ffmpeg
    
    Enabled decoders:
    
    Enabled encoders:
    
    Enabled hwaccels:
    
    Enabled parsers:
    aac                     h264
    
    Enabled demuxers:
    aac                     h264                    hls                     mpegts
    
    Enabled muxers:
    mov                     mp4
    
    Enabled protocols:
    hls                     http                    https                   tcp                     tls
    
    Enabled filters:
    aformat                 anull                   atrim                   format                  hflip                   null                    transpose               trim                    vflip
    
    Enabled bsfs:
    null
    
    Enabled indevs:
    
    Enabled outdevs:
    
    License: LGPL version 2.1 or later
    

    It included several filters which I won't ever need or use, but these filters are pulled in automatically if you don't specify --disable-avfilter, and specifying --disable-avfilter prevents the ffmpeg binary from being produced. So I'm stuck with those.

    Using these parameters and then running make, I received a binary that was about 5.9 MB in size and looked right:

    $> ldd ffmpeg
            not a dynamic executable
    

    But when I try to run it:

    $> ./ffmpeg -version
    Segmentation fault
    

    Using valgrind to try and inspect the cause of the segmentation fault:

    $> valgrind ./ffmpeg -version
    .... lots of stuff ...
    ==61362== Jump to the invalid address stated on the next line
    ==61362==    at 0x0: ???
    ==61362==    by 0x70BB1B: ??? (in /src/FFmpeg/ffmpeg)
    ==61362==    by 0x70B2E6: ??? (in /src/FFmpeg/ffmpeg)
    ==61362==    by 0x4033F9: ??? (in /src/FFmpeg/ffmpeg)
    ==61362==    by 0x1FFF000677: ???
    ==61362==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
    ==61362==
    ==61362==
    ==61362== Process terminating with default action of signal 11 (SIGSEGV)
    ==61362==  Bad permissions for mapped region at address 0x0
    ==61362==    at 0x0: ???
    ==61362==    by 0x70BB1B: ??? (in /src/FFmpeg/ffmpeg)
    ==61362==    by 0x70B2E6: ??? (in /src/FFmpeg/ffmpeg)
    ==61362==    by 0x4033F9: ??? (in /src/FFmpeg/ffmpeg)
    ==61362==    by 0x1FFF000677: ???
    ==61362==
    ==61362== HEAP SUMMARY:
    ==61362==     in use at exit: 0 bytes in 0 blocks
    ==61362==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
    ==61362==
    ==61362== All heap blocks were freed -- no leaks are possible
    ==61362==
    ==61362== For counts of detected and suppressed errors, rerun with: -v
    ==61362== Use --track-origins=yes to see where uninitialised values come from
    ==61362== ERROR SUMMARY: 93 errors from 90 contexts (suppressed: 0 from 0)
    Segmentation fault
    

    Attempting to access memory at location 0x0 sounds like trying to follow a null pointer. But I'm not sure how to fix this.

    gdb backtrace

    When I first ran gdb ./ffmpeg gdb immediately gave me a segmentation fault and I wasn't kicked into the gdb REPL, so I couldn't investigate

    After rebuilding ffmpeg I was able to get in this time:

    $> gdb ./ffmpeg
    
    GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
    Copyright (C) 2018 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later /gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-linux-gnu".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    /www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
    /www.gnu.org/software/gdb/documentation/>.
    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from ffmpeg...done.
    (gdb) r
    Starting program: /src/FFmpeg/ffmpeg
    warning: Error disabling address space randomization: Operation not permitted
    
    Program received signal SIGSEGV, Segmentation fault.
    0x0000000000000000 in ?? ()
    (gdb) bt
    #0  0x0000000000000000 in ?? ()
    #1  0x0000000000f9a8d5 in __register_frame_info_bases.part.6 ()
    #2  0x00000000004445fd in frame_dummy ()
    #3  0x0000000000000001 in ?? ()
    #4  0x0000000000ebd20c in __libc_csu_init ()
    #5  0x0000000000ebc9d7 in __libc_start_main ()
    #6  0x000000000044451a in _start ()
    (gdb)
    

    I tried grep'ing the code base for __register_frame_info_bases and found nothing. So I'm not really sure where to go from here

    A fix, but not an explanation

    By randomly removing configuration parameters and rebuilding I discovered that --disable-pthreads was causing the segmentation fault. When I remove this, ffmpeg runs just fine

    I don't know why this is the case, though. Why would they make it possible to remove something that you need to run?

  • How to loop video with varying sizes over static image using ffmpeg, (has frame stutter issue)

    12 février 2020, par Kian Kordtomeikel

    'ffmpeg -loop 1 -i "' + Background + '" -i "' + curvideosloc + '" -filter_complex "overlay=(W-w)/2:(H-h)/2:shortest=1,format=yuv420p" "' + finalvideoloc + '"'

    The above is the command that I currently use to set a background (which is 1080p) over a video (which changes in size throughout the video to a max size of 1800 by 900), however when I do this, at most (for some reason not all) points in which the video file size changes it has a stutter where it just displays the static background then puts the video back on top and I can't figure out why. Any ideas?

    Thanks!

  • How FFmpeg CRF works

    12 février 2020, par park joh

    How FFmpeg -CRF works?

    How do they decide the best quality of this specific second?

    Will we get better results if I will split the file by seconds and encode each slice separately with -CRF and then join all the slices or would I will get the same/wors results and why?

  • ffmpeg conversion : Twitter rejects video with "Not valid video"

    12 février 2020, par DeadlyBacon

    I have an app that uploads via twitter api chunked upload, and it finally works with photos.

    However, I am trying to get it to work with videos.

    Uploading didnt work out-of-the-box even though the video format is mp4. The twitter guidelines for uploads are these

    With that in mind, I have this ffmpeg command so far:

    ffmpeg -i in.mp4  -vf \"scale=1280:720\" -b:v 5000K -minrate 5000K -maxrate 5000K -b:a 128K -r 30 -f mp4 -vcodec libx264 -profile:v high -pix_fmt yuv420p -strict -2  -ac 2 -acodec aac out.mp4
    

    I still get "Not valid video", and I don't know why.

    Here's my mediainfo output for out.mp4:

    General
    Count                                    : 328
    Count of stream of this kind             : 1
    Kind of stream                           : General
    Kind of stream                           : General
    Stream identifier                        : 0
    Count of video streams                   : 1
    Count of audio streams                   : 1
    Video_Format_List                        : AVC
    Video_Format_WithHint_List               : AVC
    Codecs Video                             : AVC
    Video_Language_List                      : English
    Audio_Format_List                        : AAC
    Audio_Format_WithHint_List               : AAC
    Audio codecs                             : AAC LC
    Audio_Language_List                      : English
    Complete name                            : video-5e4405cd4348a5e4405cd434d2.mp4
    File name                                : video-5e4405cd4348a5e4405cd434d2
    File extension                           : mp4
    Format                                   : MPEG-4
    Format                                   : MPEG-4
    Format/Extensions usually used           : mov mp4 m4v m4a m4b m4p 3ga 3gpa 3gpp 3gp 3gpp2 3g2 k3g jpm jpx mqv ismv isma ismt f4a f4b f4v
    Commercial name                          : MPEG-4
    Format profile                           : Base Media
    Internet media type                      : video/mp4
    Codec ID                                 : isom
    Codec ID                                 : isom (isom/iso2/avc1/mp41)
    Codec ID/Url                             : http://www.apple.com/quicktime/download/standalone.html
    CodecID_Compatible                       : isom/iso2/avc1/mp41
    Codec                                    : MPEG-4
    Codec                                    : MPEG-4
    Codec/Extensions usually used            : mov mp4 m4v m4a m4b m4p 3ga 3gpa 3gpp 3gp 3gpp2 3g2 k3g jpm jpx mqv ismv isma ismt f4a f4b f4v
    File size                                : 52664272
    File size                                : 50.2 MiB
    File size                                : 50 MiB
    File size                                : 50 MiB
    File size                                : 50.2 MiB
    File size                                : 50.22 MiB
    Duration                                 : 79744
    Duration                                 : 1 min 19 s
    Duration                                 : 1 min 19 s 744 ms
    Duration                                 : 1 min 19 s
    Duration                                 : 00:01:19.744
    Duration                                 : 00:01:19:20
    Duration                                 : 00:01:19.744 (00:01:19:20)
    Overall bit rate                         : 5283334
    Overall bit rate                         : 5 283 kb/s
    Frame rate                               : 30.000
    Frame rate                               : 30.000 FPS
    Frame count                              : 2390
    Stream size                              : 88780
    Stream size                              : 86.7 KiB (0%)
    Stream size                              : 87 KiB
    Stream size                              : 87 KiB
    Stream size                              : 86.7 KiB
    Stream size                              : 86.70 KiB
    Stream size                              : 86.7 KiB (0%)
    Proportion of this stream                : 0.00169
    HeaderSize                               : 40
    DataSize                                 : 52575500
    FooterSize                               : 88732
    IsStreamable                             : No
    File last modification date              : UTC 2020-02-12 14:05:37
    File last modification date (local)      : 2020-02-12 15:05:37
    Writing application                      : Lavf57.83.100
    Writing application                      : Lavf57.83.100
    
    Video
    Count                                    : 342
    Count of stream of this kind             : 1
    Kind of stream                           : Video
    Kind of stream                           : Video
    Stream identifier                        : 0
    StreamOrder                              : 0
    ID                                       : 1
    ID                                       : 1
    Format                                   : AVC
    Format/Info                              : Advanced Video Codec
    Format/Url                               : http://developers.videolan.org/x264.html
    Commercial name                          : AVC
    Format profile                           : High@L3.1
    Format settings                          : CABAC / 4 Ref Frames
    Format settings, CABAC                   : Yes
    Format settings, CABAC                   : Yes
    Format settings, ReFrames                : 4
    Format settings, ReFrames                : 4 frames
    Internet media type                      : video/H264
    Codec ID                                 : avc1
    Codec ID/Info                            : Advanced Video Coding
    Codec                                    : AVC
    Codec                                    : AVC
    Codec/Family                             : AVC
    Codec/Info                               : Advanced Video Codec
    Codec/Url                                : http://developers.videolan.org/x264.html
    Codec/CC                                 : avc1
    Codec profile                            : High@L3.1
    Codec settings                           : CABAC / 4 Ref Frames
    Codec settings, CABAC                    : Yes
    Codec_Settings_RefFrames                 : 4
    Duration                                 : 79667
    Duration                                 : 1 min 19 s
    Duration                                 : 1 min 19 s 667 ms
    Duration                                 : 1 min 19 s
    Duration                                 : 00:01:19.667
    Duration                                 : 00:01:19:20
    Duration                                 : 00:01:19.667 (00:01:19:20)
    Bit rate                                 : 5000000
    Bit rate                                 : 5 000 kb/s
    Width                                    : 1280
    Width                                    : 1 280 pixels
    Height                                   : 720
    Height                                   : 720 pixels
    Sampled_Width                            : 1280
    Sampled_Height                           : 720
    Pixel aspect ratio                       : 1.000
    Display aspect ratio                     : 1.778
    Display aspect ratio                     : 16:9
    Rotation                                 : 0.000
    Frame rate mode                          : CFR
    Frame rate mode                          : Constant
    FrameRate_Mode_Original                  : VFR
    Frame rate                               : 30.000
    Frame rate                               : 30.000 FPS
    Frame count                              : 2390
    Resolution                               : 8
    Resolution                               : 8 bits
    Colorimetry                              : 4:2:0
    Color space                              : YUV
    Chroma subsampling                       : 4:2:0
    Chroma subsampling                       : 4:2:0
    Bit depth                                : 8
    Bit depth                                : 8 bits
    Scan type                                : Progressive
    Scan type                                : Progressive
    Interlacement                            : PPF
    Interlacement                            : Progressive
    Bits/(Pixel*Frame)                       : 0.181
    Stream size                              : 51297022
    Stream size                              : 48.9 MiB (97%)
    Stream size                              : 49 MiB
    Stream size                              : 49 MiB
    Stream size                              : 48.9 MiB
    Stream size                              : 48.92 MiB
    Stream size                              : 48.9 MiB (97%)
    Proportion of this stream                : 0.97404
    Writing library                          : x264 - core 152 r2854 e9a5903
    Writing library                          : x264 core 152 r2854 e9a5903
    Encoded_Library_Name                     : x264
    Encoded_Library_Version                  : core 152 r2854 e9a5903
    Encoding settings                        : cabac=1 / ref=3 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=12 / lookahead_threads=2 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=abr / mbtree=1 / bitrate=5000 / ratetol=1.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
    Language                                 : en
    Language                                 : English
    Language                                 : English
    Language                                 : en
    Language                                 : eng
    Language                                 : en
    
    Audio
    Count                                    : 275
    Count of stream of this kind             : 1
    Kind of stream                           : Audio
    Kind of stream                           : Audio
    Stream identifier                        : 0
    StreamOrder                              : 1
    ID                                       : 2
    ID                                       : 2
    Format                                   : AAC
    Format/Info                              : Advanced Audio Codec
    Commercial name                          : AAC
    Format profile                           : LC
    Format settings, SBR                     : No (Explicit)
    Format settings, SBR                     : No (Explicit)
    Codec ID                                 : mp4a-40-2
    Codec                                    : AAC LC
    Codec                                    : AAC LC
    Codec/Family                             : AAC
    Codec/CC                                 : 40
    Duration                                 : 79744
    Duration                                 : 1 min 19 s
    Duration                                 : 1 min 19 s 744 ms
    Duration                                 : 1 min 19 s
    Duration                                 : 00:01:19.744
    Duration                                 : 00:01:19:25
    Duration                                 : 00:01:19.744 (00:01:19:25)
    Bit rate mode                            : CBR
    Bit rate mode                            : Constant
    Bit rate                                 : 128257
    Bit rate                                 : 128 kb/s
    Channel(s)                               : 2
    Channel(s)                               : 2 channels
    Channel positions                        : Front: L R
    Channel positions                        : 2/0/0
    ChannelLayout                            : L R
    Samples per frame                        : 1024
    Sampling rate                            : 48000
    Sampling rate                            : 48.0 kHz
    Samples count                            : 3827712
    Frame rate                               : 46.875
    Frame rate                               : 46.875 FPS (1024 SPF)
    Frame count                              : 3738
    Compression mode                         : Lossy
    Compression mode                         : Lossy
    Stream size                              : 1278470
    Stream size                              : 1.22 MiB (2%)
    Stream size                              : 1 MiB
    Stream size                              : 1.2 MiB
    Stream size                              : 1.22 MiB
    Stream size                              : 1.219 MiB
    Stream size                              : 1.22 MiB (2%)
    Proportion of this stream                : 0.02428
    Language                                 : en
    Language                                 : English
    Language                                 : English
    Language                                 : en
    Language                                 : eng
    Language                                 : en
    Default                                  : Yes
    Default                                  : Yes
    Alternate group                          : 1
    Alternate group                          : 1
    
    
    
    

    Edit: Guess Ill add my PHP code too (This is chopped in a sensible manner because the actual file is very large):

    
    
    // Set up Codebird
    \Codebird\Codebird::setConsumerKey($consumer_key, $consumer_secret); // static, see README
    
    $cb = \Codebird\Codebird::getInstance();
    
    $cb->setToken($token, $token_secret);
    $cb->setTimeout(60 * 1000); // 60 second request timeout
    
      $video = new Video($path);
    
        // Convert to the parameter required by twitter.
        $converted = $video->convert();
    
        $path = realpath('videos/' . $converted);
    
        $file = fopen($path, 'rb');
    
        $size = fstat($file)['size'];
        $mime_type = mime_content_type($path);
    
        $media = $cb->media_upload([
          'command' => 'INIT',
          'media_type' => $mime_type,
        'media_category' => 'tweet_video',
          'total_bytes' => $size,
        ]);
    
    $success = $media->httpstatus >= 200 && $media->httpstatus < 300; # 2xx
    
      if (!$success) {
        throw new TwitterException("Failed to INIT upload for $path...");
      }
    
    
      // APPEND chunks to upload.
      $mediaId = $media->media_id_string;
      $segmentId = 0;
    
      while (!feof($file)) {
        echo "chunk #$segmentId....";
    
        $chunk = fread($file, 512 * 1024); // caps out at 512 MB
    
        echo "chunk size: ". strlen($chunk);
    
        $media = $cb->media_upload([
          'command' => 'APPEND',
          'media_id' => $mediaId,
          'segment_index' => $segmentId,
          'media' => $chunk,
        ]);
    
        $success = $media->httpstatus >= 200 && $media->httpstatus < 300; # 2xx
    
        if (!$success) {
          throw new TwitterException("Failed to APPEND to upload for $path, chunk $segmentId...");
        }
    
        $segmentId++;
      }
      // Close file and FINALIZE upload.
      fclose($file);
    
    echo "FINALIZING id $mediaId...";
      $media = $cb->media_upload([
          'command' => 'FINALIZE',
          'media_id' => $mediaId,
      ]);
    
      $success = $media->httpstatus >= 200 && $media->httpstatus < 300; # 2xx
    
      if (!$success) {
        var_dump($media);
        throw new TwitterException("Failed to FINALIZE upload for $path...");
      }
    
      return $mediaId;
    

    Video is my ffmpeg class, which I'll paste below, and $path is a URL leading to a perfectly valid mp4 video.

    Video.php:

    <?php
    
    class VideoConversionException extends \Exception {}
    
    class Video {
      public $name;
      public $converted;
    
    
      public function __construct($name) {
        self::clear();
    
        $this->name = $name;
      }
    
    
      public function convert() {
        $tmpVideo = 'video-' . uniqid() . uniqid() . '.mp4';
        $videoPath = 'videos/' . $tmpVideo;
    
        //$ffmpeg = "ffmpeg -i https://tvcanarias.acfipress.com/BC_190907_gc_teror.mp4  -vf "scale=1280:720" -b:v 5000K -b:a 128K -r 30 -f mp4 -vcodec libx264 -acodec aac output_video.mp4";
        $ffmpeg = "ffmpeg -i {$this->name}  -vf \"scale=1280:720\" -b:v 5000K -minrate 5000K -maxrate 5000K -b:a 128K -r 30 -f mp4 -vcodec libx264 -profile:v high -pix_fmt yuv420p -strict -2  -ac 2 -acodec aac $videoPath";
        //$ffmpeg = "ffmpeg -i {$this->name} -pix_fmt yuv420p -vcodec libx264 -vf scale=640:-1 -acodec aac -vb 1024k -minrate 1024k -maxrate 1024k -bufsize 1024k -ar 44100  -ac 2  -strict experimental -r 30 $videoPath";
        $output = [];
        exec($ffmpeg, $output, $status);
    
        if ($status != 0) {
          //die("Couldnt run ffmpeg. (Error code: #$status)");
          throw new VideoConversionException("Couldn't run ffmpeg. (Error code: #$status)");
        }
    
        $this->converted = $tmpVideo;
        return $tmpVideo;
      }
    
      public function shredConverted() {
        // delete video.
        @unlink("videos/{$this->$converted}");
      }
    
      public static function clear() {
        // We can't really shred videos right away as they might be still uploading.
        // Therefore, every time this library is used, we will just delete videos older
        // than, say, an hour.
    
        $files = scandir('videos');
    
        $curtime = time();
    
        foreach ($files as $file) {
          if ($file == '.gitignore' || $file == '.' || $file == '..') {
            continue;
          }
    
          $mtime = filemtime("videos/$file");
    
          $diff = $curtime - $mtime;
          $overAnHour = $diff > (60 * 60);
    
          if ($overAnHour) {
            @unlink("videos/$file");
          }
        }
      }
    }
    
    
  • Use audio stream overs ssh with ffmpeg on web page

    12 février 2020, par Mauricio

    I need to broadcast the audio stream (WiFi camera at my home) on the website hosted on a VPS.

    Here is the command executed from my home:

    ffmpeg -i "rtsp://172.16.0.201:554/user=admin&password=root&channel=1&stream=1.sdp" -bufsize 24k -vn -acodec copy -f mpegts - | ssh -p 22222 root@mydomain.org 'ffmpeg -i - -vn -acodec libvorbis -ac 1 -ar 8000 -ab 64k -f mpegts "rtsp://127.0.0.1:53350/live.sdp"'
    

    It seems to work because I get

    ffmpeg version n4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
      built with gcc 9.2.0 (GCC)
      configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
      libavutil      56. 31.100 / 56. 31.100
      libavcodec     58. 54.100 / 58. 54.100
      libavformat    58. 29.100 / 58. 29.100
      libavdevice    58.  8.100 / 58.  8.100
      libavfilter     7. 57.100 /  7. 57.100
      libswscale      5.  5.100 /  5.  5.100
      libswresample   3.  5.100 /  3.  5.100
      libpostproc    55.  5.100 / 55.  5.100
    ffmpeg version 4.1.4-1~deb10u1 Copyright (c) 2000-2019 the FFmpeg developers
      built with gcc 8 (Debian 8.3.0-6)
      configuration: --prefix=/usr --extra-version='1~deb10u1' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
      libavutil      56. 22.100 / 56. 22.100
      libavcodec     58. 35.100 / 58. 35.100
      libavformat    58. 20.100 / 58. 20.100
      libavdevice    58.  5.100 / 58.  5.100
      libavfilter     7. 40.101 /  7. 40.101
      libavresample   4.  0.  0 /  4.  0.  0
      libswscale      5.  3.100 /  5.  3.100
      libswresample   3.  3.100 /  3.  3.100
      libpostproc    55.  3.100 / 55.  3.100
    Guessed Channel Layout for Input Stream #0.1 : mono
    Input #0, rtsp, from 'rtsp://172.16.0.201:554/user=admin&password=root&channel=1&stream=1.sdp':
      Metadata:
        title           : RTSP Session
      Duration: N/A, start: 0.000000, bitrate: N/A
        Stream #0:0: Video: h264 (Main), yuv420p(progressive), 640x360, 12 fps, 12 tbr, 90k tbn, 24 tbc
        Stream #0:1: Audio: pcm_alaw, 8000 Hz, mono, s16, 64 kb/s
    [mpegts @ 0x5582b6b14c40] frame size not set
    Output #0, mpegts, to 'pipe:':
      Metadata:
        title           : RTSP Session
        encoder         : Lavf58.29.100
        Stream #0:0: Audio: pcm_alaw, 8000 Hz, mono, s16, 64 kb/s
    Stream mapping:
      Stream #0:1 -> #0:0 (copy)
    Press [q] to stop, [?] for help
    size=     146kB time=00:00:17.06 bitrate=  70.0kbits/s speed=1.16x
    

    But when I look on the VPS I don't see the port open with netstat.

    Yet the process seems to be running

    root     21801  0.2  2.1 265916 42188 ?        SLs  15:03   0:00 ffmpeg -i - -vn -acodec libvorbis -ac 1 -ar 8000 -ab 64k -f mpegts rtsp://127.0.0.1:53350/live.sdp
    

    I thought I would access the feed with a simple html page with this kind of code

    
    

    iptables

    Chain INPUT (policy DROP)
    ....
    ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:53350
    ACCEPT     udp  --  anywhere             anywhere             udp dpt:53350
    ....
    Chain FORWARD (policy DROP)
    ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:53350
    ACCEPT     udp  --  anywhere             anywhere             udp dpt:53350
    ....
    Chain OUTPUT (policy DROP)
    ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:53350
    ACCEPT     udp  --  anywhere             anywhere             udp dpt:53350
    ....