Recherche avancée

Médias (2)

Mot : - Tags -/map

Autres articles (54)

  • MediaSPIP version 0.1 Beta

    16 avril 2011, par

    MediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

  • MediaSPIP 0.1 Beta version

    25 avril 2011, par

    MediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
    The zip file provided here only contains the sources of MediaSPIP in its standalone version.
    To get a working installation, you must manually install all-software dependencies on the server.
    If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...)

  • Amélioration de la version de base

    13 septembre 2013

    Jolie sélection multiple
    Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
    Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...)

Sur d’autres sites (4624)

  • ffmpeg command for faster encoding at a decent bitrate with smaller file size

    28 juillet 2023, par Blair Holmes

    I'm currently using an implementation of ffmpeg on my android app. I'm allowing users to take short videos within my app and then when they upload them to the server, I'm crunching them down with ffmpeg to decrease file size so they're not passing huge amounts of data over the wire.

    



    the problem is, it's taking forever to encode the videos on the android device. These videos usually aren't longer than 45 seconds and can take 20 minutes to encode. I've done some playing around with different switches / parameters on the ffmpeg command line and I now have it at a more comfortable time, but the file sizes are significantly bigger. I'm just not sure what codec I should use (fastest encoding but with decent quality output), how ffmpeg handles changing size (aspect ratio) in terms of speed of encoding etc.

    



    Here are the two commands I've been using. This first one outputs the file size / quality that I want, but it just takes way too long to encode, not to mention it makes my device get really hot while it's encoding for so long :

    



    ffmpeg -i input.mp4 -b:v 1024k -c:a copy -vf scale=960:540 output.mp4


    



    I've tweaked the bitrate some on that as well as changed the scale to a smaller size, but I don't want to have to make the videos really small (in terms of scale) to accomplish a faster encoding. this second command goes a lot faster but makes the file size significantly bigger :

    



    ffmpeg -i input.mp4 -vcodec libx264 -preset fast -c:a copy -s 960x540 output.mp4


    



    I'd like to find a happy medium (smaller file size but faster encoding) keeping the video scale size close to the original. ffmpeg just has so many different parameters / switches that it's difficult to wrap my head around what I should be doing.

    



    EDIT : adding ffmpeg output.

    



    ffmpeg -i input.mp4 -vcodec libx264 -crf 30 -preset veryfast -c:a copy -s 960x540 output.mp4

    



        09-13 11:06:28.330 10881-10881/someapp D/home: ffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
