Recherche avancée

Médias (91)

Autres articles (102)

  • Multilang : améliorer l’interface pour les blocs multilingues

    18 février 2011, par

    Multilang est un plugin supplémentaire qui n’est pas activé par défaut lors de l’initialisation de MediaSPIP.
    Après son activation, une préconfiguration est mise en place automatiquement par MediaSPIP init permettant à la nouvelle fonctionnalité d’être automatiquement opérationnelle. Il n’est donc pas obligatoire de passer par une étape de configuration pour cela.

  • L’agrémenter visuellement

    10 avril 2011

    MediaSPIP est basé sur un système de thèmes et de squelettes. Les squelettes définissent le placement des informations dans la page, définissant un usage spécifique de la plateforme, et les thèmes l’habillage graphique général.
    Chacun peut proposer un nouveau thème graphique ou un squelette et le mettre à disposition de la communauté.

  • Possibilité de déploiement en ferme

    12 avril 2011, par

    MediaSPIP peut être installé comme une ferme, avec un seul "noyau" hébergé sur un serveur dédié et utilisé par une multitude de sites différents.
    Cela permet, par exemple : de pouvoir partager les frais de mise en œuvre entre plusieurs projets / individus ; de pouvoir déployer rapidement une multitude de sites uniques ; d’éviter d’avoir à mettre l’ensemble des créations dans un fourre-tout numérique comme c’est le cas pour les grandes plate-formes tout public disséminées sur le (...)

