Recherche avancée

Médias (0)

Mot : - Tags -/content

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (12)

  • Emballe médias : à quoi cela sert ?

    4 février 2011, par

    Ce plugin vise à gérer des sites de mise en ligne de documents de tous types.
    Il crée des "médias", à savoir : un "média" est un article au sens SPIP créé automatiquement lors du téléversement d’un document qu’il soit audio, vidéo, image ou textuel ; un seul document ne peut être lié à un article dit "média" ;

  • Contribute to a better visual interface

    13 avril 2011

    MediaSPIP is based on a system of themes and templates. Templates define the placement of information on the page, and can be adapted to a wide range of uses. Themes define the overall graphic appearance of the site.
    Anyone can submit a new graphic theme or template and make it available to the MediaSPIP community.

  • Support audio et vidéo HTML5

    10 avril 2011

    MediaSPIP utilise les balises HTML5 video et audio pour la lecture de documents multimedia en profitant des dernières innovations du W3C supportées par les navigateurs modernes.
    Pour les navigateurs plus anciens, le lecteur flash Flowplayer est utilisé.
    Le lecteur HTML5 utilisé a été spécifiquement créé pour MediaSPIP : il est complètement modifiable graphiquement pour correspondre à un thème choisi.
    Ces technologies permettent de distribuer vidéo et son à la fois sur des ordinateurs conventionnels (...)