09-13 11:06:28.330 10881-10881/someapp D/home:   built with gcc 4.8 (GCC)
09-13 11:06:28.331 10881-10881/someapp D/home:   configuration: --target-os=linux --cross-prefix=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/vagrant/SourceCode/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/vagrant/SourceCode/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
09-13 11:06:28.331 10881-10881/someapp D/home:   libavutil      55. 17.103 / 55. 17.103
09-13 11:06:28.331 10881-10881/someapp D/home:   libavcodec     57. 24.102 / 57. 24.102
09-13 11:06:28.331 10881-10881/someapp D/home:   libavformat    57. 25.100 / 57. 25.100
09-13 11:06:28.331 10881-10881/someapp D/home:   libavdevice    57.  0.101 / 57.  0.101
09-13 11:06:28.331 10881-10881/someapp D/home:   libavfilter     6. 31.100 /  6. 31.100
09-13 11:06:28.331 10881-10881/someapp D/home:   libswscale      4.  0.100 /  4.  0.100
09-13 11:06:28.331 10881-10881/someapp D/home:   libswresample   2.  0.101 /  2.  0.101
09-13 11:06:28.331 10881-10881/someapp D/home:   libpostproc    54.  0.100 / 54.  0.100
09-13 11:06:28.430 10881-10881/someapp D/home: Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/ExpeditionSpot/Videos/20160913110411.mp4':
09-13 11:06:28.430 10881-10881/someapp D/home:   Metadata:
09-13 11:06:28.430 10881-10881/someapp D/home:     major_brand     : mp42
09-13 11:06:28.430 10881-10881/someapp D/home:     minor_version   : 0
09-13 11:06:28.430 10881-10881/someapp D/home:     compatible_brands: isommp42
09-13 11:06:28.430 10881-10881/someapp D/home:     creation_time   : 2016-09-13 17:04:33
09-13 11:06:28.430 10881-10881/someapp D/home:     com.android.version: 6.0.1
09-13 11:06:28.430 10881-10881/someapp D/home:   Duration: 00:00:19.41, start: 0.000000, bitrate: 20222 kb/s
09-13 11:06:28.430 10881-10881/someapp D/home:     Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, 19963 kb/s, SAR 1:1 DAR 16:9, 30.03 fps, 30 tbr, 90k tbn, 180k tbc (default)
09-13 11:06:28.430 10881-10881/someapp D/home:     Metadata:
09-13 11:06:28.430 10881-10881/someapp D/home:       creation_time   : 2016-09-13 17:04:33
09-13 11:06:28.430 10881-10881/someapp D/home:       handler_name    : VideoHandle
09-13 11:06:28.431 10881-10881/someapp D/home:     Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default)
09-13 11:06:28.431 10881-10881/someapp D/home:     Metadata:
09-13 11:06:28.431 10881-10881/someapp D/home:       creation_time   : 2016-09-13 17:04:33
09-13 11:06:28.431 10881-10881/someapp D/home:       handler_name    : SoundHandle
09-13 11:06:28.448 10881-10881/someapp D/home: [libx264 @ 0xf71c4400] using SAR=1/1
09-13 11:06:28.448 10881-10881/someapp D/home: [libx264 @ 0xf71c4400] using cpu capabilities: none!
09-13 11:06:28.516 10881-10881/someapp D/home: [libx264 @ 0xf71c4400] profile High, level 3.1
09-13 11:06:28.516 10881-10881/someapp D/home: [libx264 @ 0xf71c4400] 264 - core 148 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=12 lookahead_threads=4 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=1 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=10 rc=crf mbtree=1 crf=27.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
09-13 11:06:28.532 10881-10881/someapp D/home: Output #0, mp4, to '/storage/emulated/0/ExpeditionSpot/.tmp/small-20160913110411.mp4':
09-13 11:06:28.532 10881-10881/someapp D/home:   Metadata:
09-13 11:06:28.532 10881-10881/someapp D/home:     major_brand     : mp42
09-13 11:06:28.533 10881-10881/someapp D/home:     minor_version   : 0
09-13 11:06:28.533 10881-10881/someapp D/home:     compatible_brands: isommp42
09-13 11:06:28.533 10881-10881/someapp D/home:     com.android.version: 6.0.1
09-13 11:06:28.533 10881-10881/someapp D/home:     encoder         : Lavf57.25.100
09-13 11:06:28.533 10881-10881/someapp D/home:     Stream #0:0(eng): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 960x540 [SAR 1:1 DAR 16:9], q=-1--1, 30 fps, 15360 tbn, 30 tbc (default)
09-13 11:06:28.533 10881-10881/someapp D/home:     Metadata:
09-13 11:06:28.533 10881-10881/someapp D/home:       creation_time   : 2016-09-13 17:04:33
09-13 11:06:28.533 10881-10881/someapp D/home:       handler_name    : VideoHandle
09-13 11:06:28.533 10881-10881/someapp D/home:       encoder         : Lavc57.24.102 libx264
09-13 11:06:28.533 10881-10881/someapp D/home:     Side data:
09-13 11:06:28.533 10881-10881/someapp D/home:       unknown side data type 10 (24 bytes)
09-13 11:06:28.533 10881-10881/someapp D/home:     Stream #0:1(eng): Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, 96 kb/s (default)
09-13 11:06:28.533 10881-10881/someapp D/home:     Metadata:
09-13 11:06:28.533 10881-10881/someapp D/home:       creation_time   : 2016-09-13 17:04:33
09-13 11:06:28.533 10881-10881/someapp D/home:       handler_name    : SoundHandle
09-13 11:06:28.533 10881-10881/someapp D/home: Stream mapping:
09-13 11:06:28.533 10881-10881/someapp D/home:   Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
09-13 11:06:28.533 10881-10881/someapp D/home:   Stream #0:1 -> #0:1 (copy)
09-13 11:06:28.533 10881-10881/someapp D/home: Press [q] to stop, [?] for help
09-13 11:06:29.102 10881-10881/someapp D/home: frame=    7 fps=0.0 q=0.0 size=       0kB time=00:00:01.04 bitrate=   0.4kbits/s speed=2.08x    
09-13 11:06:29.699 10881-10881/someapp D/home: frame=   16 fps= 15 q=0.0 size=       0kB time=00:00:01.04 bitrate=   0.4kbits/s speed=0.998x    
....
09-13 11:07:12.674 10881-10881/someapp D/home: [libx264 @ 0xf71c4400] frame I:3     Avg QP:26.83  size: 21896
09-13 11:07:12.674 10881-10881/someapp D/home: [libx264 @ 0xf71c4400] frame P:279   Avg QP:28.76  size:  5859
09-13 11:07:12.674 10881-10881/someapp D/home: [libx264 @ 0xf71c4400] frame B:296   Avg QP:29.93  size:   863
09-13 11:07:12.674 10881-10881/someapp D/home: [libx264 @ 0xf71c4400] consecutive B-frames: 18.3% 32.2% 23.9% 25.6%
09-13 11:07:12.674 10881-10881/someapp D/home: [libx264 @ 0xf71c4400] mb I  I16..4: 16.9% 54.2% 28.9%
09-13 11:07:12.674 10881-10881/someapp D/home: [libx264 @ 0xf71c4400] mb P  I16..4:  7.7%  9.1%  0.4%  P16..4: 27.5% 11.1%  4.0%  0.0%  0.0%    skip:40.1%
09-13 11:07:12.674 10881-10881/someapp D/home: [libx264 @ 0xf71c4400] mb B  I16..4:  0.8%  0.6%  0.0%  B16..8: 10.9%  2.4%  0.1%  direct: 1.8%  skip:83.5%  L0:35.8% L1:54.2% BI:10.0%
09-13 11:07:12.675 10881-10881/someapp D/home: [libx264 @ 0xf71c4400] 8x8 transform intra:52.0% inter:41.3%
09-13 11:07:12.675 10881-10881/someapp D/home: [libx264 @ 0xf71c4400] coded y,uvDC,uvAC intra: 28.9% 26.0% 2.1% inter: 6.4% 5.0% 0.0%
09-13 11:07:12.675 10881-10881/someapp D/home: [libx264 @ 0xf71c4400] i16 v,h,dc,p: 57% 20% 17%  6%
09-13 11:07:12.675 10881-10881/someapp D/home: [libx264 @ 0xf71c4400] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 33% 23% 34%  1%  2%  1%  3%  2%  2%
09-13 11:07:12.675 10881-10881/someapp D/home: [libx264 @ 0xf71c4400] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 36% 21% 17%  2%  7%  4%  6%  4%  4%
09-13 11:07:12.675 10881-10881/someapp D/home: [libx264 @ 0xf71c4400] i8c dc,h,v,p: 59% 16% 23%  2%
09-13 11:07:12.675 10881-10881/someapp D/home: [libx264 @ 0xf71c4400] Weighted P-Frames: Y:16.8% UV:4.7%
09-13 11:07:12.675 10881-10881/someapp D/home: [libx264 @ 0xf71c4400] kb/s:812.09


    


  • Decoding pcm_s16le with FFMPEG ?

    9 juin, par Davide Caresia

    i have a problem decoding a wav file using ffmpeg. I'm new to it and i'm not quite used to it.

    


    In my application i have to input the audio file and get an array of samples to work on.
