Recherche avancée

Médias (1)

Mot : - Tags -/lev manovitch

Autres articles (12)

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

  • ANNEXE : Les extensions, plugins SPIP des canaux

    11 février 2010, par

    Un plugin est un ajout fonctionnel au noyau principal de SPIP. MediaSPIP consiste en un choix délibéré de plugins existant ou pas auparavant dans la communauté SPIP, qui ont pour certains nécessité soit leur création de A à Z, soit des ajouts de fonctionnalités.
    Les extensions que MediaSPIP nécessite pour fonctionner
    Depuis la version 2.1.0, SPIP permet d’ajouter des plugins dans le répertoire extensions/.
    Les "extensions" ne sont ni plus ni moins que des plugins dont la particularité est qu’ils se (...)

  • Le plugin : Gestion de la mutualisation

    2 mars 2010, par

    Le plugin de Gestion de mutualisation permet de gérer les différents canaux de mediaspip depuis un site maître. Il a pour but de fournir une solution pure SPIP afin de remplacer cette ancienne solution.
    Installation basique
    On installe les fichiers de SPIP sur le serveur.
    On ajoute ensuite le plugin "mutualisation" à la racine du site comme décrit ici.
    On customise le fichier mes_options.php central comme on le souhaite. Voilà pour l’exemple celui de la plateforme mediaspip.net :
    < ?php (...)

