Recherche avancée

Médias (0)

Mot : - Tags -/interaction

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

Autres articles (71)

  • Other interesting software

    13 avril 2011, par

    We don’t claim to be the only ones doing what we do ... and especially not to assert claims to be the best either ... What we do, we just try to do it well and getting better ...
    The following list represents softwares that tend to be more or less as MediaSPIP or that MediaSPIP tries more or less to do the same, whatever ...
    We don’t know them, we didn’t try them, but you can take a peek.
    Videopress
    Website : http://videopress.com/
    License : GNU/GPL v2
    Source code : (...)

  • Personnaliser les catégories

    21 juin 2013, par

    Formulaire de création d’une catégorie
    Pour ceux qui connaissent bien SPIP, une catégorie peut être assimilée à une rubrique.
    Dans le cas d’un document de type catégorie, les champs proposés par défaut sont : Texte
    On peut modifier ce formulaire dans la partie :
    Administration > Configuration des masques de formulaire.
    Dans le cas d’un document de type média, les champs non affichés par défaut sont : Descriptif rapide
    Par ailleurs, c’est dans cette partie configuration qu’on peut indiquer le (...)

  • Keeping control of your media in your hands

    13 avril 2011, par

    The vocabulary used on this site and around MediaSPIP in general, aims to avoid reference to Web 2.0 and the companies that profit from media-sharing.
    While using MediaSPIP, you are invited to avoid using words like "Brand", "Cloud" and "Market".
    MediaSPIP is designed to facilitate the sharing of creative media online, while allowing authors to retain complete control of their work.
    MediaSPIP aims to be accessible to as many people as possible and development is based on expanding the (...)

