Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • ffmpeg video slideshow script with vertical stack transition ?

    11 mai 2019, par Trần Công Trường

    I have cmd: ffmpeg -y -r 1/5 -i "C:\test\a\%0d.jpg" -r 24 "C:\test\out.mp4" I want slideshow script with vertical stack transition. Similar to the video below: https://www.youtube.com/watch?v=3G47V5EDJZw . Thanks

  • Mosaic of multiple thumbnails with ffmpeg

    11 mai 2019, par Bruno Andrade

    I'm trying to do something like this image (without the header) using only FFMPEG.

    Expected result

    I use this code and I get very close to the result

    ffmpeg -ss 00:02:45 -i test.mp4 -an -frames 1 -vf "select=not(mod(n\,1000)),scale=242:140,tile=4x4,scale=950:-1" out91.png
    
    1. I can not set the time of the thumbnail

    2. I can not make thumbnails a good representation of the video. I wish the miniatures were from the beginning middle and end. Skipping some part of the beginning not to catch the introduction. Skipping a part of the end to not get the credits. Currently the miniatures end before the video,

  • How to transcode raw uncompressed RTP to an H264 RTSP stream

    10 mai 2019, par Gino

    I am new to streaming and am trying to figure out how to transcode streams via ffmpeg.

    I have a few raw rtp uncompressed streams where some are on address 239.x.x.x and others are on 169.x.x.x.

    I want to setup an RTSP server to grab those streams and transcode them into H264 and stream them out to a new address and port.

    I have tried some ffmpeg commands but I keep getting errors about having to compile ffmpeg with pthreads.

    I have no idea how to do that so does anyone know what commands I can use that will work with the current windows version of ffmpeg?

    For now, I am just trying to save the stream to a file to see if that works. Command I am using is:

    ffmpeg -i rtp://224.1.1.10:6972 transcoded test.mp4
    

    and the return I get in the command line is

    ffmpeg version 4.1.3 Copyright (c) 2000-2019 the FFmpeg developers
      built with gcc 8.3.1 (GCC) 20190414
      configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
      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
      libswscale      5.  3.100 /  5.  3.100
      libswresample   3.  3.100 /  3.  3.100
      libpostproc    55.  3.100 / 55.  3.100
    
    [udp @ 000002cb292abf40] 'circular_buffer_size' option was set but it is not supported on this build (pthread support is required)  
    [udp @ 000002cb292bc200] 'circular_buffer_size' option was set but it is not supported on this build (pthread support is required)  
    rtp://224.1.1.10:6972: Immediate exit requested  
    Exiting normally, received signal 2.
    
  • How to encode using the FFMpeg in Android (using H263)

    10 mai 2019, par Kenny910

    I am trying to follow the sample code on encoding in the ffmpeg document and successfully build a application to encode and generate a mp4 file but I face the following problems:

    1) I am using the H263 for encoding but I can only set the width and height of the AVCodecContext to 176x144, for other case (like 720x480 or 640x480) it will return fail.

    2) I can't play the output mp4 file by using the default Android player, isn't it support H263 mp4 file? p.s. I can play it by using other player

    3) Is there any sample code on encoding other video frame to make a new video (which mean decode the video and encode it back in different quality setting, also i would like to modify the frame content)?

    Here is my code, thanks!

    JNIEXPORT jint JNICALL Java_com_ffmpeg_encoder_FFEncoder_nativeEncoder(JNIEnv* env, jobject thiz, jstring filename){
    
    LOGI("nativeEncoder()");
    
    avcodec_register_all();
    avcodec_init();
    av_register_all();
    
    AVCodec         *codec;
    AVCodecContext  *codecCtx;
    int             i;
    int             out_size;
    int             size;
    int             x;
    int             y;
    int             output_buffer_size;
    FILE            *file;
    AVFrame         *picture;
    uint8_t         *output_buffer;
    uint8_t         *picture_buffer;
    
    /* Manual Variables */
    int             l;
    int             fps = 30;
    int             videoLength = 5;
    
    /* find the H263 video encoder */
    codec = avcodec_find_encoder(CODEC_ID_H263);
    if (!codec) {
        LOGI("avcodec_find_encoder() run fail.");
    }
    
    codecCtx = avcodec_alloc_context();
    picture = avcodec_alloc_frame();
    
    /* put sample parameters */
    codecCtx->bit_rate = 400000;
    /* resolution must be a multiple of two */
    codecCtx->width = 176;
    codecCtx->height = 144;
    /* frames per second */
    codecCtx->time_base = (AVRational){1,fps};
    codecCtx->pix_fmt = PIX_FMT_YUV420P;
    codecCtx->codec_id = CODEC_ID_H263;
    codecCtx->codec_type = AVMEDIA_TYPE_VIDEO;
    
    /* open it */
    if (avcodec_open(codecCtx, codec) < 0) {
        LOGI("avcodec_open() run fail.");
    }
    
    const char* mfileName = (*env)->GetStringUTFChars(env, filename, 0);
    
    file = fopen(mfileName, "wb");
    if (!file) {
        LOGI("fopen() run fail.");
    }
    
    (*env)->ReleaseStringUTFChars(env, filename, mfileName);
    
    /* alloc image and output buffer */
    output_buffer_size = 100000;
    output_buffer = malloc(output_buffer_size);
    
    size = codecCtx->width * codecCtx->height;
    picture_buffer = malloc((size * 3) / 2); /* size for YUV 420 */
    
    picture->data[0] = picture_buffer;
    picture->data[1] = picture->data[0] + size;
    picture->data[2] = picture->data[1] + size / 4;
    picture->linesize[0] = codecCtx->width;
    picture->linesize[1] = codecCtx->width / 2;
    picture->linesize[2] = codecCtx->width / 2;
    
    for(l=0;l/encode 1 second of video
        for(i=0;i/prepare a dummy image YCbCr
            //Y
            for(y=0;yheight;y++) {
                for(x=0;xwidth;x++) {
                    picture->data[0][y * picture->linesize[0] + x] = x + y + i * 3;
                }
            }
    
            //Cb and Cr
            for(y=0;yheight/2;y++) {
                for(x=0;xwidth/2;x++) {
                    picture->data[1][y * picture->linesize[1] + x] = 128 + y + i * 2;
                    picture->data[2][y * picture->linesize[2] + x] = 64 + x + i * 5;
                }
            }
    
            //encode the image
            out_size = avcodec_encode_video(codecCtx, output_buffer, output_buffer_size, picture);
            fwrite(output_buffer, 1, out_size, file);
        }
    
        //get the delayed frames
        for(; out_size; i++) {
            out_size = avcodec_encode_video(codecCtx, output_buffer, output_buffer_size, NULL);
            fwrite(output_buffer, 1, out_size, file);
        }
    }
    
    //add sequence end code to have a real mpeg file
    output_buffer[0] = 0x00;
    output_buffer[1] = 0x00;
    output_buffer[2] = 0x01;
    output_buffer[3] = 0xb7;
    
    fwrite(output_buffer, 1, 4, file);
    fclose(file);
    free(picture_buffer);
    free(output_buffer);
    avcodec_close(codecCtx);
    av_free(codecCtx);
    av_free(picture);
    
    LOGI("finish");
    
    return 0; }
    
  • How can I get my saved mp4 to exactly match the output of plot.show() ?

    10 mai 2019, par Jimmy

    When I try to save the results of an animation to mp4 using ffmpeg, I am getting a jumbled mess.

    plt.show() shows exactly what I want it to show in the animation. However, when I save it using ffmpeg, the result is very different from what plt.show() returns. I have tried various arguments for fps etc. but nothing has helped.

    %matplotlib
    import pandas as pd
    import matplotlib as mpl ## uncomment this if you are running this on a Mac
    #mpl.use('TkAgg')         ## and want to use blit=True
    import matplotlib.pyplot as plt 
    import matplotlib.animation as animation 
    import numpy as np 
    import csv
    
    people = ('','Jim', 'Dan')
    plt.rcdefaults()
    fig, ax = plt.subplots()
    y_pos = np.arange(len(people))
    
    ax.set_xlim(0,10)
    ax.set_yticks(y_pos)
    ax.set_yticklabels(people)
    ax.invert_yaxis() 
    ax.set_xlabel('Skill')
    titleList=['Basketball','Hockey','Baseball']
    df=[[0,5,7],[0,4,9],[0,2,6]]
    def animate(i):
       # Example data
        while i<3:
            ax.set_yticks(y_pos)
            ax.set_yticklabels(people)
            ax.set_xlabel(titleList[i])
            performance=df[i]
    
            title = ax.text(0.5,0.95,str(titleList[i]), bbox={'facecolor':'w', 'alpha':0.5, 'pad':5},transform=ax.transAxes, ha="center")
    
            rects = ax.barh(y_pos, performance, align='center',
                    color='blue', ecolor='None')
            return [rect for rect in rects] + [title]
    
    
    ani = animation.FuncAnimation(fig,animate, frames=3, blit=True
                                ,interval=2000,repeat=False)
    
    plt.rcParams['animation.ffmpeg_path'] = 'C:\\ffmpeg\\bin\\ffmpeg.exe'
    Writer = animation.writers['ffmpeg']
    ani.save('test.mp4')
    plt.show() 
    

    The result is a very fast video where all the data gets written over (similar to the plt.show() results when blit=False).