I used ffmpeg to create a function that gets in input the path of the file, the position in time where to start to output the samples and the lenght of the chunk to decode in seconds.

    


    When I try to decode the file harp.wav everything runs fine, and I can plot the samples as in the image plot-harp.png

    


    The file is a WAV file encoded as : pcm_u8, 11025 Hz, 1 channels, u8, 88 kb/s

    


    The problems comes when i try to decode the file demo-unprocessed.wav.
It outputs a series of samples that has no sense. It outputs a serie of samples plotted as the image graph1-demo.jpg shows.

    


    The file is a WAV file encoded as : pcm_s16le, 44100 Hz, 1 channels, s16, 705 kb/s

    


    IDK where the problem in my code is, I already checked the code before and after the decoding with FFMPEG, and it works absolutely fine.

    


    Here is the code for the dataReader.cpp :

    


    /* Start by including the necessary */&#xA;#include "dataReader.h"&#xA;#include <cstdlib>&#xA;#include <iostream>&#xA;#include <fstream>&#xA;&#xA;#ifdef __cplusplus&#xA;extern "C" {&#xA;#endif&#xA;    #include <libavcodec></libavcodec>avcodec.h> &#xA;    #include <libavformat></libavformat>avformat.h>&#xA;    #include <libavutil></libavutil>avutil.h>&#xA;#ifdef __cplusplus &#xA;}&#xA;#endif&#xA;&#xA;using namespace std;&#xA;&#xA;/* initialization function for audioChunk */&#xA;audioChunk::audioChunk(){&#xA;    data=NULL;&#xA;    size=0;&#xA;    bitrate=0;&#xA;}&#xA;&#xA;/* function to get back chunk lenght in seconds */&#xA;int audioChunk::getTimeLenght(){&#xA;    return size/bitrate;&#xA;}&#xA;&#xA;/* initialization function for audioChunk_dNorm */&#xA;audioChunk_dNorm::audioChunk_dNorm(){&#xA;    data=NULL;&#xA;    size=0;&#xA;    bitrate=0;&#xA;}&#xA;&#xA;/* function to get back chunk lenght in seconds */&#xA;int audioChunk_dNorm::getTimeLenght(){&#xA;    return size/bitrate;&#xA;}&#xA;&#xA;/* function to normalize audioChunk into audioChunk_dNorm */&#xA;void audioChunk_dNorm::fillAudioChunk(audioChunk* cnk){&#xA;&#xA;    size=cnk->size;&#xA;    bitrate=cnk->bitrate;&#xA;&#xA;    double min=cnk->data[0];&#xA;    double max=cnk->data[0];&#xA;&#xA;    for(int i=0;isize;i&#x2B;&#x2B;){&#xA;        if(*(cnk->data&#x2B;i)>max) max=*(cnk->data&#x2B;i);&#xA;        else if(*(cnk->data&#x2B;i)data&#x2B;i);&#xA;    }&#xA;&#xA;    data=new double[size];&#xA;&#xA;    for(int i=0;i/data[i]=cnk->data[i]&#x2B;256*data[i&#x2B;1];&#xA;        if(data[i]!=255) data[i]=2*((cnk->data[i])-(max-min)/2)/(max-min);&#xA;        else data[i]=0;&#xA;    }&#xA;    cout&lt;&lt;"bitrate "&lt;* inizialize audioChunk */&#xA;    audioChunk output;&#xA;&#xA;    /* Check input times */&#xA;    if((start_time&lt;0)||(lenght&lt;0)) {&#xA;        cout&lt;&lt;"Input times should be positive";&#xA;        return output;&#xA;    }&#xA;&#xA;    /* Start FFmpeg */&#xA;    av_register_all();&#xA;&#xA;    /* Initialize the frame to read the data and verify memory allocation */&#xA;    AVFrame* frame = av_frame_alloc();&#xA;    if (!frame)&#xA;    {&#xA;        cout &lt;&lt; "Error allocating the frame" &lt;&lt; endl;&#xA;        return output;&#xA;    }&#xA;&#xA;    /* Initialization of the Context, to open the file */&#xA;    AVFormatContext* formatContext = NULL;&#xA;    /* Opening the file, and check if it has opened */&#xA;    if (avformat_open_input(&amp;formatContext, path_name, NULL, NULL) != 0)&#xA;    {&#xA;        av_frame_free(&amp;frame);&#xA;        cout &lt;&lt; "Error opening the file" &lt;&lt; endl;&#xA;        return output;&#xA;    }&#xA;&#xA;    /* Find the stream info, if not found, exit */&#xA;    if (avformat_find_stream_info(formatContext, NULL) &lt; 0)&#xA;    {&#xA;        av_frame_free(&amp;frame);&#xA;        avformat_close_input(&amp;formatContext);&#xA;        cout &lt;&lt; "Error finding the stream info" &lt;&lt; endl;&#xA;        return output;&#xA;    }&#xA;&#xA;    /* Check inputs to verify time input */&#xA;    if(start_time>(formatContext->duration/1000000)){&#xA;        cout&lt;&lt; "Error, start_time is over file duration"&lt;* Chunk = number of samples to output */&#xA;    long long int chunk = ((formatContext->bit_rate)*lenght/8);&#xA;    /* Start = address of sample where start to read */&#xA;    long long int start = ((formatContext->bit_rate)*start_time/8);&#xA;    /* Tot_sampl = number of the samples in the file */&#xA;    long long int tot_sampl = (formatContext->bit_rate)*(formatContext->duration)/8000000;&#xA;&#xA;    /* Set the lenght of chunk to avoid segfault and to read all the file */&#xA;    if (start&#x2B;chunk>tot_sampl) {chunk = tot_sampl-start;}&#xA;    if (lenght==0) {start = 0; chunk = tot_sampl;}&#xA;&#xA;    /* initialize the array to output */&#xA;    output.data = new unsigned char[chunk];&#xA;    output.bitrate = formatContext->bit_rate;&#xA;    output.size=chunk;&#xA;&#xA;    av_dump_format(formatContext,0,NULL,0);&#xA;    cout&lt;* Find the audio Stream, if no audio stream are found, clean and exit */&#xA;    AVCodec* cdc = NULL;&#xA;    int streamIndex = av_find_best_stream(formatContext, AVMEDIA_TYPE_AUDIO, -1, -1, &amp;cdc, 0);&#xA;    if (streamIndex &lt; 0)&#xA;    {&#xA;        av_frame_free(&amp;frame);&#xA;        avformat_close_input(&amp;formatContext);&#xA;        cout &lt;&lt; "Could not find any audio stream in the file" &lt;&lt; endl;&#xA;        return output;&#xA;    }&#xA;&#xA;    /* Open the audio stream to read data  in audioStream */&#xA;    AVStream* audioStream = formatContext->streams[streamIndex];&#xA;&#xA;    /* Initialize the codec context */&#xA;    AVCodecContext* codecContext = audioStream->codec;&#xA;    codecContext->codec = cdc;&#xA;    /* Open the codec, and verify if it has opened */&#xA;    if (avcodec_open2(codecContext, codecContext->codec, NULL) != 0)&#xA;    {&#xA;        av_frame_free(&amp;frame);&#xA;        avformat_close_input(&amp;formatContext);&#xA;        cout &lt;&lt; "Couldn&#x27;t open the context with the decoder" &lt;&lt; endl;&#xA;        return output;&#xA;    }&#xA;&#xA;    /* Initialize buffer to store compressed packets */&#xA;    AVPacket readingPacket;&#xA;    av_init_packet(&amp;readingPacket);&#xA;&#xA;&#xA;    int j=0;&#xA;    int count = 0; &#xA;&#xA;    while(av_read_frame(formatContext, &amp;readingPacket)==0){&#xA;        if((count&#x2B;readingPacket.size)>start){&#xA;            if(readingPacket.stream_index == audioStream->index){&#xA;&#xA;                AVPacket decodingPacket = readingPacket;&#xA;&#xA;                // Audio packets can have multiple audio frames in a single packet&#xA;                while (decodingPacket.size > 0){&#xA;                    // Try to decode the packet into a frame&#xA;                    // Some frames rely on multiple packets, so we have to make sure the frame is finished before&#xA;                    // we can use it&#xA;                    int gotFrame = 0;&#xA;                    int result = avcodec_decode_audio4(codecContext, frame, &amp;gotFrame, &amp;decodingPacket);&#xA;&#xA;                    count &#x2B;= result;&#xA;&#xA;                    if (result >= 0 &amp;&amp; gotFrame)&#xA;                    {&#xA;                        decodingPacket.size -= result;&#xA;                        decodingPacket.data &#x2B;= result;&#xA;                        int a;&#xA;&#xA;                        for(int i=0;idata[0][i];&#xA;&#xA;                            j&#x2B;&#x2B;;&#xA;                            if(j>=chunk) break;&#xA;                        }&#xA;&#xA;                        // We now have a fully decoded audio frame&#xA;                    }&#xA;                    else&#xA;                    {&#xA;                        decodingPacket.size = 0;&#xA;                        decodingPacket.data = NULL;&#xA;                    }&#xA;                    if(j>=chunk) break;&#xA;                }&#xA;            }              &#xA;        }else count&#x2B;=readingPacket.size;&#xA;&#xA;        // To prevent memory leak, must free packet.&#xA;        av_free_packet(&amp;readingPacket);&#xA;        if(j>=chunk) break;&#xA;    }&#xA;&#xA;    // Some codecs will cause frames to be buffered up in the decoding process. If the CODEC_CAP_DELAY flag&#xA;    // is set, there can be buffered up frames that need to be flushed, so we&#x27;ll do that&#xA;    if (codecContext->codec->capabilities &amp; CODEC_CAP_DELAY)&#xA;    {&#xA;        av_init_packet(&amp;readingPacket);&#xA;        // Decode all the remaining frames in the buffer, until the end is reached&#xA;        int gotFrame = 0;&#xA;        int a;&#xA;        int result=avcodec_decode_audio4(codecContext, frame, &amp;gotFrame, &amp;readingPacket);&#xA;        while (result >= 0 &amp;&amp; gotFrame)&#xA;        {&#xA;            // We now have a fully decoded audio frame&#xA;            for(int i=0;idata[0][i];&#xA;&#xA;                j&#x2B;&#x2B;;&#xA;                if(j>=chunk) break;&#xA;            }&#xA;            if(j>=chunk) break;&#xA;        }&#xA;    }&#xA;&#xA;    // Clean up!&#xA;    av_free(frame);&#xA;    avcodec_close(codecContext);&#xA;    avformat_close_input(&amp;formatContext);&#xA;&#xA;    cout&lt;&lt;"Ended Reading, "&lt;code></fstream></iostream></cstdlib>

    &#xA;

    Here is the dataReader.h

    &#xA;

    /* &#xA; * File:   dataReader.h&#xA; * Author: davide&#xA; *&#xA; * Created on 27 luglio 2015, 11.11&#xA; */&#xA;&#xA;#ifndef DATAREADER_H&#xA;#define DATAREADER_H&#xA;&#xA;/* function that reads a file and outputs an array of samples&#xA; * @ path_name = the path of the file to read&#xA; * @ start_time = the position where to start the data reading, 0 = start&#xA; *                the time is in seconds, it can hold to 10e-6 seconds&#xA; * @ lenght = the lenght of the frame to extract the data, &#xA; *            0 = read all the file (do not use with big files)&#xA; *            if lenght > of file duration, it reads through the end of file.&#xA; *            the time is in seconds, it can hold to 10e-6 seconds  &#xA; */&#xA;&#xA;#include &#xA;&#xA;class audioChunk{&#xA;public:&#xA;    uint8_t *data;&#xA;    unsigned int size;&#xA;    int bitrate;&#xA;    int getTimeLenght();&#xA;    audioChunk();&#xA;};&#xA;&#xA;class audioChunk_dNorm{&#xA;public:&#xA;    double* data;&#xA;    unsigned int size;&#xA;    int bitrate;&#xA;    int getTimeLenght();&#xA;    void fillAudioChunk(audioChunk* cnk);&#xA;    audioChunk_dNorm();&#xA;};&#xA;&#xA;audioChunk readData(const char* path_name, const double start_time, const double lenght);&#xA;&#xA;#endif  /* DATAREADER_H */&#xA;

    &#xA;

    And finally there is the main.cpp of the application.

    &#xA;

    /* &#xA; * File:   main.cpp&#xA; * Author: davide&#xA; *&#xA; * Created on 28 luglio 2015, 17.04&#xA; */&#xA;&#xA;#include <cstdlib>&#xA;#include "dataReader.h"&#xA;#include "transforms.h"&#xA;#include "tognuplot.h"&#xA;#include <fstream>&#xA;#include <iostream>&#xA;&#xA;using namespace std;&#xA;&#xA;/*&#xA; * &#xA; */&#xA;int main(int argc, char** argv) {&#xA;&#xA;    audioChunk *chunk1=new audioChunk;&#xA;&#xA;    audioChunk_dNorm *normChunk1=new audioChunk_dNorm;&#xA;&#xA;    *chunk1=readData("./audio/demo-unprocessed.wav",0,1);&#xA;&#xA;    normChunk1->fillAudioChunk(chunk1);&#xA;&#xA;    ofstream file1;&#xA;    file1.open("./file/2wave.txt", std::ofstream::trunc);&#xA;    if(file1.is_open()) {&#xA;        for(int i=0;isize;i&#x2B;&#x2B;) {&#xA;            int a=chunk1->data[i];&#xA;            file1&lt;code></iostream></fstream></cstdlib>

    &#xA;

    I can't understand why the outputs goes like this. Is it possible that the decoder can't convert the samples (pcm_16le, 16bits) into FFMPEG AVFrame.data, that stores the samples ad uint8_t ? And if it is it is there some way to make FFMPEG work for audio files that stores samples at more than 8 bits ?

    &#xA;

    The file graph1-demo_good.jpg is how the samples should be, extracted with a working LIBSNDFILE application that I made.

    &#xA;

    EDIT : Seems like the program can't convert the decoded data, couples of little endian bytes stored in a couple of uint8_t unsigned char, into the destination format (that i set as unsigned char[]), because it stores the bits as little-endian 16 bytes. So the data into audioChunk.data is right, but I have to read it not as an unsigned char, but as a couple of little-endian bytes.

    &#xA;

  • ffmpeg command to add moving text watermark to video [closed]

    13 octobre 2023, par Imran Khan
    &#xD;&#xA;
    &#xD;&#xA;
            // Constants for watermark movement, direction change intervals, fade intervals, and overlap duration&#xA;        const MOVE_SPEED = 3;&#xA;        const DIRECTION_CHANGE_MIN = 3000;&#xA;        const DIRECTION_CHANGE_MAX = 6000;&#xA;        const FADE_INTERVAL_MIN = 10000;&#xA;        const FADE_INTERVAL_MAX = 20000;&#xA;        const OVERLAP_DURATION = 2000;&#xA;&#xA;        // Get references to the video container and watermarks&#xA;        const container = document.querySelector(&#x27;.video-container&#x27;);&#xA;        const watermark1 = document.getElementById(&#x27;watermark1&#x27;);&#xA;        const watermark2 = document.getElementById(&#x27;watermark2&#x27;);&#xA;&#xA;        // Helper function to get a random integer between min and max (inclusive)&#xA;        function getRandomInt(min, max) {&#xA;            return Math.floor(Math.random() * (max - min &#x2B; 1)) &#x2B; min;&#xA;        }&#xA;&#xA;        // Helper function to get a random direction (either 1 or -1)&#xA;        function getRandomDirection() {&#xA;            return Math.random() > 0.5 ? 1 : -1;&#xA;        }&#xA;&#xA;        // Set the initial position of the watermark inside the video container&#xA;        function setInitialPosition(watermark) {&#xA;            const x = getRandomInt(0, container.offsetWidth - watermark.offsetWidth);&#xA;            const y = getRandomInt(0, container.offsetHeight - watermark.offsetHeight);&#xA;            watermark.style.left = `${x}px`;&#xA;            watermark.style.top = `${y}px`;&#xA;            watermark.style.opacity = 1;&#xA;        }&#xA;&#xA;        // Function to handle continuous movement of the watermark&#xA;        function continuousMove(watermark) {&#xA;            let dx = getRandomDirection() * MOVE_SPEED;&#xA;            let dy = getRandomDirection() * MOVE_SPEED;&#xA;&#xA;            // Inner function to handle the actual movement logic&#xA;            function move() {&#xA;                let x = parseInt(watermark.style.left || 0) &#x2B; dx;&#xA;                let y = parseInt(watermark.style.top || 0) &#x2B; dy;&#xA;&#xA;                // Check boundaries and reverse direction if necessary&#xA;                if (x &lt; 0 || x > container.offsetWidth - watermark.offsetWidth) {&#xA;                    dx = -dx;&#xA;                }&#xA;                if (y &lt; 0 || y > container.offsetHeight - watermark.offsetHeight) {&#xA;                    dy = -dy;&#xA;                }&#xA;&#xA;                // Apply the new position&#xA;                watermark.style.left = `${x}px`;&#xA;                watermark.style.top = `${y}px`;&#xA;&#xA;                // Continue moving&#xA;                setTimeout(move, 100);&#xA;            }&#xA;&#xA;            move();&#xA;&#xA;            // Change direction at random intervals&#xA;            setInterval(() => {&#xA;                const randomChoice = Math.random();&#xA;                if (randomChoice &lt; 0.33) {&#xA;                    dx = getRandomDirection() * MOVE_SPEED;&#xA;                    dy = 0;&#xA;                } else if (randomChoice &lt; 0.66) {&#xA;                    dy = getRandomDirection() * MOVE_SPEED;&#xA;                    dx = 0;&#xA;                } else {&#xA;                    dx = getRandomDirection() * MOVE_SPEED;&#xA;                    dy = getRandomDirection() * MOVE_SPEED;&#xA;                }&#xA;            }, getRandomInt(DIRECTION_CHANGE_MIN, DIRECTION_CHANGE_MAX));&#xA;        }&#xA;&#xA;        // Handle the fading out of the old watermark and fading in of the new watermark&#xA;        function fadeOutAndIn(oldWatermark, newWatermark) {&#xA;            setTimeout(() => {&#xA;                setInitialPosition(newWatermark);&#xA;                newWatermark.style.opacity = 1;&#xA;            }, 0);&#xA;&#xA;            setTimeout(() => {&#xA;                oldWatermark.style.opacity = 0;&#xA;            }, OVERLAP_DURATION);&#xA;&#xA;            // Continue the cycle&#xA;            setTimeout(() => fadeOutAndIn(newWatermark, oldWatermark), getRandomInt(FADE_INTERVAL_MIN, FADE_INTERVAL_MAX));&#xA;        }&#xA;&#xA;        // Initialize the watermarks&#xA;        setInitialPosition(watermark1);&#xA;        continuousMove(watermark1);&#xA;        setTimeout(() => fadeOutAndIn(watermark1, watermark2), getRandomInt(FADE_INTERVAL_MIN, FADE_INTERVAL_MAX));&#xA;        continuousMove(watermark2);&#xA;    

    &#xD;&#xA;

    body, html {&#xA;            height: 100%;&#xA;            margin: 0;&#xA;            font-family: Arial, sans-serif;&#xA;            display: flex;&#xA;            justify-content: center;&#xA;            align-items: center;&#xA;            background-color: #eee;&#xA;        }&#xA;&#xA;        .video-container {&#xA;            width: 50vw;&#xA;            height: 50vh;&#xA;            background-color: black;&#xA;            position: relative;&#xA;            overflow: hidden;&#xA;        }&#xA;&#xA;        .watermark {&#xA;            font-size: 22px;&#xA;            position: absolute;&#xA;            color: white;&#xA;            opacity: 0;&#xA;            transition: opacity 2s;&#xA;        }

    &#xD;&#xA;

    &#xA;&#xA;&#xA;    &#xA;    &#xA;    &#xA;&#xA;&#xA;    <div class="video-container">&#xA;        <span class="watermark">watermark</span>&#xA;        <span class="watermark">watermark</span>&#xA;    </div>&#xA;    &#xA;&#xA;

    &#xD;&#xA;

    &#xD;&#xA;

    &#xD;&#xA;&#xA;

    I am trying to achieve an animation effect using ffmpeg. I am adding text watermark to an input video and animate the text diagonally, horizontally or vertically changed randomly. Here is what I have achieved so far.

    &#xA;

    ffmpeg -i video.mp4 -c:v libx264 -preset veryfast -crf 25 -tune zerolatency -vendor ap10 -pix_fmt yuv420p -filter:v "drawtext=fontfile=./fonts/Roboto/Roboto-Light.ttf:text=&#x27;Watermark&#x27;:fontcolor=white:alpha=0.5:fontsize=60:y=h/10*mod(t\,10):x=w/10*mod(t\,10):enable=1" -c:a copy watermark.mp4

    &#xA;

    Here is what I want it to work.

    &#xA;

    Initial Position :&#xA;The watermark randomly placed in the video the first time they appear.

    &#xA;

    Continuous Movement :&#xA;The watermark continuously moves within the video.&#xA;The direction and speed of the watermark's movement are random. It can move diagonally, purely horizontally, or purely vertically.&#xA;When the watermark reaches the boundaries of the video, it bounces back, changing its direction.

    &#xA;

    Direction Change :&#xA;During its continuous movement, the watermark will suddenly change its direction at random intervals between 3 to 6 seconds.&#xA;When changing direction, the watermark can randomly determined move diagonally, purely horizontally, or purely vertically.

    &#xA;

    Fade In and Out :&#xA;Every 10 to 20 seconds (randomly determined), the current watermark begins to fade out.&#xA;As the old watermark starts to fade out, a new watermark fades in at a random position, ensuring that there's always a visible watermark on the screen.&#xA;These two watermarks (the fading old one and the emerging new one) overlap on the screen for a duration of 2 seconds, after which the old watermark completely disappears.&#xA;These patterns and characteristics together provide a dynamic, constantly moving, and changing watermark for the video

    &#xA;

    To achieve the result I think we can use the drawtext multiple times. I have attached the HTML and JavaScript variant just for the reference to understand the result but I am trying to do this using ffmpeg.

    &#xA;