Sur d’autres sites (3542)

  • Decode mp3 using FFMpeg, Android NDK - What is wrong with my AVFormatContext ?

    27 février 2020, par michpohl

    I am trying to decode am MP3 file to a raw PCM stream using FFMpeg via JNI on Android. I have compiled the latest FFMpeg version (4.2) and added it to my app. This did not make any problems.
    The goal is to be able to use mp3 files from the device’s storage for playback with oboe

    Since I am relatively inexperienced with both C++ and FFMpeg, my approach is based upon this :
    oboe’s RhythmGame example

    I have based my FFMpegExtractorclass on the one found in the example here. With the help of StackOverflow the AAssetManageruse was removed and instead a MediaSource helper class now serves as a wrapper for my stream (see here)

    But unfortunately, creating the AVFormatContext doesn’t work right - and I can’t seem to understand why. Since I have very limited understanding of correct pointer usage and C++ memory management, I suspect it’s most likely I’m doing something wrong in that area. But honestly, I have no idea.

    This is my FFMpegExtractor.h :

    #define MYAPP_FFMPEGEXTRACTOR_H

    extern "C" {
    #include <libavformat></libavformat>avformat.h>
    #include <libswresample></libswresample>swresample.h>
    #include <libavutil></libavutil>opt.h>
    }

    #include <cstdint>
    #include <android></android>asset_manager.h>
    #include
    #include <fstream>
    #include "MediaSource.cpp"


    class FFMpegExtractor {
    public:

       FFMpegExtractor();

       ~FFMpegExtractor();

       int64_t decode2(char *filepath, uint8_t *targetData, AudioProperties targetProperties);

    private:
       MediaSource *mSource;

       bool createAVFormatContext(AVIOContext *avioContext, AVFormatContext **avFormatContext);

       bool openAVFormatContext(AVFormatContext *avFormatContext);

       int32_t cleanup(AVIOContext *avioContext, AVFormatContext *avFormatContext);

       bool getStreamInfo(AVFormatContext *avFormatContext);

       AVStream *getBestAudioStream(AVFormatContext *avFormatContext);

       AVCodec *findCodec(AVCodecID id);

       void printCodecParameters(AVCodecParameters *params);

       bool createAVIOContext2(const std::string &amp;filePath, uint8_t *buffer, uint32_t bufferSize,
                               AVIOContext **avioContext);
    };


    #endif //MYAPP_FFMPEGEXTRACTOR_H
    </fstream></cstdint>

    This is FFMPegExtractor.cpp :

    #include <memory>
    #include <oboe></oboe>Definitions.h>
    #include "FFMpegExtractor.h"
    #include "logging.h"
    #include <fstream>

    FFMpegExtractor::FFMpegExtractor() {
       mSource = new MediaSource;
    }

    FFMpegExtractor::~FFMpegExtractor() {
       delete mSource;
    }

    constexpr int kInternalBufferSize = 1152; // Use MP3 block size. https://wiki.hydrogenaud.io/index.php?title=MP3

    /**
    * Reads from an IStream into FFmpeg.
    *
    * @param ptr       A pointer to the user-defined IO data structure.
    * @param buf       A buffer to read into.
    * @param buf_size  The size of the buffer buff.
    *
    * @return The number of bytes read into the buffer.
    */


    // If FFmpeg needs to read the file, it will call this function.
    // We need to fill the buffer with file's data.
    int read(void *opaque, uint8_t *buffer, int buf_size) {
       MediaSource *source = (MediaSource *) opaque;
       return source->read(buffer, buf_size);
    }

    // If FFmpeg needs to seek in the file, it will call this function.
    // We need to change the read pos.
    int64_t seek(void *opaque, int64_t offset, int whence) {
       MediaSource *source = (MediaSource *) opaque;
       return source->seek(offset, whence);
    }


    // Create and save a MediaSource instance.
    bool FFMpegExtractor::createAVIOContext2(const std::string &amp;filepath, uint8_t *buffer, uint32_t bufferSize,
                                            AVIOContext **avioContext) {

       mSource = new MediaSource;
       mSource->open(filepath);
       constexpr int isBufferWriteable = 0;

       *avioContext = avio_alloc_context(
               buffer, // internal buffer for FFmpeg to use
               bufferSize, // For optimal decoding speed this should be the protocol block size
               isBufferWriteable,
               mSource, // Will be passed to our callback functions as a (void *)
               read, // Read callback function
               nullptr, // Write callback function (not used)
               seek); // Seek callback function

       if (*avioContext == nullptr) {
           LOGE("Failed to create AVIO context");
           return false;
       } else {
           return true;
       }
    }

    bool
    FFMpegExtractor::createAVFormatContext(AVIOContext *avioContext,
                                          AVFormatContext **avFormatContext) {

       *avFormatContext = avformat_alloc_context();
       (*avFormatContext)->pb = avioContext;

       if (*avFormatContext == nullptr) {
           LOGE("Failed to create AVFormatContext");
           return false;
       } else {
           LOGD("Successfully created AVFormatContext");
           return true;
       }
    }

    bool FFMpegExtractor::openAVFormatContext(AVFormatContext *avFormatContext) {

       int result = avformat_open_input(&amp;avFormatContext,
                                        "", /* URL is left empty because we're providing our own I/O */
                                        nullptr /* AVInputFormat *fmt */,
                                        nullptr /* AVDictionary **options */
       );

       if (result == 0) {
           return true;
       } else {
           LOGE("Failed to open file. Error code %s", av_err2str(result));
           return false;
       }
    }

    bool FFMpegExtractor::getStreamInfo(AVFormatContext *avFormatContext) {

       int result = avformat_find_stream_info(avFormatContext, nullptr);
       if (result == 0) {
           return true;
       } else {
           LOGE("Failed to find stream info. Error code %s", av_err2str(result));
           return false;
       }
    }

    AVStream *FFMpegExtractor::getBestAudioStream(AVFormatContext *avFormatContext) {

       int streamIndex = av_find_best_stream(avFormatContext, AVMEDIA_TYPE_AUDIO, -1, -1, nullptr, 0);

       if (streamIndex &lt; 0) {
           LOGE("Could not find stream");
           return nullptr;
       } else {
           return avFormatContext->streams[streamIndex];
       }
    }

    int64_t FFMpegExtractor::decode2(
           char* filepath,
           uint8_t *targetData,
           AudioProperties targetProperties) {

       LOGD("Decode SETUP");
       int returnValue = -1; // -1 indicates error

       // Create a buffer for FFmpeg to use for decoding (freed in the custom deleter below)
       auto buffer = reinterpret_cast(av_malloc(kInternalBufferSize));


       // Create an AVIOContext with a custom deleter
       std::unique_ptr ioContext{
               nullptr,
               [](AVIOContext *c) {
                   av_free(c->buffer);
                   avio_context_free(&amp;c);
               }
       };
       {
           AVIOContext *tmp = nullptr;
           if (!createAVIOContext2(filepath, buffer, kInternalBufferSize, &amp;tmp)) {
               LOGE("Could not create an AVIOContext");
               return returnValue;
           }
           ioContext.reset(tmp);
       }
       // Create an AVFormatContext using the avformat_free_context as the deleter function
       std::unique_ptr formatContext{
               nullptr,
               &amp;avformat_free_context
       };

       {
           AVFormatContext *tmp;
           if (!createAVFormatContext(ioContext.get(), &amp;tmp)) return returnValue;
           formatContext.reset(tmp);
       }
       if (!openAVFormatContext(formatContext.get())) return returnValue;
       LOGD("172");

       if (!getStreamInfo(formatContext.get())) return returnValue;
       LOGD("175");

       // Obtain the best audio stream to decode
       AVStream *stream = getBestAudioStream(formatContext.get());
       if (stream == nullptr || stream->codecpar == nullptr) {
           LOGE("Could not find a suitable audio stream to decode");
           return returnValue;
       }
       LOGD("183");

       printCodecParameters(stream->codecpar);

       // Find the codec to decode this stream
       AVCodec *codec = avcodec_find_decoder(stream->codecpar->codec_id);
       if (!codec) {
           LOGE("Could not find codec with ID: %d", stream->codecpar->codec_id);
           return returnValue;
       }

       // Create the codec context, specifying the deleter function
       std::unique_ptr codecContext{
               nullptr,
               [](AVCodecContext *c) { avcodec_free_context(&amp;c); }
       };
       {
           AVCodecContext *tmp = avcodec_alloc_context3(codec);
           if (!tmp) {
               LOGE("Failed to allocate codec context");
               return returnValue;
           }
           codecContext.reset(tmp);
       }

       // Copy the codec parameters into the context
       if (avcodec_parameters_to_context(codecContext.get(), stream->codecpar) &lt; 0) {
           LOGE("Failed to copy codec parameters to codec context");
           return returnValue;
       }

       // Open the codec
       if (avcodec_open2(codecContext.get(), codec, nullptr) &lt; 0) {
           LOGE("Could not open codec");
           return returnValue;
       }

       // prepare resampler
       int32_t outChannelLayout = (1 &lt;&lt; targetProperties.channelCount) - 1;
       LOGD("Channel layout %d", outChannelLayout);

       SwrContext *swr = swr_alloc();
       av_opt_set_int(swr, "in_channel_count", stream->codecpar->channels, 0);
       av_opt_set_int(swr, "out_channel_count", targetProperties.channelCount, 0);
       av_opt_set_int(swr, "in_channel_layout", stream->codecpar->channel_layout, 0);
       av_opt_set_int(swr, "out_channel_layout", outChannelLayout, 0);
       av_opt_set_int(swr, "in_sample_rate", stream->codecpar->sample_rate, 0);
       av_opt_set_int(swr, "out_sample_rate", targetProperties.sampleRate, 0);
       av_opt_set_int(swr, "in_sample_fmt", stream->codecpar->format, 0);
       av_opt_set_sample_fmt(swr, "out_sample_fmt", AV_SAMPLE_FMT_FLT, 0);
       av_opt_set_int(swr, "force_resampling", 1, 0);

       // Check that resampler has been inited
       int result = swr_init(swr);
       if (result != 0) {
           LOGE("swr_init failed. Error: %s", av_err2str(result));
           return returnValue;
       };
       if (!swr_is_initialized(swr)) {
           LOGE("swr_is_initialized is false\n");
           return returnValue;
       }

       // Prepare to read data
       int bytesWritten = 0;
       AVPacket avPacket; // Stores compressed audio data
       av_init_packet(&amp;avPacket);
       AVFrame *decodedFrame = av_frame_alloc(); // Stores raw audio data
       int bytesPerSample = av_get_bytes_per_sample((AVSampleFormat) stream->codecpar->format);

       LOGD("Bytes per sample %d", bytesPerSample);

       // While there is more data to read, read it into the avPacket
       while (av_read_frame(formatContext.get(), &amp;avPacket) == 0) {

           if (avPacket.stream_index == stream->index) {

               while (avPacket.size > 0) {
                   // Pass our compressed data into the codec
                   result = avcodec_send_packet(codecContext.get(), &amp;avPacket);
                   if (result != 0) {
                       LOGE("avcodec_send_packet error: %s", av_err2str(result));
                       goto cleanup;
                   }

                   // Retrieve our raw data from the codec
                   result = avcodec_receive_frame(codecContext.get(), decodedFrame);
                   if (result != 0) {
                       LOGE("avcodec_receive_frame error: %s", av_err2str(result));
                       goto cleanup;
                   }

                   // DO RESAMPLING
                   auto dst_nb_samples = (int32_t) av_rescale_rnd(
                           swr_get_delay(swr, decodedFrame->sample_rate) + decodedFrame->nb_samples,
                           targetProperties.sampleRate,
                           decodedFrame->sample_rate,
                           AV_ROUND_UP);

                   short *buffer1;
                   av_samples_alloc(
                           (uint8_t **) &amp;buffer1,
                           nullptr,
                           targetProperties.channelCount,
                           dst_nb_samples,
                           AV_SAMPLE_FMT_FLT,
                           0);
                   int frame_count = swr_convert(
                           swr,
                           (uint8_t **) &amp;buffer1,
                           dst_nb_samples,
                           (const uint8_t **) decodedFrame->data,
                           decodedFrame->nb_samples);

                   int64_t bytesToWrite = frame_count * sizeof(float) * targetProperties.channelCount;
                   memcpy(targetData + bytesWritten, buffer1, (size_t) bytesToWrite);
                   bytesWritten += bytesToWrite;
                   av_freep(&amp;buffer1);

                   avPacket.size = 0;
                   avPacket.data = nullptr;
               }
           }
       }

       av_frame_free(&amp;decodedFrame);

       returnValue = bytesWritten;

       cleanup:
       return returnValue;
    }

    void FFMpegExtractor::printCodecParameters(AVCodecParameters *params) {

       LOGD("Stream properties");
       LOGD("Channels: %d", params->channels);
       LOGD("Channel layout: %"
                    PRId64, params->channel_layout);
       LOGD("Sample rate: %d", params->sample_rate);
       LOGD("Format: %s", av_get_sample_fmt_name((AVSampleFormat) params->format));
       LOGD("Frame size: %d", params->frame_size);
    }
    </fstream></memory>

    And this is the MediaSource.cpp :

    #ifndef MYAPP_MEDIASOURCE_CPP
    #define MYAPP_MEDIASOURCE_CPP

    extern "C" {
    #include <libavformat></libavformat>avformat.h>
    #include <libswresample></libswresample>swresample.h>
    #include <libavutil></libavutil>opt.h>
    }

    #include <cstdint>
    #include <android></android>asset_manager.h>
    #include
    #include <fstream>
    #include "logging.h"

    // wrapper class for file stream
    class MediaSource {
    public:

       MediaSource() {
       }

       ~MediaSource() {
           source.close();
       }

       void open(const std::string &amp;filePath) {
           const char *x = filePath.c_str();
           LOGD("Opened %s", x);
           source.open(filePath, std::ios::in | std::ios::binary);
       }

       int read(uint8_t *buffer, int buf_size) {
           // read data to buffer
           source.read((char *) buffer, buf_size);
           // return how many bytes were read
           return source.gcount();
       }

       int64_t seek(int64_t offset, int whence) {
           if (whence == AVSEEK_SIZE) {
               // FFmpeg needs file size.
               int oldPos = source.tellg();
               source.seekg(0, std::ios::end);
               int64_t length = source.tellg();
               // seek to old pos
               source.seekg(oldPos);
               return length;
           } else if (whence == SEEK_SET) {
               // set pos to offset
               source.seekg(offset);
           } else if (whence == SEEK_CUR) {
               // add offset to pos
               source.seekg(offset, std::ios::cur);
           } else {
               // do not support other flags, return -1
               return -1;
           }
           // return current pos
           return source.tellg();
       }

    private:
       std::ifstream source;
    };

    #endif //MYAPP_MEDIASOURCE_CPP
    </fstream></cstdint>

    When the code is executed, I can see that I submit the correct file path, so I assume the resource mp3 is there.
    When this code is executed the app crashes in line 103 of FFMpegExtractor.cpp, at formatContext.reset(tmp);

    This is what Android Studio logs when the app crashes :

    --------- beginning of crash
    2020-02-27 14:31:26.341 9852-9945/com.user.myapp A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x7fffffff0 in tid 9945 (chaelpohl.loopy), pid 9852 (user.myapp)

    This is the (sadly very short) output I get with ndk-stack :

    ********** Crash dump: **********
    Build fingerprint: 'samsung/dreamltexx/dreamlte:9/PPR1.180610.011/G950FXXU6DSK9:user/release-keys'
    #00 0x0000000000016c50 /data/app/com.user.myapp-D7dBCgHF-vdQNNSald4lWA==/lib/arm64/libavformat.so (avformat_free_context+260)
                                                                                                            avformat_free_context
                                                                                                            ??:0:0
    Crash dump is completed

    I tested a bit around, and every call to my formatContext crashes the app. So I assume there is something wrong with the input I provide to build it but I have no clue how to debug this.

    Any help is appreciated ! (Happy to provide additional resources if something crucial is missing).

  • Unplayable video after running FFmpeg command

    25 mai 2020, par HB.

    I asked this question last year. I resolved the issue I had and I implemented the same logic for merging an image with a video, instead of two images. This is running on Android.

    &#xA;&#xA;

    Here is the command I'm using currently :

    &#xA;&#xA;

    "-i", mFilePath, "-i", drawingPath, "-filter_complex", "[0:v]scale=iw*sar:ih,setsar=1,pad=&#x27;max(iw\\,2*trunc(ih*47/80/2))&#x27;:&#x27;max(ih\\,2*trunc(ow*80/47/2))&#x27;:(ow-iw)/2:(oh-ih)/2[v0];[1:v][v0]scale2ref[v1][v0];[v0][v1]overlay=x=(W-w)/2:y=(H-h)/2[v]", "-map", "[v]", "-map", "0:a", "-c:v", "libx264", "-preset", "ultrafast", "-r", outputFPS, outputPath}&#xA;

    &#xA;&#xA;

    47/80/2 is calculated by getting a device's screen dimensions - 1128 x 1920.

    &#xA;&#xA;

    When running this on certain devices, it results in an unplayable video.

    &#xA;&#xA;

    But running the following command works perfectly fine :

    &#xA;&#xA;

    "-i", mFilePath, "-crf", "18", "-c:v", "libx264", "-preset", "ultrafast", outputPath};&#xA;

    &#xA;&#xA;

    I think the issue is with the filter being applied ?

    &#xA;&#xA;


    &#xA;&#xA;

    I compared running the first command on two different devices.

    &#xA;&#xA;

      &#xA;
    • On the first device (Samsung J7 Pro), I was able to run the command successfully and play the video afterward. I tested the output on both devices and it is working.
    • &#xA;

    • On the second device (Sony Xperia Tablet Z), I was able to run the command successfully but could not play the video. I tested the output on both devices and it doesn't play on either. It does play on my computer.
    • &#xA;

    &#xA;&#xA;

    I compared the original video with the one not working and the one without a filter and the only difference I could find is that the one that is not working profile is Baseline@L4.2 and the one without a filter profile is Baseline@L4.0. The original video profile is High@L4.0.

    &#xA;&#xA;

    Here are all the videos. The original, the one without a filter (working) and the one with the filter(no working).

    &#xA;&#xA;

    I have no idea why this is happening ? Any help would be appreciated.

    &#xA;&#xA;


    &#xA;&#xA;

    Edit 1 :

    &#xA;&#xA;

    Here is the actual log as requested :

    &#xA;&#xA;

    "-i", "/storage/emulated/0/Android/data/com.my.package/files/CameraTemp/2020_05_24_09_17_53.mp4", "-i", "/storage/emulated/0/Android/data/com.my.package/files/MyVideos/tempShapes.png", "-filter_complex", "[0:v]scale=iw*sar:ih,setsar=1,pad=&#x27;max(iw\\,2*trunc(ih*47/80/2))&#x27;:&#x27;max(ih\\,2*trunc(ow*80/47/2))&#x27;:(ow-iw)/2:(oh-ih)/2[v0];[1:v][v0]scale2ref[v1][v0];[v0][v1]overlay=x=(W-w)/2:y=(H-h)/2[v]", "-map", "[v]", "-map", "0:a", "-c:v", "libx264", "-preset", "ultrafast", "-r", "30", "/storage/emulated/0/Android/data/com.my.package/files/MyVideos/video with line.mp4"&#xA;

    &#xA;&#xA;

    and here is the complete log :

    &#xA;&#xA;

    ffmpeg version n4.0-39-gda39990 Copyright (c) 2000-2018 the FFmpeg developers&#xA;  built with gcc 4.9.x (GCC) 20150123 (prerelease)&#xA;  configuration: --target-os=linux --cross-prefix=/root/bravobit/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/root/bravobit/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-ffprobe --enable-libopus --enable-libvorbis --enable-libfdk-aac --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-libvpx --enable-libass --enable-yasm --enable-pthreads --disable-debug --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-linux-perf --disable-doc --disable-shared --enable-static --enable-runtime-cpudetect --enable-nonfree --enable-network --enable-avresample --enable-avformat --enable-avcodec --enable-indev=lavfi --enable-hwaccels --enable-ffmpeg --enable-zlib --enable-gpl --enable-small --enable-nonfree --pkg-config=pkg-config --pkg-config-flags=--static --prefix=/root/bravobit/ffmpeg-android/build/armeabi-v7a --extra-cflags=&#x27;-I/root/bravobit/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all&#x27; --extra-ldflags=&#x27;-L/root/bravobit/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie&#x27; --extra-cxxflags=&#xA;  libavutil      56. 14.100 / 56. 14.100&#xA;  libavcodec     58. 18.100 / 58. 18.100&#xA;  libavformat    58. 12.100 / 58. 12.100&#xA;  libavdevice    58.  3.100 / 58.  3.100&#xA;  libavfilter     7. 16.100 /  7. 16.100&#xA;  libavresample   4.  0.  0 /  4.  0.  0&#xA;  libswscale      5.  1.100 /  5.  1.100&#xA;  libswresample   3.  1.100 /  3.  1.100&#xA;  libpostproc    55.  1.100 / 55.  1.100&#xA;Input #0, mov,mp4,m4a,3gp,3g2,mj2, from &#x27;/storage/emulated/0/Android/data/com.my.package/files/CameraTemp/2020_05_24_09_17_53.mp4&#x27;:&#xA;  Metadata:&#xA;    major_brand     : mp42&#xA;    minor_version   : 0&#xA;    compatible_brands: isommp42&#xA;    creation_time   : 2020-05-24T08:18:02.000000Z&#xA;  Duration: 00:00:01.64, start: 0.000000, bitrate: 20750 kb/s&#xA;    Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), yuv420p, 1920x1080, 18056 kb/s, SAR 1:1 DAR 16:9, 29.70 fps, 29.67 tbr, 90k tbn, 180k tbc (default)&#xA;    Metadata:&#xA;      creation_time   : 2020-05-24T08:18:02.000000Z&#xA;      handler_name    : VideoHandle&#xA;    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 155 kb/s (default)&#xA;    Metadata:&#xA;      creation_time   : 2020-05-24T08:18:02.000000Z&#xA;      handler_name    : SoundHandle&#xA;Input #1, png_pipe, from &#x27;/storage/emulated/0/Android/data/com.my.package/files/MyVideos/tempShapes.png&#x27;:&#xA;  Duration: N/A, bitrate: N/A&#xA;    Stream #1:0: Video: png, rgba(pc), 1920x1128, 25 tbr, 25 tbn, 25 tbc&#xA;Stream mapping:&#xA;  Stream #0:0 (h264) -> scale (graph 0)&#xA;  Stream #1:0 (png) -> scale2ref:default (graph 0)&#xA;  overlay (graph 0) -> Stream #0:0 (libx264)&#xA;  Stream #0:1 -> #0:1 (aac (native) -> aac (native))&#xA;Press [q] to stop, [?] for help&#xA;frame=    0 fps=0.0 q=0.0 size=       0kB time=-577014:32:22.77 bitrate=  -0.0kbits/s speed=N/A    &#xA;frame=    0 fps=0.0 q=0.0 size=       0kB time=-577014:32:22.77 bitrate=  -0.0kbits/s speed=N/A    &#xA;[libx264 @ 0xb83fc8a0] using SAR=1/1&#xA;[libx264 @ 0xb83fc8a0] using cpu capabilities: ARMv6 NEON&#xA;[libx264 @ 0xb83fc8a0] profile Constrained Baseline, level 4.2&#xA;[libx264 @ 0xb83fc8a0] 264 - core 152 r2851M ba24899 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=2 keyint_min=1 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0&#xA;Output #0, mp4, to &#x27;/storage/emulated/0/Android/data/com.my.package/files/MyVideos/video with line.mp4&#x27;:&#xA;  Metadata:&#xA;    major_brand     : mp42&#xA;    minor_version   : 0&#xA;    compatible_brands: isommp42&#xA;    encoder         : Lavf58.12.100&#xA;    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1920x1128 [SAR 1:1 DAR 80:47], q=-1--1, 29 fps, 14848 tbn, 29 tbc (default)&#xA;    Metadata:&#xA;      encoder         : Lavc58.18.100 libx264&#xA;    Side data:&#xA;      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1&#xA;    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)&#xA;    Metadata:&#xA;      creation_time   : 2020-05-24T08:18:02.000000Z&#xA;      handler_name    : SoundHandle&#xA;      encoder         : Lavc58.18.100 aac&#xA;frame=    1 fps=0.4 q=0.0 size=       0kB time=00:00:01.01 bitrate=   0.4kbits/s speed=0.397x    &#xA;frame=    5 fps=1.6 q=0.0 size=       0kB time=00:00:01.01 bitrate=   0.4kbits/s speed=0.33x    &#xA;frame=    9 fps=2.5 q=24.0 size=     256kB time=00:00:01.01 bitrate=2075.0kbits/s speed=0.28x    &#xA;frame=   13 fps=3.1 q=25.0 size=    1024kB time=00:00:01.01 bitrate=8298.9kbits/s speed=0.243x    &#xA;frame=   18 fps=3.8 q=29.0 size=    2048kB time=00:00:01.01 bitrate=16597.5kbits/s speed=0.214x    &#xA;frame=   21 fps=3.9 q=25.0 size=    2560kB time=00:00:01.01 bitrate=20746.7kbits/s speed=0.19x    &#xA;frame=   23 fps=3.9 q=25.0 size=    2816kB time=00:00:01.01 bitrate=22821.4kbits/s speed=0.173x    &#xA;frame=   26 fps=4.0 q=29.0 size=    3584kB time=00:00:01.01 bitrate=29045.3kbits/s speed=0.156x    &#xA;Past duration 0.617577 too large&#xA;Past duration 0.639641 too large&#xA;frame=   28 fps=3.9 q=29.0 size=    3840kB time=00:00:01.01 bitrate=31119.9kbits/s speed=0.142x    &#xA;Past duration 0.665230 too large&#xA;frame=   29 fps=3.8 q=25.0 size=    3840kB time=00:00:01.01 bitrate=31119.9kbits/s speed=0.132x    &#xA;Past duration 0.690834 too large&#xA;Past duration 0.711281 too large&#xA;Past duration 0.736885 too large&#xA;frame=   32 fps=3.9 q=29.0 size=    4608kB time=00:00:01.01 bitrate=37343.8kbits/s speed=0.123x    &#xA;Past duration 0.762474 too large&#xA;Past duration 0.783577 too large&#xA;Past duration 0.807564 too large&#xA;frame=   35 fps=3.9 q=25.0 size=    4864kB time=00:00:01.01 bitrate=39418.4kbits/s speed=0.112x    &#xA;Past duration 0.831551 too large&#xA;Past duration 0.855537 too large&#xA;frame=   37 fps=3.5 q=25.0 size=    5376kB time=00:00:01.01 bitrate=43567.7kbits/s speed=0.0968x    &#xA;Past duration 0.879524 too large&#xA;Past duration 0.903511 too large&#xA;frame=   39 fps=3.4 q=25.0 size=    5376kB time=00:00:01.06 bitrate=41196.6kbits/s speed=0.0927x    &#xA;Past duration 0.927498 too large&#xA;Past duration 0.951500 too large&#xA;frame=   41 fps=3.4 q=25.0 size=    5376kB time=00:00:01.13 bitrate=38700.0kbits/s speed=0.0931x    &#xA;frame=   41 fps=3.2 q=25.0 size=    5376kB time=00:00:01.13 bitrate=38700.0kbits/s speed=0.0886x    &#xA;frame=   41 fps=3.1 q=25.0 size=    5888kB time=00:00:01.43 bitrate=33554.2kbits/s speed=0.108x    &#xA;Past duration 0.975487 too large&#xA;frame=   45 fps=3.2 q=26.0 size=    6656kB time=00:00:01.60 bitrate=33905.4kbits/s speed=0.114x    &#xA;frame=   45 fps=3.0 q=-1.0 Lsize=    8158kB time=00:00:01.65 bitrate=40480.7kbits/s speed=0.11x    &#xA;video:8127kB audio:28kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.032895%&#xA;[libx264 @ 0xb83fc8a0] frame I:23    Avg QP:24.70  size:337646&#xA;[libx264 @ 0xb83fc8a0] frame P:22    Avg QP:29.00  size: 25250&#xA;[libx264 @ 0xb83fc8a0] mb I  I16..4: 100.0%  0.0%  0.0%&#xA;[libx264 @ 0xb83fc8a0] mb P  I16..4:  0.4%  0.0%  0.0%  P16..4: 43.6%  0.0%  0.0%  0.0%  0.0%    skip:56.0%&#xA;[libx264 @ 0xb83fc8a0] coded y,uvDC,uvAC intra: 90.0% 84.7% 58.1% inter: 20.1% 6.2% 0.1%&#xA;[libx264 @ 0xb83fc8a0] i16 v,h,dc,p: 25% 28% 28% 20%&#xA;[libx264 @ 0xb83fc8a0] i8c dc,h,v,p: 39% 25% 20% 16%&#xA;[libx264 @ 0xb83fc8a0] kb/s:42901.20&#xA;[aac @ 0xb83d7d10] Qavg: 3517.779&#xA;

    &#xA;

  • FFMPEG crash while cropping video

    18 octobre 2022, par Khawar Raza

    I am using FFMPEG to crop a video. I am using ffmpeg-kit as a ffmpeg wrapper in my android app where the user can select any output size irrespective of the original video aspect ratio. Below is the problematic command :

    &#xA;

    -i "/storage/emulated/0/Download/83a2f6_1080p~2.mp4" -filter_complex "[0:v]crop=304:236:2:2[cropped]" -map "[cropped]" "/storage/emulated/0/DCIM/appname/vid_d8ee328d-ec7a-468b-9313-4561dceea33e.mp4"&#xA;

    &#xA;

    When the execution starts, the application crashes.

    &#xA;

    Logs :

    &#xA;

    I/ffmpeg-kit: Loading ffmpeg-kit.&#xA;I/ffmpeg-kit: Loaded ffmpeg-kit-min-gpl-arm64-v8a-4.5.1-20220101.&#xA;D/ffmpeg-kit: Async callback block started.&#xA;D/VideoEditor:  ffmpeg version v4.5-dev-3393-g30322ebe3c&#xA;D/VideoEditor:   Copyright (c) 2000-2021 the FFmpeg developers&#xA;D/VideoEditor:  &#xA;D/VideoEditor:    built with Android (7155654, based on r399163b1) clang version 11.0.5 (https://android.googlesource.com/toolchain/llvm-project 87f1315dfbea7c137aa2e6d362dbb457e388158d)&#xA;D/VideoEditor:    configuration: --cross-prefix=aarch64-linux-android- --sysroot=/files/android-sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/sysroot --prefix=/storage/light/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/storage/light/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-test --disable-programs --disable-postproc --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --disable-sndio --disable-schannel --disable-securetransport --disable-xlib --disable-cuda --disable-cuvid --disable-nvenc --disable-vaapi --disable-vdpau --disable-videotoolbox --disable-audiotoolbox --disable-appkit --disable-alsa --disable-cuda --disable-cuvid --disable-nvenc --disable-vaapi --disable-vdpau --enable-libx264 --enable-libxvid --enable-libx265 --enable-libvidstab --disable-sdl2 --disable-openssl --enable-zlib --enable-mediacodec --enable-gpl&#xA;D/VideoEditor:    libavutil      57. 13.100 / 57. 13.100&#xA;D/VideoEditor:    libavcodec     59. 15.102 / 59. 15.102&#xA;D/VideoEditor:    libavformat    59. 10.100 / 59. 10.100&#xA;D/VideoEditor:    libavdevice    59.  1.100 / 59.  1.100&#xA;D/VideoEditor:    libavfilter     8. 21.100 /  8. 21.100&#xA;D/VideoEditor:    libswscale      6.  1.102 /  6.  1.102&#xA;D/VideoEditor:    libswresample   4.  0.100 /  4.  0.100&#xA;D/VideoEditor:  Input #0, mov,mp4,m4a,3gp,3g2,mj2, from &#x27;/storage/emulated/0/Download/83a2f6_1080p~2.mp4&#x27;:&#xA;D/VideoEditor:    Metadata:&#xA;D/VideoEditor:      major_brand     : &#xA;D/VideoEditor:  mp42&#xA;D/VideoEditor:  &#xA;D/VideoEditor:      minor_version   : &#xA;D/VideoEditor:  0&#xA;D/VideoEditor:  &#xA;D/VideoEditor:      compatible_brands: &#xA;D/VideoEditor:  isommp42&#xA;D/VideoEditor:  &#xA;D/VideoEditor:      com.android.version: &#xA;D/VideoEditor:  12&#xA;D/VideoEditor:  &#xA;D/VideoEditor:    Duration: &#xA;D/VideoEditor:  00:02:18.11&#xA;D/VideoEditor:  , start: &#xA;D/VideoEditor:  0.000000&#xA;D/VideoEditor:  , bitrate: &#xA;D/VideoEditor:  1929 kb/s&#xA;D/VideoEditor:  &#xA;D/VideoEditor:    Stream #0:0&#xA;D/VideoEditor:  [0x1]&#xA;D/VideoEditor:  (eng)&#xA;D/VideoEditor:  : Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1080x808, 1864 kb/s&#xA;D/VideoEditor:  , &#xA;D/VideoEditor:  18 fps, &#xA;D/VideoEditor:  18 tbr, &#xA;D/VideoEditor:  90k tbn&#xA;D/VideoEditor:   (default)&#xA;D/VideoEditor:  &#xA;D/VideoEditor:      Metadata:&#xA;D/VideoEditor:        creation_time   : &#xA;D/VideoEditor:  2022-10-06T11:47:07.000000Z&#xA;D/VideoEditor:  &#xA;D/VideoEditor:        handler_name    : &#xA;D/VideoEditor:  VideoHandle&#xA;D/VideoEditor:  &#xA;D/VideoEditor:        vendor_id       : &#xA;D/VideoEditor:  [0][0][0][0]&#xA;D/VideoEditor:  &#xA;D/VideoEditor:    Stream #0:1&#xA;D/VideoEditor:  [0x2]&#xA;D/VideoEditor:  (und)&#xA;D/VideoEditor:  : Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 64 kb/s&#xA;D/VideoEditor:   (default)&#xA;D/VideoEditor:  &#xA;D/VideoEditor:      Metadata:&#xA;D/VideoEditor:        creation_time   : &#xA;D/VideoEditor:  2022-10-06T11:47:07.000000Z&#xA;D/VideoEditor:  &#xA;D/VideoEditor:        handler_name    : &#xA;D/VideoEditor:  SoundHandle&#xA;D/VideoEditor:  &#xA;D/VideoEditor:        vendor_id       : &#xA;D/VideoEditor:  [0][0][0][0]&#xA;D/VideoEditor:  &#xA;&#xA;&#xA;D/VideoEditor:  [h264 @ 0x7654fe8500] The "sub_text_format" option is deprecated: Deprecated, does nothing&#xA;D/VideoEditor:  Stream mapping:&#xA;D/VideoEditor:    Stream #0:0 (h264) -> crop&#xA;D/VideoEditor:  &#xA;D/VideoEditor:    crop&#xA;D/VideoEditor:   -> Stream #0:0 (libx264)&#xA;D/VideoEditor:  Press [q] to stop, [?] for help&#xA;&#xA;&#xA;D/VideoEditor:  [libx264 @ 0x7654fb9af0] using cpu capabilities: ARMv8 NEON&#xA;D/VideoEditor:  [libx264 @ 0x7654fb9af0] profile High, level 1.2, 4:2:0, 8-bit&#xA;D/VideoEditor:  [libx264 @ 0x7654fb9af0] 264 - core 163 - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=7 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=18 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00&#xA;D/VideoEditor:  Output #0, mp4, to &#x27;/storage/emulated/0/DCIM/appname/vid_d8ee328d-ec7a-468b-9313-4561dceea33e.mp4&#x27;:&#xA;D/VideoEditor:    Metadata:&#xA;D/VideoEditor:      major_brand     : &#xA;D/VideoEditor:  mp42&#xA;D/VideoEditor:  &#xA;D/VideoEditor:      minor_version   : &#xA;D/VideoEditor:  0&#xA;D/VideoEditor:  &#xA;D/VideoEditor:      compatible_brands: &#xA;D/VideoEditor:  isommp42&#xA;D/VideoEditor:  &#xA;D/VideoEditor:      com.android.version: &#xA;D/VideoEditor:  12&#xA;D/VideoEditor:  &#xA;D/VideoEditor:      encoder         : &#xA;D/VideoEditor:  Lavf59.10.100&#xA;D/VideoEditor:  &#xA;D/VideoEditor:    Stream #0:0&#xA;D/VideoEditor:  : Video: h264 (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 304x236, q=2-31&#xA;D/VideoEditor:  , &#xA;D/VideoEditor:  18 fps, &#xA;D/VideoEditor:  18432 tbn&#xA;D/VideoEditor:   (default)&#xA;D/VideoEditor:  &#xA;D/VideoEditor:      Metadata:&#xA;D/VideoEditor:        encoder         : &#xA;D/VideoEditor:  Lavc59.15.102 libx264&#xA;D/VideoEditor:  &#xA;D/VideoEditor:      Side data:&#xA;D/VideoEditor:        &#xA;D/VideoEditor:  cpb: &#xA;D/VideoEditor:  bitrate max/min/avg: 0/0/0 buffer size: 0 &#xA;D/VideoEditor:  vbv_delay: N/A&#xA;D/VideoEditor:  &#xA;D/VideoEditor:  frame=    1 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    &#xA;&#xA;A/libc: Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x745d9ff000 in tid 16893 (pool-15-thread-), pid 16696 (videocompressor)&#xA;&#xA;&#xA;A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***&#xA;Build fingerprint: &#x27;samsung/x1sxx/x1s:12/SP1A.210812.016/G980FXXSFFVH7:user/release-keys&#x27;&#xA;Revision: &#x27;22&#x27;&#xA;ABI: &#x27;arm64&#x27;&#xA;Processor: &#x27;5&#x27;&#xA;A/DEBUG: Timestamp: 2022-10-09 18:57:38.882598912&#x2B;0500&#xA;A/DEBUG: Process uptime: 1086s&#xA;A/DEBUG: Cmdline: com.app.packagename&#xA;A/DEBUG: pid: 16939, tid: 20568, name: pool-15-thread-  >>> com.app.packagename &lt;&lt;&lt;&#xA;A/DEBUG: uid: 11091&#xA;A/DEBUG: signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x74640ce000&#xA;A/DEBUG:     x0  0000007594f30960  x1  00000074640c9a60  x2  00000074640c9eb4  x3  00000074640cac34&#xA;A/DEBUG:     x4  00000074640cdff4  x5  00000074671bb2dc  x6  00000000fffffffb  x7  0000000000000013&#xA;A/DEBUG:     x8  000000000000000e  x9  00000074640cddc0  x10 0000000000000013  x11 0000007488459ffc&#xA;A/DEBUG:     x12 00000074640c9c70  x13 000000000000000e  x14 0000000000007fff  x15 0000000000000013&#xA;A/DEBUG:     x16 00000074640cac04  x17 00000074640c7a58  x18 000000746626e000  x19 0000000000000027&#xA;A/DEBUG:     x20 000000776541c3b0  x21 00000074671bc4f8  x22 00000074640ca9f0  x23 0000007765422300&#xA;A/DEBUG:     x24 0000000000000027  x25 00000074640cac04  x26 0000000000000028  x27 00000074640c9a30&#xA;A/DEBUG:     x28 0000007594f30940  x29 000000000000010a&#xA;A/DEBUG:     lr  000000748841a960  sp  00000074671bb290  pc  000000748845a010  pst 0000000080000000&#xA;A/DEBUG: backtrace:&#xA;A/DEBUG:       #00 pc 0000000000359010  /data/app/~~IBCbjRbZBpQ00ORNDFZdxg==/com.app.packagename-5sdOCmN82SjJJTibcsYMpQ==/base.apk!libavcodec.so&#xA;

    &#xA;

    I don't know what is wrong with the output width and height parameters. If I change [0:v]crop=304:236:2:2[cropped] to [0:v]crop=304:304:2:2[cropped] with change in height, the process completes successfully. The original video (1080x808) is not smaller than the output size. It does not seem to be a problem in the video as I have tried different videos. Any tips on what is missing from my command ?

    &#xA;