Recherche avancée

Médias (10)

Mot : - Tags -/wav

Autres articles (87)

Sur d’autres sites (15906)

  • Playing RTP stream on Android 4.1.2 (Jelly Bean) [closed]

    27 décembre 2024, par Homie_Tomie

    I'll try to keep it quick. Using FFMPEG I started a stream on my PC. Here is the code :

    


    import subprocess

def start_stream():
    command = [
        'ffmpeg',
        '-f', 'gdigrab',  # Desktop capture (Windows)
        '-framerate', '15',  # Low framerate for higher performance
        '-i', 'desktop',  # Capture desktop
        '-c:v', 'libx264',  # Video codec (H.264)
        '-preset', 'ultrafast',  # Ultra-fast encoding preset for minimal latency
        '-tune', 'zerolatency',  # Zero latency for real-time streaming
        '-x264opts', 'keyint=15:min-keyint=15:no-scenecut',  # Frequent keyframes
        '-b:v', '500k',  # Low bitrate to minimize data usage and reduce latency
        '-s', '800x480',  # Resolution fits phone screen and helps performance
        '-max_delay', '0',  # No buffering, instant frame output
        '-flush_packets', '1',  # Flush packets immediately after encoding
        '-f', 'rtp',  # Use mpegts as the container for RTP stream
        'rtp://192.168.72.26:1234',  # Stream over UDP to localhost on port 1234
        '-sdp_file', 'stream.sdp'  # Create SDP file
    ]
    
    try:
        print("Starting stream...")
        subprocess.run(command, check=True)
    except subprocess.CalledProcessError as e:
        print(f"Error occurred: {e}")
    except KeyboardInterrupt:
        print("\nStream interrupted")

if __name__ == "__main__":
    print("Starting screen capture...")
    start_stream()


    


    Now, when I start the stream I can connect to it in VLC when I open up the stream.sdp file. Using the same method I can open up the stream on my iPhone, but when I try to open it on my old Android phone the stream connects but the screen is black. However, when I turn the screen I can see the first frame that was sent to the phone. Why does the stream not work ?

    


    I will be thankful for any and all advice :)

    


  • FFmpeg c api create encoder for AV_CODEC_ID_H264 crash on Windows

    30 avril 2023, par Guanyuming He

    I'm using ffmpeg (version 5.1.2) to clip a mp4 video per frame so I need to decode and encode it. However, when I'm creating the encoder for its video stream, the program always crashes at the call to avio_open2(), after H264 gives this error message :

    


    [h264_mf @ 0000025C1EBC1900] could not set output type (80004005)


    


    enter image description here

    


    The configuration (time_base, pix_fmt, width, height) of the codec context of the encoder is copied from the decoder, and I checked if the pixel format is supported by finding if it's in codec->pix_fmts.

    


    I find that the problem does not involve all my other pieces of code, because this minimal program can duplicate the same problem :

    


    extern "C"&#xA;{&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;}&#xA;&#xA;int main()&#xA;{&#xA;    auto codec = avcodec_find_encoder(AV_CODEC_ID_H264);&#xA;    auto codec_ctx = avcodec_alloc_context3(codec);&#xA;&#xA;    codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P;&#xA;    codec_ctx->width = 2560;&#xA;    codec_ctx->height = 1440;&#xA;    codec_ctx->time_base.num = 1; codec_ctx->time_base.den = 180000;&#xA;&#xA;    avcodec_open2(codec_ctx, codec, NULL);&#xA;&#xA;    return 0;&#xA;}&#xA;

    &#xA;

    Then I suspect if it's a bug of ffmpeg. My environment is Windows 11 64-bit, Visual Studio 2022. The ffmpeg library is obtained from vcpkg, as shown in the following image :

    &#xA;

    enter image description here

    &#xA;

  • matplotlib 3D linecollection animation gets slower over time

    15 juin 2021, par Vignesh Desmond

    I'm trying to animate a 3d line plot for attractors, using Line3DCollection. The animation is initally fast but it gets progressively slower over time. A minimal example of my code :

    &#xA;

    def generate_video(nframes):&#xA;&#xA;    fig = plt.figure(figsize=(16, 9), dpi=120)&#xA;    canvas_width, canvas_height = fig.canvas.get_width_height()&#xA;    ax = fig.add_axes([0, 0, 1, 1], projection=&#x27;3d&#x27;)&#xA;&#xA;    X = np.random.random(nframes)&#xA;    Y = np.random.random(nframes)&#xA;    Z = np.random.random(nframes)&#xA;&#xA;    cmap = plt.cm.get_cmap("hsv")&#xA;    line = Line3DCollection([], cmap=cmap)&#xA;    ax.add_collection3d(line)&#xA;    line.set_segments([])&#xA;&#xA;    def update(frame):&#xA;        i = frame % len(vect.X)&#xA;        points = np.array([vect.X[:i], vect.Y[:i], vect.Z[:i]]).transpose().reshape(-1,1,3)&#xA;        segs = np.concatenate([points[:-1],points[1:]],axis=1)&#xA;        line.set_segments(segs)&#xA;        line.set_array(np.array(vect.Y)) # Color gradient&#xA;        ax.elev &#x2B;= 0.0001&#xA;        ax.azim &#x2B;= 0.1&#xA;&#xA;    outf = &#x27;test.mp4&#x27;&#xA;    cmdstring = (&#x27;ffmpeg&#x27;, &#xA;                    &#x27;-y&#x27;, &#x27;-r&#x27;, &#x27;60&#x27;, # overwrite, 1fps&#xA;                    &#x27;-s&#x27;, &#x27;%dx%d&#x27; % (canvas_width, canvas_height),&#xA;                    &#x27;-pix_fmt&#x27;, &#x27;argb&#x27;,&#xA;                    &#x27;-f&#x27;, &#x27;rawvideo&#x27;,  &#x27;-i&#x27;, &#x27;-&#x27;,&#xA;                    &#x27;-b:v&#x27;, &#x27;5000k&#x27;,&#x27;-vcodec&#x27;, &#x27;mpeg4&#x27;, outf)&#xA;    p = subprocess.Popen(cmdstring, stdin=subprocess.PIPE)&#xA;&#xA;    for frame in range(nframes):&#xA;        update(frame)&#xA;        fig.canvas.draw()&#xA;        string = fig.canvas.tostring_argb()&#xA;        p.stdin.write(string)&#xA;&#xA;    p.communicate()&#xA;&#xA;generate_video(nframes=10000)&#xA;

    &#xA;

    I used the code from this answer to save the animation to mp4 using ffmpeg instead of anim.FuncAnimation as its much faster for me. But both methods get slower over time and I'm not sure how to make the animation not become slower. Any advice is welcome.

    &#xA;

    Versions :&#xA;Matplotlib : 3.4.2&#xA;FFMpeg : 4.2.4-1ubuntu0.1

    &#xA;