Sur d’autres sites (8016)

  • How do I use the FFmpeg libraries to extract every nth frame from a video and save it as a small image file in C++ ?

    1er novembre 2022, par Panchs

    After experimenting with the examples on the FFmpeg documentation, I was finally able to create a short program that extracts every nth frame from a video. However, the output files that it produces are huge at over 15mb for each image. How can I change this to produce lower quality images ?

    


    The result I am trying to get is done easily on the command line with :

    


    ffmpeg -i [input video] -vf "select=not(mod(n\,10))" -fps_mode vfr img_%03d.jpg

    


    For a video with about 500 frames, this creates 50 images that are only about 800kb each ; how am would I be able to mimic this in my program ?

    


    My code consists of opening the input file, decoding the packets, then saving the frames :

    


    #include <cstdio>&#xA;#include <cstdlib>&#xA;#include <iostream>&#xA;&#xA;extern "C" {&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;#include <libavformat></libavformat>avformat.h>&#xA;#include <libavfilter></libavfilter>buffersink.h>&#xA;#include <libavfilter></libavfilter>buffersrc.h>&#xA;#include <libavutil></libavutil>opt.h>&#xA;#include <libswscale></libswscale>swscale.h>&#xA;}&#xA;&#xA;static AVFormatContext *fmt_ctx;&#xA;static AVCodecContext *dec_ctx;&#xA;static int video_stream_index = -1;&#xA;&#xA;// OPEN THE INPUT FILE&#xA;static int open_input_file(const char *filename) {&#xA;    // INIT VARS AND FFMPEG OBJECTS&#xA;    int ret;&#xA;    const AVCodec *dec;&#xA;&#xA;    // OPEN INPUT FILE&#xA;    if((ret = avformat_open_input(&amp;fmt_ctx, filename, NULL, NULL)) &lt; 0) {&#xA;        printf("ERROR: failed to open input file\n");&#xA;        return ret;&#xA;    }&#xA;&#xA;    // FIND STREAM INFO BASED ON INPUT FILE&#xA;    if((ret = avformat_find_stream_info(fmt_ctx, NULL)) &lt; 0) {&#xA;        printf("ERROR: failed to find stream information\n");&#xA;        return ret;&#xA;    }&#xA;&#xA;    // FIND THE BEST VIDEO STREAM FOR THE INPUT FILE&#xA;    ret = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, &amp;dec, 0);&#xA;    if(ret &lt; 0) {&#xA;        printf("ERROR: failed to find a video stream in the input file\n");&#xA;        return ret;&#xA;    }&#xA;    video_stream_index = ret;&#xA;&#xA;    // ALLOCATE THE DECODING CONTEXT FOR THE INPUT FILE&#xA;    dec_ctx = avcodec_alloc_context3(dec);&#xA;    if(!dec_ctx) {&#xA;        printf("ERROR: failed to allocate decoding context\n");&#xA;        // CAN NOT ALLOCATE MEMORY ERROR&#xA;        return AVERROR(ENOMEM);&#xA;    }&#xA;    avcodec_parameters_to_context(dec_ctx, fmt_ctx->streams[video_stream_index]->codecpar);&#xA;&#xA;    // INIT THE VIDEO DECODER&#xA;    if((ret = avcodec_open2(dec_ctx, dec, NULL)) &lt; 0) {&#xA;        printf("ERROR: failed to open video decoder\n");&#xA;        return ret;&#xA;    }&#xA;&#xA;    return 0;&#xA;}&#xA;&#xA;// SAVE THE FILE&#xA;static void save(unsigned char *buf, int wrap, int x_size, int y_size, char *file_name) {&#xA;    // INIT THE EMPTY FILE&#xA;    FILE *file;&#xA;&#xA;    // OPEN AND WRITE THE IMAGE FILE&#xA;    file = fopen(file_name, "wb");&#xA;    fprintf(file, "P6\n%d %d\n%d\n", x_size, y_size, 255);&#xA;    for(int i = 0; i &lt; y_size; i&#x2B;&#x2B;) {&#xA;        fwrite(buf &#x2B; i * wrap, 1, x_size * 3, file);&#xA;    }&#xA;    fclose(file);&#xA;}&#xA;&#xA;// DECODE FRAME AND CONVERT IT TO AN RGB IMAGE&#xA;static void decode(AVCodecContext *cxt, AVFrame *frame, AVPacket *pkt,&#xA;                   const char *out_file_name, const char *file_ext, int mod=1) {&#xA;    // INIT A BLANK CHAR TO HOLD THE FILE NAME AND AN EMPTY INT TO HOLD FUNCTION RETURN VALUES&#xA;    char buf[1024];&#xA;    int ret;&#xA;&#xA;    // SEND PACKET TO DECODER&#xA;    ret = avcodec_send_packet(cxt, pkt);&#xA;    if(ret &lt; 0) {&#xA;        printf("ERROR: error sending packet for decoding\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    // CREATE A SCALAR CONTEXT FOR CONVERSION&#xA;    SwsContext *sws_ctx = sws_getContext(dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt, dec_ctx->width,&#xA;                                         dec_ctx->height, AV_PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);&#xA;&#xA;    // CREATE A NEW RGB FRAME FOR CONVERSION&#xA;    AVFrame* rgb_frame = av_frame_alloc();&#xA;    rgb_frame->format = AV_PIX_FMT_RGB24;&#xA;    rgb_frame->width = dec_ctx->width;&#xA;    rgb_frame->height = dec_ctx->height;&#xA;&#xA;    // ALLOCATE A NEW BUFFER FOR THE RGB CONVERSION FRAME&#xA;    av_frame_get_buffer(rgb_frame, 0);&#xA;&#xA;    // WHILE RETURN COMES BACK OKAY (FUNCTION RETURNS >= 0)...&#xA;    while(ret >= 0) {&#xA;        // GET FRAME BACK FROM DECODER&#xA;        ret = avcodec_receive_frame(cxt, frame);&#xA;        // IF "RESOURCE TEMP NOT AVAILABLE" OR "END OF FILE" ERROR...&#xA;        if(ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {&#xA;            return;&#xA;        } else if(ret &lt; 0) {&#xA;            printf("ERROR: error during decoding\n");&#xA;            exit(1);&#xA;        }&#xA;&#xA;        // IF FRAME NUMBER IF THE (MOD)TH FRAME...&#xA;        if(cxt->frame_number % mod == 0){&#xA;            // OUTPUT WHICH FRAME IS BEING SAVED&#xA;            printf("saving frame %03d\n", cxt->frame_number);&#xA;            // REMOVES TEMPORARY BUFFERED DATA&#xA;            fflush(stdout);&#xA;&#xA;            // SCALE (CONVERT) THE OLD FRAME TO THE NEW RGB FRAME&#xA;            sws_scale(sws_ctx, frame->data, frame->linesize, 0, frame->height,&#xA;                      rgb_frame->data, rgb_frame->linesize);&#xA;&#xA;            // SET "BUF" TO THE OUTPUT FILE PATH (SAVES TO "out_file_name_###.file_ext")&#xA;            snprintf(buf, sizeof(buf), "%s_%03d.%s", out_file_name, cxt->frame_number, file_ext);&#xA;            // SAVE THE FRAME&#xA;            save(rgb_frame->data[0], rgb_frame->linesize[0], rgb_frame->width, rgb_frame->height, buf);&#xA;        }&#xA;    }&#xA;}&#xA;&#xA;int main() {&#xA;    // SIMULATE COMMAND LINE ARGUMENTS&#xA;    char argv0[] = "test";&#xA;    char argv1[] = "/User/Desktop/frames/test_video.mov";&#xA;    char *argv[] = {argv0, argv1, nullptr};&#xA;&#xA;    // INIT VARS AND FFMPEG OBJECTS&#xA;    int ret;&#xA;    AVPacket *packet;&#xA;    AVFrame *frame;&#xA;&#xA;    // ALLOCATE FRAME AND PACKET&#xA;    frame = av_frame_alloc();&#xA;    packet = av_packet_alloc();&#xA;    if (!frame || !packet) {&#xA;        fprintf(stderr, "Could not allocate frame or packet\n");&#xA;        exit(1);&#xA;    }&#xA;&#xA;    // IF FILE DOESN&#x27;T OPEN, GO TO THE END&#xA;    if((ret = open_input_file(argv[1])) &lt; 0) {&#xA;        goto end;&#xA;    }&#xA;    &#xA;    // READ ALL THE PACKETS - simple&#xA;    while(av_read_frame(fmt_ctx, packet) >= 0) {&#xA;        // IF PACKET INDEX MATCHES VIDEO INDEX...&#xA;        if (packet->stream_index == video_stream_index) {&#xA;            // SEND PACKET TO THE DECODER and SAVE&#xA;            std::string name = "/User/Desktop/frames/img";&#xA;            std::string ext = "bmp";&#xA;            decode(dec_ctx, frame, packet, name.c_str(), ext.c_str(), 5);&#xA;        }&#xA;&#xA;        // UNREFERENCE THE PACKET&#xA;        av_packet_unref(packet);&#xA;    }&#xA;&#xA;    // END MARKER&#xA;    end:&#xA;    avcodec_free_context(&amp;dec_ctx);&#xA;    avformat_close_input(&amp;fmt_ctx);&#xA;    av_frame_free(&amp;frame);&#xA;    av_packet_free(&amp;packet);&#xA;&#xA;    // FINAL ERROR CATCH&#xA;    if (ret &lt; 0 &amp;&amp; ret != AVERROR_EOF) {&#xA;        fprintf(stderr, "Error occurred: %s\n", av_err2str(ret));&#xA;        exit(1);&#xA;    }&#xA;&#xA;    exit(0);&#xA;}&#xA;</iostream></cstdlib></cstdio>

    &#xA;

    I am not sure how to go about producing images that are much smaller in size like the ones produced on the command line. I have a feeling that this is possible somehow during the conversion to RGB or the saving of the file but I can't seem to figure out how.

    &#xA;

    Also, is there any way that I could go about this much more efficiently ? On the command line, this finishes very quickly (no more than a second or two for a 9 sec. movie at 60 fps).

    &#xA;

  • Flutter FFmpeg | Concat Multiple Videos From TXT File And Save As A Video

    7 mai 2023, par Muhammad Hassan

    I have a text file with all path of video files that I want to concat using&#xA;https://pub.dev/packages/ffmpeg_kit_flutter in my flutter app.

    &#xA;

    For this purpose, I write a file my_file.txt with the below data...

    &#xA;

    /data/user/0/com.example.video_merger/cache/75f72300-1203-4e2c-93cf-65777152f1d16524788775537818173.mp4&#xA;/data/user/0/com.example.video_merger/cache/318d5ea7-3e0c-4453-903b-06966aa86f348487775694692938421.mp4&#xA;

    &#xA;

    Now I am using the below code to merge all the upper videos.

    &#xA;

    String outputPath = "/data/user/0/com.example.video_merger/app_flutter/output.mp4";&#xA;String commandToExecute = &#x27;-f concat -i $rawDocumentPath/my_file.txt -c copy $outputPath&#x27;;&#xA;FFmpegKit.execute(commandToExecute).then((session) async {&#xA;  final returnCode = await session.getReturnCode();&#xA;  print("FFmpeg Process Exited With ReturnCode = $returnCode");&#xA;  GallerySaver.saveVideo(outputPath).then((_) {&#xA;    print("Merged Video Saved");&#xA;  });&#xA;  if (ReturnCode.isSuccess(returnCode)) {&#xA;    // SUCCESS&#xA;  } else if (ReturnCode.isCancel(returnCode)) {&#xA;    // CANCEL&#xA;  } else {&#xA;    // ERROR&#xA;  }&#xA;});&#xA;

    &#xA;

    But it is giving me error as shown below...

    &#xA;

    FFmpeg Process Exited With ReturnCode = 1 &#xA;E/GallerySaver(31493): /data/user/0/com.example.video_merger/app_flutter/output.mp4: open failed: ENOENT (No such file or directory)&#xA;

    &#xA;

    But when I use the below ffmpeg command directly without reading from text file works fine and save my video.

    &#xA;

    String commandToExecute = &#x27;-y -i ${_storedVideoOne!.path} -i ${_storedVideoTwo!.path} -r 24000/1001 -filter_complex \&#x27;[0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[out]\&#x27; -map \&#x27;[out]\&#x27; $outputPath&#x27;;&#xA;

    &#xA;

    Now my question is that I will have dynamic number of videos to concat so I want to use text file where I will write all paths then will make merged video from them. So what is the error in my ffmpeg command...???

    &#xA;

    Log Report :

    &#xA;

    I used the log reporting as follows to get the below output of errors...

    &#xA;

        FFmpegKit.executeAsync(&#xA;      commandToExecute2,&#xA;          (session) async {&#xA;            final returnCode = await session.getReturnCode();&#xA;            print("FFmpeg Process Exited With ReturnCode = $returnCode");&#xA;            GallerySaver.saveVideo(outputPath).then((_) async {&#xA;              print("Merged Video Saved");&#xA;            });&#xA;            if (ReturnCode.isSuccess(returnCode)) {&#xA;              // SUCCESS&#xA;            } else if (ReturnCode.isCancel(returnCode)) {&#xA;              // CANCEL&#xA;            } else {&#xA;              // ERROR&#xA;            }&#xA;          },&#xA;          (log) {&#xA;        print("XXXXXXXXXXXX fFmpeg XXXXXXXXXX ${log.getMessage()}");&#xA;      },&#xA;    );&#xA;

    &#xA;

    And here is the Log Output...

    &#xA;

    I/flutter ( 5432): Text On File: /data/user/0/com.example.video_merger/cache/75f72300-1203-4e2c-93cf-65777152f1d16524788775537818173.mp4&#xA;I/flutter ( 5432): /data/user/0/com.example.video_merger/cache/318d5ea7-3e0c-4453-903b-06966aa86f348487775694692938421.mp4&#xA;I/flutter ( 5432): XXXXXXXXXXXX fFmpeg XXXXXXXXXX ffmpeg version n5.1.2&#xA;I/flutter ( 5432): XXXXXXXXXXXX fFmpeg XXXXXXXXXX Copyright (c) 2000-2022 the FFmpeg developers&#xA;I/flutter ( 5432): XXXXXXXXXXXX fFmpeg XXXXXXXXXX&#xA;I/flutter ( 5432): XXXXXXXXXXXX fFmpeg XXXXXXXXXX  built with Android (7155654, based on r399163b1) clang version 11.0.5 (https://android.googlesource.com/toolchain/llvm-project 87f1315dfbea7c137aa2e6d362dbb457e388158d)&#xA;I/flutter ( 5432): XXXXXXXXXXXX fFmpeg XXXXXXXXXX  configuration: --cross-prefix=aarch64-linux-android- --sysroot=/files/android-sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/sysroot --prefix=/home/taner/Projects/ffmpeg-kit/prebuilt/android-arm64/ffmpeg --pkg-config=/usr/bin/pkg-config --enable-version3 --arch=aarch64 --cpu=armv8-a --target-os=android --enable-neon --enable-asm --enable-inline-asm --ar=aarch64-linux-android-ar --cc=aarch64-linux-android24-clang --cxx=aarch64-linux-android24-clang&#x2B;&#x2B; --ranlib=aarch64-linux-android-ranlib --strip=aarch64-linux-android-strip --nm=aarch64-linux-android-nm --extra-libs=&#x27;-L/home/taner/Projects/ffmpeg-kit/prebuilt/android-arm64/cpu-features/lib -lndk_compat&#x27; --disable-autodetect --enable-cross-compile --enable-pic --enable-jni --enable-optimizations --enable-swscale --disable-static --enable-shared --enable-pthreads --enable-v4l2-m2m --disable-outdev=fbdev --disable-indev=fbdev --enable-small --disable-xmm-clobber-test --disable-debug --enable-lto --disable-neon-clobber-t&#xA;I/flutter ( 5432): XXXXXXXXXXXX fFmpeg XXXXXXXXXX  libavutil      57. 28.100 / 57. 28.100&#xA;I/flutter ( 5432): XXXXXXXXXXXX fFmpeg XXXXXXXXXX  libavcodec     59. 37.100 / 59. 37.100&#xA;I/flutter ( 5432): XXXXXXXXXXXX fFmpeg XXXXXXXXXX  libavformat    59. 27.100 / 59. 27.100&#xA;I/flutter ( 5432): XXXXXXXXXXXX fFmpeg XXXXXXXXXX  libavdevice    59.  7.100 / 59.  7.100&#xA;I/flutter ( 5432): XXXXXXXXXXXX fFmpeg XXXXXXXXXX  libavfilter     8. 44.100 /  8. 44.100&#xA;I/flutter ( 5432): XXXXXXXXXXXX fFmpeg XXXXXXXXXX  libswscale      6.  7.100 /  6.  7.100&#xA;I/flutter ( 5432): XXXXXXXXXXXX fFmpeg XXXXXXXXXX  libswresample   4.  7.100 /  4.  7.100&#xA;I/flutter ( 5432): XXXXXXXXXXXX fFmpeg XXXXXXXXXX [concat @ 0xb400007d62447910] Line 1: unknown keyword &#x27;/data/user/0/com.example.video_merger/cache/75f72300-1203-4e2c-93cf-65777152f1d16524788775537818173.mp4&#x27;&#xA;I/flutter ( 5432): XXXXXXXXXXXX fFmpeg XXXXXXXXXX /data/user/0/com.example.video_merger/app_flutter/my_file.txt: Invalid data found when processing input&#xA;I/flutter ( 5432): FFmpeg Process Exited With ReturnCode = 1&#xA;

    &#xA;

  • FFmpeg does not save the mp4 clips to file

    31 janvier 2021, par oo92

    I'm using the FFmpeg Python library to save 60-second mp4 clips to a .mp4 file from Twitch live streams using its API. This is my code :

    &#xA;

    current_dir = os.getcwd()&#xA;&#xA;client = TwitchClient(client_id=&#x27;&#x27;)&#xA;streams_now = client.streams.get_live_streams(limit=100, offset=900)&#xA;epoch = str(math.ceil(time.time()))&#xA;&#xA;if not os.path.exists(current_dir &#x2B; &#x27;/twitch_videos/&#x27;):&#xA;    os.mkdir(current_dir &#x2B; &#x27;/twitch_videos/&#x27;)&#xA;&#xA;for i in range(0, 100):&#xA;    try:&#xA;        username = streams_now[i][&#x27;channel&#x27;][&#x27;name&#x27;]&#xA;        id = streams_now[i][&#x27;id&#x27;]&#xA;        game = streams_now[i][&#x27;game&#x27;]&#xA;        game = game.translate(str.maketrans({&#x27;:&#x27;: &#x27;-&#x27;, &#x27; &#x27;: &#x27;-&#x27;, "&#x27;": &#x27;&#x27;, &#x27;!&#x27;: &#x27;&#x27;, &#x27;&amp;&#x27;: &#x27;_&#x27;, &#x27;.&#x27;: &#x27;&#x27;, &#x27;&#x2B;&#x27;: &#x27;_&#x27;}))&#xA;        streaming = streamlink.streams(&#x27;http://twitch.tv/&#x27; &#x2B; username)&#xA;        stream = streaming["best"].url&#xA;&#xA;        twitch_stream = ffmpeg.input(stream)&#xA;&#xA;        twitch_stream = ffmpeg.filter(twitch_stream,&#xA;                                      &#x27;fps&#x27;,&#xA;                                      fps=1,&#xA;                                      round=&#x27;up&#x27;)&#xA;&#xA;        twitch_stream = ffmpeg.output(twitch_stream,&#xA;                                      current_dir &#x2B; &#x27;/twitch_videos/&#x27; &#x2B; &#x27;%d_&#x27; &#x2B; username &#x2B; &#x27;_&#x27; &#x2B; epoch &#x2B; &#x27;.mp4&#x27;,&#xA;                                      sc_threshold=&#x27;0&#x27;,&#xA;                                      g=&#x27;60&#x27;,&#xA;                                      f=&#x27;segment&#x27;,&#xA;                                      segment_time=&#x27;600&#x27;,&#xA;                                      segment_format_options=&#x27;movflags=&#x2B;faststart&#x27;,&#xA;                                      reset_timestamps=&#x27;1&#x27;)frl3dqgn21bbpp6tajjvg5pdevczac&#xA;        ffmpeg.run(twitch_stream)&#xA;&#xA;&#xA;    except:&#xA;        pass&#xA;

    &#xA;

    I am concatenating the path it should go to the name of the file but the folder is empty after I take a look. The reason why its in the try-catch block is because some streams do not have the best tag so I want to skip those.

    &#xA;

    Update

    &#xA;

    I put a bunch of print statements inside the try block and none of them get printed. I put similar if statements inside the except block and they are all printed. This means that there is something wrong with my code inside the try block. This tells me that the code inside the try block never gets executed.

    &#xA;