Sur d’autres sites (3549)

  • Reading in pydub AudioSegment from url. BytesIO returning "OSError [Errno 2] No such file or directory" on heroku only ; fine on localhost

    24 octobre 2014, par Mark

    EDIT 1 for anyone with the same error : installing ffmpeg did indeed solve that BytesIO error

    EDIT 1 for anyone still willing to help : my problem is now that when I AudioSegment.export("filename.mp3", format="mp3"), the file is made, but has size 0 bytes — details below (as "EDIT 1")


    EDIT 2 : All problems now solved.

    • Files can be read in as AudioSegment using BytesIO
    • I found buildpacks to ensure ffmpeg was installed correctly on my app, with lame support for exporting proper mp3 files

    Answer below


    Original question

    I have pydub working nicely locally to crop a particular mp3 file based on parameters in the url.
    (?start_time=3.8&end_time=5.1)

    When I run foreman start it all looks good on localhost. The html renders nicely.
    The key lines from the views.py include reading in a file from a url using

    url = "https://s3.amazonaws.com/shareducate02/The_giving_tree__by_Alex_Blumberg__sponsored_by_mailchimp-short.mp3"
    mp3 = urllib.urlopen(url).read() # inspired by http://nbviewer.ipython.org/github/ipython-books/cookbook-code/blob/master/notebooks/chapter11_image/06_speech.ipynb
    original=AudioSegment.from_mp3(BytesIO(mp3))  # AudioSegment.from_mp3 is a pydub command, see http://pydub.com
    section = original[start_time_ms:end_time_ms]

    That all works great... until I push to heroku (django app) and run it online.
    then when I load the same page now on the herokuapp.com, I get this error

    OSError at /path/to/page
    [Errno 2] No such file or directory
    Request Method: GET
    Request URL:    http://my.website.com/path/to/page?start_time=3.8&end_time=5
    Django Version: 1.6.5
    Exception Type: OSError
    Exception Value:    
    [Errno 2] No such file or directory
    Exception Location: /app/.heroku/python/lib/python2.7/subprocess.py in _execute_child, line 1327
    Python Executable:  /app/.heroku/python/bin/python
    Python Version: 2.7.8
    Python Path:    
    ['/app',
    '/app/.heroku/python/bin',
    '/app/.heroku/python/lib/python2.7/site-packages/setuptools-5.4.1-py2.7.egg',
    '/app/.heroku/python/lib/python2.7/site-packages/distribute-0.6.36-py2.7.egg',
    '/app/.heroku/python/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg',
    '/app',
    '/app/.heroku/python/lib/python27.zip',
    '/app/.heroku/python/lib/python2.7',
    '/app/.heroku/python/lib/python2.7/plat-linux2',
    '/app/.heroku/python/lib/python2.7/lib-tk',
    '/app/.heroku/python/lib/python2.7/lib-old',
    '/app/.heroku/python/lib/python2.7/lib-dynload',
    '/app/.heroku/python/lib/python2.7/site-packages',
    '/app/.heroku/python/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']


    Traceback:
    File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
     112.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "/app/evernote/views.py" in finalize
     105.       original=AudioSegment.from_mp3(BytesIO(mp3))
    File "/app/.heroku/python/lib/python2.7/site-packages/pydub/audio_segment.py" in from_mp3
     318.         return cls.from_file(file, 'mp3')
    File "/app/.heroku/python/lib/python2.7/site-packages/pydub/audio_segment.py" in from_file
     302.         retcode = subprocess.call(convertion_command, stderr=open(os.devnull))
    File "/app/.heroku/python/lib/python2.7/subprocess.py" in call
     522.     return Popen(*popenargs, **kwargs).wait()
    File "/app/.heroku/python/lib/python2.7/subprocess.py" in __init__
     710.                                 errread, errwrite)
    File "/app/.heroku/python/lib/python2.7/subprocess.py" in _execute_child
     1327.                 raise child_exception

    I have commented out some of the original to convince myself that sure enough the single line original=AudioSegment.from_mp3(BytesIO(mp3)) is where the problem kicks in... but this is not a problem locally

    The full function in views.py starts like this :

    from django.shortcuts import render, get_object_or_404
    from django.http import HttpResponseRedirect #, Http404, HttpResponse
    from django.core.urlresolvers import reverse
    from django.views import generic
    import pydub
    # Maybe only need:
    from pydub import AudioSegment # == see below
    from time import gmtime, strftime

    import boto
    from boto.s3.connection import S3Connection
    from boto.s3.key import Key

    # http://nbviewer.ipython.org/github/ipython-books/cookbook-code/blob/master/notebooks/chapter11_image/06_speech.ipynb
    import urllib
    from io import BytesIO
    # import numpy as np
    # import scipy.signal as sg
    # import pydub # mentioned above already
    # import matplotlib.pyplot as plt
    # from IPython.display import Audio, display
    # import matplotlib as mpl
    # %matplotlib inline

    import os
    # from settings import AWS_ACCESS_KEY, AWS_SECRET_KEY, AWS_BUCKET_NAME
    AWS_ACCESS_KEY = os.environ.get('AWS_ACCESS_KEY') # there must be a better way?
    AWS_SECRET_KEY = os.environ.get('AWS_SECRET_KEY')
    AWS_BUCKET_NAME = os.environ.get('S3_BUCKET_NAME')

    # http://stackoverflow.com/questions/415511/how-to-get-current-time-in-python

    boto_conn = S3Connection(AWS_ACCESS_KEY, AWS_SECRET_KEY)
    bucket = boto_conn.get_bucket(AWS_BUCKET_NAME)
    s3_url_format = 'https://s3.amazonaws.com/shareducate02/{end_path}'

    and specifically the view in views.py that’s called when I visit the page :

    def finalize(request):

       start_time = request.GET.get('start_time')

       end_time = request.GET.get('end_time')

       original_file = "https://s3.amazonaws.com/shareducate02/The_giving_tree__by_Alex_Blumberg__sponsored_by_mailchimp-short.mp3"


       if start_time:

         # original=AudioSegment.from_mp3(original_file)  #...that didn't work
         # but this works below:

         # next three uncommented lines from http://nbviewer.ipython.org/github/ipython-books/cookbook-code/blob/master/notebooks/chapter11_image/06_speech.ipynb
         # python 2.x
         url = original_file
         # req = urllib.Request(url, headers={'User-Agent': ''}) # Note: I commented out this because I got error that "Request" did not exist
         mp3 = urllib.urlopen(url).read()
         # That's for my 2.7

         # If I ever upgrade to python 3.x, would need to change it to:
         # req = urllib.request.Request(url, headers={'User-Agent': ''})
         # mp3 = urllib.request.urlopen(req).read()
         # as per instructions on http://nbviewer.ipython.org/github/ipython-books/cookbook-code/blob/master/notebooks/chapter11_image/06_speech.ipynb

         original=AudioSegment.from_mp3(BytesIO(mp3))
         # original=AudioSegment.from_mp3("static/givingtree.mp3") # alternative that works locally (on laptop) but no use for heroku

         start_time_ms = int(float(start_time) * 1000)
         if end_time:
           end_time_ms = int(float(end_time) * 1000)
         else:
           end_time_ms = int(float(original.duration_seconds) * 1000)
         duration_ms = end_time_ms - start_time_ms
         # duration = end_time - start_time
         duration = duration_ms/1000

      #   section = original[start_time_ms:end_time_ms]
      #   section_with_fading = section.fade_in(100).fade_out(100)

         clip = "demo-"
         number = strftime("%Y-%m-%d_%H-%M-%S", gmtime())
         clip += number
         clip += ".mp3"

         # DON'T BOTHER writing locally:
         # clip_with_path = "evernote/static/"+clip
         # section_with_fading.export(clip_with_path, format = "mp3")

      #   tempclip = section_with_fading.export(format = "mp3")

         # commented out while de-bugging, but was working earlier if run on localhost
         # c = boto.connect_s3()
         # b = c.get_bucket(S3_BUCKET_NAME)  # as defined above
         # k = Key(b)
         # k.key=clip
         # # k.set_contents_from_filename(clip_with_path)
         # k.set_contents_from_file(tempclip)
         # k.set_acl('public-read')
         clip_made = True
       else:
         duration = 0.0
         clip_made = False
         clip = ""
       context = {'original_file':original_file, 'new_file':clip, 'start_time': start_time, 'end_time':end_time, 'duration':duration, 'clip_made':clip_made}
       return render(request, 'finalize.html' , context)

    Any suggestions ?

    Potentially related :
    I have ffmpeg installed locally

    But have been unable to install it onto heroku, due to not understanding buildpacks. I tried just a moment ago (http://stackoverflow.com/questions/14407388/how-to-install-ffmpeg-for-a-django-app-on-heroku and https://github.com/shunjikonishi/heroku-buildpack-ffmpeg) but so far ffmpeg is not working on heroku (ffmpeg is not recognised when I do "heroku run ffmpeg —version")
    ...do you think this is the reason ?

    An answer like any of these would be much appreciated as I’m going round in circles here :

    1. "I think ffmpeg is indeed your problem. Try harder to sort that out, to get it installed on heroku"
    2. "Actually, I think this is why BytesIO is not working for you : ..."
    3. "Your approach is terrible anyway... if you want to read in an audio file to process using pydub, you should just do this instead : ..." (since I’m just hacking my way through pydub for my first time... my approach may be poor)

    EDIT 1

    ffmpeg is now installed (e.g., I can output wav files)

    However, I can’t create mp3 files, still... or more correctly, I can, but the filesize is zero

    (venv-app)moriartymacbookair13:getstartapp macuser$ heroku config:add BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
    Setting config vars and restarting awe01... done, v93
    BUILDPACK_URL: https://github.com/ddollar/heroku-buildpack-multi.git
    (venv-app)moriartymacbookair13:getstartapp macuser$ vim .buildpacks
    (venv-app)moriartymacbookair13:getstartapp macuser$ cat .buildpacks
    https://github.com/shunjikonishi/heroku-buildpack-ffmpeg.git
    https://github.com/heroku/heroku-buildpack-python.git
    (venv-app)moriartymacbookair13:getstartapp macuser$ git add --all
    (venv-app)moriartymacbookair13:getstartapp macuser$ git commit -m "need multi, not just ffmpeg, so adding back in multi + shun + heroku, with trailing .git in .buildpacks file"
    [master cd99fef] need multi, not just ffmpeg, so adding back in multi + shun + heroku, with trailing .git in .buildpacks file
    1 file changed, 2 insertions(+), 2 deletions(-)
    (venv-app)moriartymacbookair13:getstartapp macuser$ git push heroku master
    Fetching repository, done.
    Counting objects: 5, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (3/3), done.
    Writing objects: 100% (3/3), 372 bytes | 0 bytes/s, done.
    Total 3 (delta 2), reused 0 (delta 0)

    -----> Fetching custom git buildpack... done
    -----> Multipack app detected
    =====> Downloading Buildpack: https://github.com/shunjikonishi/heroku-buildpack-ffmpeg.git
    =====> Detected Framework: ffmpeg
    -----> Install ffmpeg
          DOWNLOAD_URL =  http://flect.github.io/heroku-binaries/libs/ffmpeg.tar.gz
          exporting PATH and LIBRARY_PATH
    =====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-python.git
    =====> Detected Framework: Python
    -----> Installing dependencies with pip
          Cleaning up...

    -----> Preparing static assets
          Collectstatic configuration error. To debug, run:
          $ heroku run python ./example/manage.py collectstatic --noinput

    Using release configuration from last framework (Python).
    -----> Discovering process types
          Procfile declares types -> web

    -----> Compressing... done, 198.1MB
    -----> Launching... done, v94
          http://[redacted].herokuapp.com/ deployed to Heroku

    To git@heroku.com:awe01.git
      78d6b68..cd99fef  master -> master
    (venv-app)moriartymacbookair13:getstartapp macuser$ heroku run ffmpeg
    Running `ffmpeg` attached to terminal... up, run.6408
    ffmpeg version git-2013-06-02-5711e4f Copyright (c) 2000-2013 the FFmpeg developers
     built on Jun  2 2013 07:38:40 with gcc 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)
     configuration: --enable-shared --disable-asm --prefix=/app/vendor/ffmpeg
     libavutil      52. 34.100 / 52. 34.100
     libavcodec     55. 13.100 / 55. 13.100
     libavformat    55.  8.102 / 55.  8.102
     libavdevice    55.  2.100 / 55.  2.100
     libavfilter     3. 74.101 /  3. 74.101
     libswscale      2.  3.100 /  2.  3.100
     libswresample   0. 17.102 /  0. 17.102
    Hyper fast Audio and Video encoder
    usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

    Use -h to get full help or, even better, run 'man ffmpeg'
    (venv-app)moriartymacbookair13:getstartapp macuser$ heroku run bash
    Running `bash` attached to terminal... up, run.9660
    ~ $ python
    Python 2.7.8 (default, Jul  9 2014, 20:47:08)
    [GCC 4.4.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pydub
    >>> from pydub import AudioSegment
    >>> exit()
    ~ $ which ffmpeg
    /app/vendor/ffmpeg/bin/ffmpeg
    ~ $ python

    Python 2.7.8 (default, Jul  9 2014, 20:47:08)
    [GCC 4.4.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pydub
    >>> from pydub import AudioSegment
    >>> AudioSegment.silent(5000).export("/tmp/asdf.mp3", "mp3")
    <open file="file"></open>tmp/asdf.mp3', mode 'wb+' at 0x7f9a37d44780>
    >>> exit ()
    ~ $ cd /tmp/
    /tmp $ ls
    asdf.mp3
    /tmp $ open asdf.mp3
    bash: open: command not found
    /tmp $ ls -lah
    total 8.0K
    drwx------  2 u36483 36483 4.0K 2014-10-22 04:14 .
    drwxr-xr-x 14 root   root  4.0K 2014-09-26 07:08 ..
    -rw-------  1 u36483 36483    0 2014-10-22 04:14 asdf.mp3

    Note the file size of 0 above for the mp3 file... when I do the same thing on my macbook, the file size is never zero

    Back to the heroku shell :

    /tmp $ python
    Python 2.7.8 (default, Jul  9 2014, 20:47:08)
    [GCC 4.4.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pydub
    >>> from pydub import AudioSegment
    >>> pydub.AudioSegment.ffmpeg = "/app/vendor/ffmpeg/bin/ffmpeg"
    >>> AudioSegment.silence(1200).export("/tmp/herokuSilence.mp3", format="mp3")
    Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
    AttributeError: type object 'AudioSegment' has no attribute 'silence'
    >>> AudioSegment.silent(1200).export("/tmp/herokuSilence.mp3", format="mp3")
    <open file="file"></open>tmp/herokuSilence.mp3', mode 'wb+' at 0x7fcc2017c780>
    >>> exit()
    /tmp $ ls
    asdf.mp3  herokuSilence.mp3
    /tmp $ ls -lah
    total 8.0K
    drwx------  2 u36483 36483 4.0K 2014-10-22 04:29 .
    drwxr-xr-x 14 root   root  4.0K 2014-09-26 07:08 ..
    -rw-------  1 u36483 36483    0 2014-10-22 04:14 asdf.mp3
    -rw-------  1 u36483 36483    0 2014-10-22 04:29 herokuSilence.mp3
    </module></stdin>

    I realised the first time that I had forgotten the pydub.AudioSegment.ffmpeg = "/app/vendor/ffmpeg/bin/ffmpeg" command, but as you can see above, the file is still zero size

    Out of desperation, I even tried adding the ".heroku" into the path to be as verbatim as your example, but that didn’t fix it :

    /tmp $ python
    Python 2.7.8 (default, Jul  9 2014, 20:47:08)
    [GCC 4.4.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pydub
    >>> from pydub import AudioSegment
    >>> pydub.AudioSegment.ffmpeg = "/app/.heroku/vendor/ffmpeg/bin/ffmpeg"
    >>> AudioSegment.silent(1200).export("/tmp/herokuSilence03.mp3", format="mp3")
    <open file="file"></open>tmp/herokuSilence03.mp3', mode 'wb+' at 0x7fc92aca7780>
    >>> exit()
    /tmp $ ls -lah
    total 8.0K
    drwx------  2 u36483 36483 4.0K 2014-10-22 04:31 .
    drwxr-xr-x 14 root   root  4.0K 2014-09-26 07:08 ..
    -rw-------  1 u36483 36483    0 2014-10-22 04:14 asdf.mp3
    -rw-------  1 u36483 36483    0 2014-10-22 04:31 herokuSilence03.mp3
    -rw-------  1 u36483 36483    0 2014-10-22 04:29 herokuSilence.mp3

    Finally, I tried exporting a .wav file to check pydub was at least working correctly

    /tmp $ python
    Python 2.7.8 (default, Jul  9 2014, 20:47:08)
    [GCC 4.4.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pydub
    >>> from pydub import AudioSegment
    >>> pydub.AudioSegment.ffmpeg = "/app/vendor/ffmpeg/bin/ffmpeg"
    >>> AudioSegment.silent(1300).export("/tmp/heroku_wav_silence01.wav", format="wav")
    <open file="file"></open>tmp/heroku_wav_silence01.wav', mode 'wb+' at 0x7fa33cbf3780>
    >>> exit()
    /tmp $ ls
    asdf.mp3  herokuSilence03.mp3  herokuSilence.mp3  heroku_wav_silence01.wav
    /tmp $ ls -lah
    total 40K
    drwx------  2 u36483 36483 4.0K 2014-10-22 04:42 .
    drwxr-xr-x 14 root   root  4.0K 2014-09-26 07:08 ..
    -rw-------  1 u36483 36483    0 2014-10-22 04:14 asdf.mp3
    -rw-------  1 u36483 36483    0 2014-10-22 04:31 herokuSilence03.mp3
    -rw-------  1 u36483 36483    0 2014-10-22 04:29 herokuSilence.mp3
    -rw-------  1 u36483 36483  29K 2014-10-22 04:42 heroku_wav_silence01.wav
    /tmp $

    At least that filesize for .wav is non-zero, so pydub is working

    My current theory is that either I’m still not using ffmpeg correctly, or it’s insufficient... maybe I need an mp3 additional install on top of basic ffmpeg.

    Several sites mention "libavcodec-extra-53" but I’m not sure how to install that on heroku, or to check if I have it ? https://github.com/jiaaro/pydub/issues/36
    Similarly tutorials on libmp3lame seem to be geared towards laptop installation rather than installation on heroku, so I’m at a loss http://superuser.com/questions/196857/how-to-install-libmp3lame-for-ffmpeg

    In case relevant, I also have youtube-dl in my requirements.txt... this also works locally on my macbook, but fails when I run it in the heroku shell :

    ~/ytdl $ youtube-dl --restrict-filenames -x --audio-format mp3 n2anDgdUHic
    [youtube] Setting language
    [youtube] Confirming age
    [youtube] n2anDgdUHic: Downloading webpage
    [youtube] n2anDgdUHic: Downloading video info webpage
    [youtube] n2anDgdUHic: Extracting video information
    [download] Destination: Boyce_Avenue_feat._Megan_Nicole_-_Skyscraper_Patrick_Ebert_Edit-n2anDgdUHic.m4a
    [download] 100% of 5.92MiB in 00:00
    [ffmpeg] Destination: Boyce_Avenue_feat._Megan_Nicole_-_Skyscraper_Patrick_Ebert_Edit-n2anDgdUHic.mp3
    ERROR: audio conversion failed: Unknown encoder 'libmp3lame'
    ~/ytdl $

    The informative link is that it too specificies an mp3 failure, so perhaps they two issues are related.


    EDIT 2

    See answer, all problems solved

  • ffmpeg command to copy raw data into MP4 hangs and never finishes

    28 mai 2019, par James Adams

    I am running an ffmpeg command to copy raw H.265 data into an MP4 file and the command never completes. The file isn’t large, just 10 seconds worth of data. Here’s the command I’m running :

    $ ffmpeg -rtsp_transport tcp -i rtsp://user:pass@71.185.124.195:554/c1/b1558830329/e1558830339/replay/ -vcodec copy -y test_clip.mp4

    I then get output like this :

    ffmpeg version 3.4.6-0ubuntu0.18.04.1 Copyright (c) 2000-2019 the FFmpeg developers
     built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
     configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --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-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --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-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
     libavutil      55. 78.100 / 55. 78.100
     libavcodec     57.107.100 / 57.107.100
     libavformat    57. 83.100 / 57. 83.100
     libavdevice    57. 10.100 / 57. 10.100
     libavfilter     6.107.100 /  6.107.100
     libavresample   3.  7.  0 /  3.  7.  0
     libswscale      4.  8.100 /  4.  8.100
     libswresample   2.  9.100 /  2.  9.100
     libpostproc    54.  7.100 / 54.  7.100
    Guessed Channel Layout for Input Stream #0.1 : mono
    Input #0, rtsp, from 'rtsp://user:pass@71.85.104.195:554/c1/b1558830329/e1558830339/replay/':
     Metadata:
       title           : ONVIF RTSP Server
     Duration: N/A, start: 0.000000, bitrate: N/A
       Stream #0:0: Video: h264 (High), yuvj420p(pc, bt709, progressive), 1920x1080, 30 fps, 30 tbr, 90k tbn, 60 tbc
       Stream #0:1: Audio: pcm_mulaw, 8000 Hz, mono, s16, 64 kb/s
    Stream mapping:
     Stream #0:0 -> #0:0 (copy)
     Stream #0:1 -> #0:1 (pcm_mulaw (native) -> aac (native))
    Press [q] to stop, [?] for help
    [aac @ 0x55b71ce31900] Too many bits 8832.000000 > 6144 per frame requested, clamping to max
    Output #0, mp4, to 'test_clip.mp4':
     Metadata:
       title           : ONVIF RTSP Server
       encoder         : Lavf57.83.100
       Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709, progressive), 1920x1080, q=2-31, 30 fps, 30 tbr, 90k tbn, 90k tbc
       Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 8000 Hz, mono, fltp, 48 kb/s
       Metadata:
         encoder         : Lavc57.107.100 aac
    [mp4 @ 0x55b71ce17e00] Non-monotonous DTS in output stream 0:0; previous: 18000, current: 3000; changing to 18001. This may result in incorrect timestamps in the output file.
    [mp4 @ 0x55b71ce17e00] Non-monotonous DTS in output stream 0:0; previous: 18001, current: 6000; changing to 18002. This may result in incorrect timestamps in the output file.
    [mp4 @ 0x55b71ce17e00] Non-monotonous DTS in output stream 0:0; previous: 18002, current: 9000; changing to 18003. This may result in incorrect timestamps in the output file.
    [mp4 @ 0x55b71ce17e00] Non-monotonous DTS in output stream 0:0; previous: 18003, current: 12000; changing to 18004. This may result in incorrect timestamps in the output file.
    [mp4 @ 0x55b71ce17e00] Non-monotonous DTS in output stream 0:0; previous: 18004, current: 15000; changing to 18005. This may result in incorrect timestamps in the output file.
    [mp4 @ 0x55b71ce17e00] Non-monotonous DTS in output stream 0:0; previous: 18005, current: 18000; changing to 18006. This may result in incorrect timestamps in the output file.
    frame=   44 fps=0.0 q=-1.0 size=     256kB time=00:00:01.43 bitrate=1463.4kbits/frame=   60 fps= 57 q=-1.0 size=     512kB time=00:00:01.96 bitrate=2132.9kbits/frame=   76 fps= 48 q=-1.0 size=     768kB time=00:00:02.50 bitrate=2516.7kbits/frame=   92 fps= 44 q=-1.0 size=    1024kB time=00:00:03.03 bitrate=2765.6kbits/frame=  108 fps= 41 q=-1.0 size=    1024kB time=00:00:03.56 bitrate=2352.0kbits/[NULL @ 0x55b71cdfa540] SEI type 5 size 2208 truncated at 1944
    frame=  123 fps= 39 q=-1.0 size=    1280kB time=00:00:04.06 bitrate=2578.6kbits/frame=  139 fps= 38 q=-1.0 size=    1536kB time=00:00:04.60 bitrate=2735.5kbits/frame=  155 fps= 37 q=-1.0 size=    1536kB time=00:00:05.13 bitrate=2451.3kbits/frame=  171 fps= 36 q=-1.0 size=    1792kB time=00:00:05.66 bitrate=2590.7kbits/frame=  187 fps= 36 q=-1.0 size=    2048kB time=00:00:06.20 bitrate=2706.1kbits/frame=  203 fps= 35 q=-1.0 size=    2304kB time=00:00:06.73 bitrate=2803.2kbits/frame=  219 fps= 35 q=-1.0 size=    2304kB time=00:00:07.26 bitrate=2597.4kbits/frame=  235 fps= 34 q=-1.0 size=    2560kB time=00:00:07.80 bitrate=2688.7kbits/frame=  246 fps= 33 q=-1.0 size=    2560kB time=00:00:08.16 bitrate=2568.0kbits/frame=  267 fps= 34 q=-1.0 size=    3072kB time=00:00:08.86 bitrate=2838.3kbits/frame=  282 fps= 34 q=-1.0 size=    3072kB time=00:00:09.36 bitrate=2686.8kbits/frame=  298 fps= 33 q=-1.0 size=    3328kB time=00:00:09.90 bitrate=2753.9kbits/frame=  314 fps= 33 q=-1.0 size=    3328kB time=00:00:10.43 bitrate=2613.1kbits/^Cspeed=1.11x    

    The command never completes and I need to kill it using Ctrl-C.

    I have also tried adding the options -nostdin -loglevel error and appending this to the end of the command : > /dev/null 2>&amp;1 &lt; /dev/null but to no avail.

    I am testing the above since it mimics the actual code I’m developing which utilizes a Python package that wraps calls to ffmpeg. The Python code below works well on a laptop but hangs on EC2 (both are Ubuntu 18.04) :

    import argparse
    import datetime
    import ffmpeg


    # ------------------------------------------------------------------------------
    if __name__ == "__main__":

       # USAGE
       # $ python collect_and_store.py --rtsp rtsp://user:pass1@71.85.125.110:554 \
       #       --duration 30 --count 10

       # construct the argument parser and parse the arguments
       args_parser = argparse.ArgumentParser()
       args_parser.add_argument("--rtsp",
                                required=True,
                                type=str,
                                help="RTSP URL for video stream")
       args_parser.add_argument("--duration",
                                required=True,
                                type=int,
                                help="duration of saved clips (in seconds)")
       args_parser.add_argument("--count",
                                required=True,
                                type=int,
                                help="number of clips to save")
       args = vars(args_parser.parse_args())

       # sanity check for some of the arguments
       if not args["rtsp"].lower().startswith("rtsp://"):
           raise ValueError("Invalid input URL -- only RTSP supported")

       seconds_per_clip = args["duration"]
       start = int(datetime.datetime.now().strftime("%s"))
       end = start + seconds_per_clip
       number_of_files_to_collect = args["count"]

       while number_of_files_to_collect > 0:

           # build URL with start and end times
           # NOTE URL is for Uniview RTSP, add options for other camera types
           url = args["rtsp"] + f"/c1/b{start}/e{end}/replay/"

           # file where we'll write clip data
           temp_file = f"clip_b{start}_e{end}.mp4"

           # create the equivalent of the ffmpeg command:
           # $ ffmpeg -i  -vcodec copy -y -rtsp_transport tcp
           stream = ffmpeg.input(url)
           stream = ffmpeg.output(stream, temp_file,
                                  **{"codec:v": "copy",
                                     "rtsp_transport": "tcp",
                                     "y": None
                                     }
                                  )
           ffmpeg.run(stream)

           print(f"\n\nMP4 file created: {temp_file}")

           number_of_files_to_collect -= 1
           start = end + 1
           end = start + seconds_per_clip
  • Unable to Access IP Camera in OpenCV

    3 janvier 2017, par user7258890

    I’m trying to use Javafx and OpenCV to access a webcam (Axis M1013) over wireless to run vision processing for my FRC team. When I run my code, I can access the GUI that I made using Scenebuilder, but when I try to start the camera, the program crashes. It seems to me like it’s having trouble utilizing the VideoCapture class. I know for a fact that my problem is not with the camera, because i can access the feed through a browser feed, and my laptop’s webcam will work fine. I’m using OpevCV version 2.4.13, jdk 8u101x64, and ffmpeg 3.2

    I have looked at other posts at :

    stackoverflow.com/questions/18625948/opencv-java-unsatisfiedlinkerror

    answers.opencv.org/question/21720/java-webcam-capture

    answers.opencv.org/question/20071/unsatisfiedlinkerror-given-by-highghuiimread-on-java

    I have tried the solutions mentioned in all of these. So far, none have resolved my problem.

    My code is based mostly off the tutorials at :

    opencv-java-tutorials.readthedocs.io/en/latest/03-first-javafx-application-with-opencv.html

    Here is my main java code :

       @Override
    public void start(Stage primaryStage) {
       System.load("C:\\opencv\\build\\x64\\vc12\\bin\\opencv_ffmpeg_64.dll");
       try {
           FXMLLoader loader = new FXMLLoader(getClass().getResource("Sample.fxml"));
           BorderPane root = (BorderPane) loader.load();
           Scene scene = new Scene(root, 400, 400);
           scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
           primaryStage.setScene(scene);
           primaryStage.show();
       } catch(Exception e) {
           System.out.println("error opening camera gui");
       }
    }

    public static void main(String[] args) {
       launch(args);
    }

    And here is my camera controller :

    public class SampleController {
    @FXML
    private Button Start_btn;

    @FXML
    private ImageView currentFrame;
    private ScheduledExecutorService timer;
    private VideoCapture capture;
    private boolean cameraActive = false;

    @FXML
    public void startCamera()
    {
       System.loadLibrary("opencv_ffmpeg_64");
       if (!this.cameraActive)
       {
           try
           {
            capture = new VideoCapture("http://FRC:FRC@axis-camera-223-catapult.lan:554/mjpg/1/video.mjpg");
           }
           catch (Exception e)
           {
               System.out.println("an error occured when attempting to access camera.");
           }
           // is the video stream available?
           if (this.capture.isOpened())
           {
               this.cameraActive = true;

               // grab a frame every 33 ms (30 frames/sec)
               Runnable frameGrabber = new Runnable() {

                   @Override
                   public void run()
                   {
                       // effectively grab and process a single frame
                       Mat frame = grabFrame();
                       // convert and show the frame
                       Image imageToShow = Utils.mat2Image(frame);
                       updateImageView(currentFrame, imageToShow);
                   }
               };

               this.timer = Executors.newSingleThreadScheduledExecutor();
               this.timer.scheduleAtFixedRate(frameGrabber, 0, 33, TimeUnit.MILLISECONDS);

               // update the button content
               this.Start_btn.setText("Stop Camera");
           }
           else
           {
               // log the error
               System.err.println("Impossible to open the camera connection...");
           }
       }
       else
       {
           // the camera is not active at this point
           this.cameraActive = false;
           // update again the button content
           this.Start_btn.setText("Start Camera");

           // stop the timer
           this.stopAquisition();
       }

       System.out.println("Camera is now on.");
    }

    /**
    * Get frame from open video
    * @return
    */
       private Mat grabFrame()

       {
           Mat frame = new Mat();
           if (this.capture.isOpened())
           {
               try
               {
                   this.capture.read(frame);

                   }
           catch (Exception e)
           {
               System.err.println("Exception during the image elaboration: " + e);
           }
       }
       return frame;
    }
       private void stopAquisition()
       {
           if (this.timer!=null &amp;&amp; !this.timer.isShutdown())
           {
               try
               {
                   this.timer.shutdown();
                   this.timer.awaitTermination(33, TimeUnit.MILLISECONDS);
               }
               catch (InterruptedException e)
               {
                   System.err.println("Exception in stopping the frame capture, trying to release camera now..." + e);

               }
           }
           if (this.capture.isOpened())
           {
               this.capture.release();
           }
       }
       private void updateImageView(ImageView view, Image image)
       {
           Utils.onFXThread(view.imageProperty(), image);
       }
       protected void setClosed()
       {
           this.stopAquisition();
       }
    }

    When I try and run this as i have said before, the GUI will launch, but when i try and open the camera, i get an error message :

    Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Node.fireEvent(Node.java:8411)
    at javafx.scene.control.Button.fire(Button.java:185)
    at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
    at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
    at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:380)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:294)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:416)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:415)
    at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
    at com.sun.glass.ui.View.notifyMouse(View.java:937)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.reflect.misc.Trampoline.invoke(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
    ... 48 more
    Caused by: java.lang.UnsatisfiedLinkError:     org.opencv.highgui.VideoCapture.VideoCapture_1(Ljava/lang/String;)J
    at org.opencv.highgui.VideoCapture.VideoCapture_1(Native Method)
    at org.opencv.highgui.VideoCapture.<init>(VideoCapture.java:128)
    at jfxtest1.SampleController.startCamera(SampleController.java:36)
    ... 58 more
    </init>

    If anyone can help me, that would be much appreciated.

    Thanks in advance.