Recherche avancée

Médias (0)

Mot : - Tags -/publication

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

Autres articles (40)

  • HTML5 audio and video support

    13 avril 2011, par

    MediaSPIP uses HTML5 video and audio tags to play multimedia files, taking advantage of the latest W3C innovations supported by modern browsers.
    The MediaSPIP player used has been created specifically for MediaSPIP and can be easily adapted to fit in with a specific theme.
    For older browsers the Flowplayer flash fallback is used.
    MediaSPIP allows for media playback on major mobile platforms with the above (...)

  • De l’upload à la vidéo finale [version standalone]

    31 janvier 2010, par

    Le chemin d’un document audio ou vidéo dans SPIPMotion est divisé en trois étapes distinctes.
    Upload et récupération d’informations de la vidéo source
    Dans un premier temps, il est nécessaire de créer un article SPIP et de lui joindre le document vidéo "source".
    Au moment où ce document est joint à l’article, deux actions supplémentaires au comportement normal sont exécutées : La récupération des informations techniques des flux audio et video du fichier ; La génération d’une vignette : extraction d’une (...)

  • 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 (6371)

  • How to use audio frame after decode mp3 file using pyav, ffmpeg, python

    2 janvier 2021, par Long Tran Dai

    I am using using python with pyav, ffmpeg to decode mp3 in the memory. I know there are some other way to do it, like pipe ffmpeg command. However, I would like to explore pyav and ffmpeg API. So I have the following code. It works but the sound is very noisy, although hearable :

    


    import numpy as np&#xA;import av # to convert mp3 to wav using ffmpeg&#xA;import pyaudio # to play music&#xA;&#xA;mp3_path = &#x27;D:/MyProg/python/SauTimThiepHong.mp3&#x27;&#xA;&#xA;def decodeStream(mp3_path):&#xA;  # Run NOT OK&#xA;  &#xA;  container = av.open(mp3_path)&#xA;  stream = next(s for s in container.streams if s.type == &#x27;audio&#x27;)&#xA;  frame_count = 0&#xA;  data = bytearray()&#xA;  for packet in container.demux(stream):&#xA;    # <class>&#xA;    # We need to skip the "flushing" packets that `demux` generates.&#xA;    #if frame_count == 5000 : break         &#xA;    if packet.dts is None:&#xA;        continue&#xA;    for frame in packet.decode():   &#xA;        #&#xA;        # type(frame) : <class>&#xA;        #frame.samples = 1152 : 1152 diem du lieu : Number of audio samples (per channel)&#xA;        # moi frame co size = 1152 (diem) * 2 (channels) * 4 (bytes / diem) = 9216 bytes&#xA;        # 11021 frames&#xA;        #arr = frame.to_ndarray() # arr.nbytes = 9216&#xA;&#xA;        #channels = []  &#xA;        channels = frame.to_ndarray().astype("float16")&#xA;        #for plane in frame.planes:&#xA;            #channels.append(plane.to_bytes()) #plane has 4 bytes / sample, but audio has only 2 bytes&#xA;        #    channels.append(np.frombuffer(plane, dtype=np.single).astype("float16"))&#xA;            #channels.append(np.frombuffer(plane, dtype=np.single)) # kieu np.single co 4 bytes&#xA;        if not frame.is_corrupt:&#xA;            #data.extend(np.frombuffer(frame.planes[0], dtype=np.single).astype("float16")) # 1 channel: noisy&#xA;            # type(planes) : <class>&#xA;            frame_count &#x2B;= 1&#xA;            #print( &#x27;>>>> %04d&#x27; % frame_count, frame)   &#xA;            #if frame_count == 5000 : break     &#xA;            # mix channels:&#xA;            for i in range(frame.samples):                &#xA;                for ch in channels: # dec_ctx->channels&#xA;                    data.extend(ch[i]) #noisy&#xA;                    #fwrite(frame->data[ch] &#x2B; data_size*i, 1, data_size, outfile)&#xA;  return bytes(data)&#xA;</class></class></class>

    &#xA;

    I use pipe ffmpeg to get decoded data to compare and find they are different :

    &#xA;

    def RunFFMPEG(mp3_path, target_fs = "44100"):&#xA;    # Run OK&#xA;    import subprocess&#xA;    # init command&#xA;    ffmpeg_command = ["ffmpeg", "-i", mp3_path,&#xA;                   "-ab", "128k", "-acodec", "pcm_s16le", "-ac", "0", "-ar", target_fs, "-map",&#xA;                   "0:a", "-map_metadata", "-1", "-sn", "-vn", "-y",&#xA;                   "-f", "wav", "pipe:1"]&#xA;    # excute ffmpeg command&#xA;    pipe = subprocess.run(ffmpeg_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize= 10**8)&#xA;    # debug&#xA;    #print(pipe.stdout, pipe.stderr)&#xA;    # read signal as numpy array and assign sampling rate&#xA;    #audio_np = np.frombuffer(buffer=pipe.stdout, dtype=np.uint16, offset=44)&#xA;    #audio_np = np.frombuffer(buffer=pipe.stdout, dtype=np.uint16)&#xA;    #sig, fs  = audio_np, target_fs&#xA;    #return audio_np&#xA;    return pipe.stdout[78:]     &#xA;

    &#xA;

    Then I use pyaudio to play data and find it very noisy

    &#xA;

    p = pyaudio.PyAudio()&#xA;streamOut = p.open(format=pyaudio.paInt16, channels=2, rate= 44100, output=True)&#xA;#streamOut = p.open(format=pyaudio.paInt16, channels=1, rate= 44100, output=True)&#xA;&#xA;mydata = decodeStream(mp3_path)&#xA;print("bytes of mydata = ", len(mydata))&#xA;#print("bytes of mydata = ", mydata.nbytes)&#xA;&#xA;ffMpegdata = RunFFMPEG(mp3_path)&#xA;print("bytes of ffMpegdata = ", len(ffMpegdata)) &#xA;#print("bytes of ffMpegdata = ", ffMpegdata.nbytes)&#xA;&#xA;minlen = min(len(mydata), len(ffMpegdata))&#xA;print("mydata == ffMpegdata", mydata[:minlen] == ffMpegdata[:minlen]) # ffMpegdata.tobytes()[:minlen] )&#xA;&#xA;#bytes of mydata =  50784768&#xA;#bytes of ffMpegdata =  50784768&#xA;#mydata == ffMpegdata False&#xA;&#xA;streamOut.write(mydata)&#xA;streamOut.write(ffMpegdata)&#xA;streamOut.stop_stream()&#xA;streamOut.close()&#xA;p.terminate()&#xA;

    &#xA;

    Please help me to understand decoded frame of pyav api (after for frame in packet.decode() :). Should it be processed more ? or I have some error ?

    &#xA;

    It makes me crazy for 3 days. I could not guess where to go.

    &#xA;

    Thank you very much.

    &#xA;

  • ffmpeg lags when streaming video+audio from RPi Zero W with Logitech C920

    7 janvier 2021, par Ema

    I've been trying to setup a baby monitor with a Raspberry Pi Zero and a Logitech C920 webcam. I does work with VLC (cvlc) but it lags too much and gets worse over time.

    &#xA;

    So I am playing around with ffmpeg and I am getting some better results. This is what I've done so far.

    &#xA;

    First I set the webcam to output h264 1080p natively (the Pi Zero W can't afford to do any transcoding).

    &#xA;

    v4l2-ctl --set-fmt-video=width=1920,height=1080,pixelformat=1&#xA;

    &#xA;

    Now, if I stream audio only with

    &#xA;

    ffmpeg \&#xA;-f alsa \&#xA;-i hw:1,0 \&#xA;-vn \&#xA;-flags &#x2B;global_header \&#xA;-acodec aac \&#xA;-ac 1 \&#xA;-ar 16000 \&#xA;-ab 16k \&#xA;-f rtp rtp://192.168.0.10:5002 > audio.sdp&#xA;

    &#xA;

    it works great and the lag is about 1 second (definitely acceptable).

    &#xA;

    If I stream video only with

    &#xA;

    ffmpeg \&#xA;-f v4l2 \&#xA;-vcodec h264 \&#xA;-i /dev/video0 \&#xA;-an \&#xA;-vcodec copy \&#xA;-pix_fmt yuv420p \&#xA;-r 30 \&#xA;-b:v 512k \&#xA;-flags &#x2B;global_header \&#xA;-f rtp rtp://192.168.0.10:5000 > video.sdp&#xA;

    &#xA;

    same result, very little lag (for some reason the first -vcodec is necessary to force the webcam to output h264).

    &#xA;

    However, when I stream both with

    &#xA;

    ffmpeg \&#xA;-f v4l2 \&#xA;-vcodec h264 \&#xA;-i /dev/video0 \&#xA;-f alsa \&#xA;-i hw:1,0 \&#xA;-an \&#xA;-preset ultrafast \&#xA;-tune zerolatency \&#xA;-vcodec copy \&#xA;-pix_fmt yuv420p \&#xA;-r 30 \&#xA;-b:v 512k \&#xA;-flags &#x2B;global_header \&#xA;-f rtp rtp://192.168.0.10:5000 \&#xA;-vn \&#xA;-flags &#x2B;global_header \&#xA;-acodec aac \&#xA;-ac 1 \&#xA;-ar 16000 \&#xA;-ab 16k \&#xA;-f rtp rtp://192.168.0.10:5002 > both.sdp&#xA;

    &#xA;

    the lag ramps up to 10 seconds and audio and video are out of sync. Does anybody know why ?

    &#xA;

    I've tried UDP and TCP instead of RTP but then the lag is always high, even with audio/video only.

    &#xA;

    Any suggestion is much appreciated.

    &#xA;

    P.S. On the client side (MacOS) I'm receiving with

    &#xA;

    ffplay -protocol_whitelist file,rtp,udp -i file.sdp&#xA;

    &#xA;

  • scripting massive number of files with ffmpeg [closed]

    2 décembre 2020, par 8Liter

    Alright, I've got over 5000 MP4 files in a single directory that I would ultimately like to process using ffmpeg. I've got a few different solutions that all work by themselves, but put together do not make my job any easier.&#xA;The current file list looks like this, in one single directory :

    &#xA;

      &#xA;
    • 10-1.mp4
    • &#xA;

    • 10-2.mp4
    • &#xA;

    • 10123-1.mp4
    • &#xA;

    • 10123-2.mp4
    • &#xA;

    • 10123-3.mp4
    • &#xA;

    • 10123-4.mp4
    • &#xA;

    • 10123-5.mp4
    • &#xA;

    • 10123-6.mp4
    • &#xA;

    • 102-1.mp4
    • &#xA;

    • 103-1.mp4
    • &#xA;

    • 103-2.mp4
    • &#xA;

    • 103-3.mp4
    • &#xA;

    • 107-1.mp4
    • &#xA;

    • 107-2.mp4
    • &#xA;

    • 107-3.mp4
    • &#xA;

    • 107-4.mp4
    • &#xA;

    • 107-5.mp4
    • &#xA;

    • 107-6.mp4
    • &#xA;

    • 11-1.mp4
    • &#xA;

    • 11-2.mp4
    • &#xA;

    &#xA;

    The ideal process I would like is the following :

    &#xA;

    A. Take however many files in the directory have a particular prefix, for example the two "11" files at the bottom, and concatenate them into a single MP4 file. The end result is a single "11.MP4"

    &#xA;

    B. Delete the original two "11-1.mp4" and "11-2.mp4", keeping only the new "11.mp4" complete file.

    &#xA;

    C. Repeat steps A-B for all other files in this directory

    &#xA;

    This is not apparently possible right now from what I can glean from other threads, but I've tested a more manual approach which is not clean OR fast, and this is what my workflow looks like in real life...

    &#xA;

      &#xA;
    1. move files with same prefix into new folder (I have a working bat file that will do this for me)
    2. &#xA;

    3. run a ffmpeg bat file to process an "output.mp4" file (I have a working bat file that will do this for me)
    4. &#xA;

    5. delete the original files
    6. &#xA;

    7. rename the output.mp4 file to the prefix name (i.e. 11.mp4)
    8. &#xA;

    9. copy that file back into the new directory
    10. &#xA;

    11. repeat steps 1-5 a thousand times.
    12. &#xA;

    &#xA;

    I've also looked into creating all new directories BASED on the filename (I have a working bat file that will do this for me) and then copy my ffmpeg bat file into each directory, and run each bat file manually... but again it's a ton of work.

    &#xA;

    (FROM STEP 1 ABOVE)

    &#xA;

    @echo off&#xA;setlocal&#xA;&#xA;set "basename=."&#xA;for /F "tokens=1* delims=.*" %%a in (&#x27;dir /B /A-D ^| sort /R&#x27;) do (&#xA;   set "filename=%%a"&#xA;   setlocal EnableDelayedExpansion&#xA;   for /F "delims=" %%c in ("!basename!") do if "!filename:%%c=!" equ "!filename!" (&#xA;      set "basename=!filename!"&#xA;      md "!basename!"&#xA;   )&#xA;   move "!filename!.%%b" "!basename!"&#xA;   for /F "delims=" %%c in ("!basename!") do (&#xA;      endlocal&#xA;      set "basename=%%c&#xA;&#xA;   )&#xA;)&#xA;

    &#xA;

    (FROM STEP 2 ABOVE)

    &#xA;

    :: Create File List&#xA;del "F:\videos\*.txt" /s /f /q&#xA;for %%i in (*.mp4) do echo file &#x27;%%i&#x27;>> mylist.txt&#xA;&#xA;:: Concatenate Files&#xA;ffmpeg.exe -f concat -safe 0 -i mylist.txt -c copy output.mp4&#xA;

    &#xA;

    Any ideas how I can approach this ? I'm open to powershell, batch, even python if I need to.

    &#xA;