Sur d’autres sites (4560)

  • ffserver : move decl to start of func

    27 juillet 2015, par Reynaldo H. Verdejo Pinochet
    ffserver : move decl to start of func
    

    Signed-off-by : Reynaldo H. Verdejo Pinochet <reynaldo@osg.samsung.com>

    • [DH] ffserver.c
  • Avoid using the term "file" and prefer "url" in some docs and comments

    5 décembre 2016, par Michael Niedermayer
    Avoid using the term "file" and prefer "url" in some docs and comments
    

    This should make it less ambigous that these are URLs

    Signed-off-by : Michael Niedermayer <michael@niedermayer.cc>

    • [DH] doc/ffmpeg.texi
    • [DH] doc/ffplay.texi
    • [DH] doc/ffprobe.texi
    • [DH] ffmpeg_opt.c
  • Using PyAV to encode mono audio to file, params match docs, but still causes Errno 22

    20 février 2023, par andrew8088

    While trying to use PyAV to encode live mono audio from a microphone to a compressed audio stream (using mp2 or flac as encoder), the program kept raising an exception ValueError: [Errno 22] Invalid argument.

    &#xA;

    To remove the live microphone source as a cause of the problem, and to make the problematic code easier for others to run/test, I have removed the mic source and now just generate a pure tone as a sequence of input buffers.

    &#xA;

    All attempts to figure out the missing or mismatched or incorrect argument have just resulted in seeing documentation and examples that are the same as my code.

    &#xA;

    I would like to know from someone who has used PyAV successfully for mono audio what the correct method and parameters are for encoding mono frames into the mono stream.

    &#xA;

    The package used is av 10.0.0 installed with&#xA;pip3 install av --no-binary av&#xA;so it uses my package-manager provided ffmpeg library, which is version 4.2.7.

    &#xA;

    The problematic python code is :

    &#xA;

    #!/usr/bin/env python3&#xA;# -*- coding: utf-8 -*-&#xA;"""&#xA;Recreating an error 22 when encoding sound with PyAV.&#xA;&#xA;Created on Sun Feb 19 08:10:29 2023&#xA;@author: andrewm&#xA;"""&#xA;import typing&#xA;import sys&#xA;import math&#xA;import fractions&#xA;&#xA;import av&#xA;from av import AudioFrame&#xA;&#xA;""" Ensure some PyAudio constants are still defined without changing &#xA;    the PyAudio recording callback function and without depending &#xA;    on PyAudio simply for reproducing the PyAV bug [Errno 22] thrown in &#xA;    File "av/filter/context.pyx", line 89, in av.filter.context.FilterContext.push&#xA;"""&#xA;class PA_Stub():&#xA;    paContinue = True&#xA;    paComplete= False&#xA;&#xA;pyaudio = PA_Stub()&#xA;&#xA;&#xA;"""Generate pure tone at given frequency with amplitude 0...1.0 at &#xA;   sampling frewuency fs and beginning at phase offset &#x27;phase&#x27;.&#xA;   Returns the new phase after the sinusoid has cycled over the &#xA;   sampling window length.&#xA;"""&#xA;def generate_tone(&#xA;        freq:int, phase:float, amp:float, fs, samp_fmt, buffer:bytearray&#xA;) -> float:&#xA;    assert samp_fmt == "s16", "Only s16 supported atm"&#xA;    samp_size_bytes = 2&#xA;    n_samples = int(len(buffer)/samp_size_bytes)&#xA;    window = [int(0) for i in range(n_samples)]&#xA;    theta = phase&#xA;    phase_inc = 2*math.pi * freq / fs&#xA;    for i in range(n_samples):&#xA;        v = amp * math.sin(theta)&#xA;        theta &#x2B;= phase_inc&#xA;        s = int((2**15-1)*v)&#xA;        window[i] = s&#xA;    for sample_i in range(len(window)):&#xA;        byte_i = sample_i * samp_size_bytes&#xA;        enc = window[sample_i].to_bytes(&#xA;                2, byteorder=sys.byteorder, signed=True&#xA;        )&#xA;        buffer[byte_i] = enc[0]&#xA;        buffer[byte_i&#x2B;1] = enc[1]&#xA;    return theta&#xA;&#xA;&#xA;channels = 1&#xA;fs = 44100  # Record at 44100 samples per second&#xA;fft_size_samps = 256&#xA;chunk_samps = fft_size_samps * 10  # Record in chunks that are multiples of fft windows.&#xA;&#xA;# print(f"fft_size_samps={fft_size_samps}\nchunk_samps={chunk_samps}")&#xA;&#xA;seconds = 3.0&#xA;out_filename = "testoutput.wav"&#xA;&#xA;# Store data in chunks for 3 seconds&#xA;sample_limit = int(fs * seconds)&#xA;sample_len = 0&#xA;frames = []  # Initialize array to store frames&#xA;&#xA;ffmpeg_codec_name = &#x27;mp2&#x27;  # flac, mp3, or libvorbis make same error.&#xA;&#xA;sample_size_bytes = 2&#xA;buffer = bytearray(int(chunk_samps*sample_size_bytes))&#xA;chunkperiod = chunk_samps / fs&#xA;total_chunks = int(math.ceil(seconds / chunkperiod))&#xA;phase = 0.0&#xA;&#xA;### uncomment if you want to see the synthetic data being used as a mic input.&#xA;# with open("test.raw","wb") as raw_out:&#xA;#     for ci in range(total_chunks):&#xA;#         phase = generate_tone(2600, phase, 0.8, fs, "s16", buffer)&#xA;#         raw_out.write(buffer)&#xA;# print("finished gen test")&#xA;# sys.exit(0)&#xA;# #---- &#xA;&#xA;# Using mp2 or mkv as the container format gets the same error.&#xA;with av.open(out_filename&#x2B;&#x27;.mp2&#x27;, "w", format="mp2") as output_con:&#xA;    output_con.metadata["title"] = "My title"&#xA;    output_con.metadata["key"] = "value"&#xA;    channel_layout = "mono"&#xA;    sample_fmt = "s16p"&#xA;&#xA;    ostream = output_con.add_stream(ffmpeg_codec_name, fs, layout=channel_layout)&#xA;    assert ostream is not None, "No stream!"&#xA;    cctx = ostream.codec_context&#xA;    cctx.sample_rate = fs&#xA;    cctx.time_base = fractions.Fraction(numerator=1,denominator=fs)&#xA;    cctx.format = sample_fmt&#xA;    cctx.channels = channels&#xA;    cctx.layout = channel_layout&#xA;    print(cctx, f"layout#{cctx.channel_layout}")&#xA;    &#xA;    # Define PyAudio-style callback for recording plus PyAV transcoding.&#xA;    def rec_callback(in_data, frame_count, time_info, status):&#xA;        global sample_len&#xA;        global ostream&#xA;        frames.append(in_data)&#xA;        nsamples = int(len(in_data) / (channels*sample_size_bytes))&#xA;        &#xA;        frame = AudioFrame(format=sample_fmt, layout=channel_layout, samples=nsamples)&#xA;        frame.sample_rate = fs&#xA;        frame.time_base = fractions.Fraction(numerator=1,denominator=fs)&#xA;        frame.pts = sample_len&#xA;        frame.planes[0].update(in_data)&#xA;        print(frame, len(in_data))&#xA;        &#xA;        for out_packet in ostream.encode(frame):&#xA;            output_con.mux(out_packet)&#xA;        for out_packet in ostream.encode(None):&#xA;            output_con.mux(out_packet)&#xA;        &#xA;        sample_len &#x2B;= nsamples&#xA;        retflag = pyaudio.paContinue if sample_lencode>

    &#xA;

    If you uncomment the RAW output part you will find the generated data can be imported as PCM s16 Mono 44100Hz into Audacity and plays the expected tone, so the generated audio data does not seem to be the problem.

    &#xA;

    The normal program console output up until the exception is :

    &#xA;

    mp2 at 0x7f8e38202cf0> layout#4&#xA;Beginning&#xA; 5120&#xA;. 5120&#xA;

    &#xA;

    The stack trace is :

    &#xA;

    Traceback (most recent call last):&#xA;&#xA;  File "Dev/multichan_recording/av_encode.py", line 147, in <module>&#xA;    ret_data, ret_flag = rec_callback(buffer, ci, {}, 1)&#xA;&#xA;  File "Dev/multichan_recording/av_encode.py", line 121, in rec_callback&#xA;    for out_packet in ostream.encode(frame):&#xA;&#xA;  File "av/stream.pyx", line 153, in av.stream.Stream.encode&#xA;&#xA;  File "av/codec/context.pyx", line 484, in av.codec.context.CodecContext.encode&#xA;&#xA;  File "av/audio/codeccontext.pyx", line 42, in av.audio.codeccontext.AudioCodecContext._prepare_frames_for_encode&#xA;&#xA;  File "av/audio/resampler.pyx", line 101, in av.audio.resampler.AudioResampler.resample&#xA;&#xA;  File "av/filter/graph.pyx", line 211, in av.filter.graph.Graph.push&#xA;&#xA;  File "av/filter/context.pyx", line 89, in av.filter.context.FilterContext.push&#xA;&#xA;  File "av/error.pyx", line 336, in av.error.err_check&#xA;&#xA;ValueError: [Errno 22] Invalid argument&#xA;&#xA;</module>

    &#xA;

    edit : It's interesting that the error happens on the 2nd AudioFrame, as apparently the first one was encoded okay, because they are given the same attribute values aside from the Presentation Time Stamp (pts), but leaving this out and letting PyAV/ffmpeg generate the PTS by itself does not fix the error, so an incorrect PTS does not seem the cause.

    &#xA;

    After a brief glance in av/filter/context.pyx the exception must come from a bad return value from res = lib.av_buffersrc_write_frame(self.ptr, frame.ptr)
    &#xA;Trying to dig into av_buffersrc_write_frame from the ffmpeg source it is not clear what could be causing this error. The only obvious one is a mismatch between channel layouts, but my code is setting the layout the same in the Stream and the Frame. That problem had been found by an old question pyav - cannot save stream as mono and their answer (that one parameter required is undocumented) is the only reason the code now has the layout='mono' argument when making the stream.

    &#xA;

    The program output shows layout #4 is being used, and from https://github.com/FFmpeg/FFmpeg/blob/release/4.2/libavutil/channel_layout.h you can see this is the value for symbol AV_CH_FRONT_CENTER which is the only channel in the MONO layout.

    &#xA;

    The mismatch is surely some other object property or an undocumented parameter requirement.

    &#xA;

    How do you encode mono audio to a compressed stream with PyAV ?

    &#xA;