
Recherche avancée
Médias (2)
-
Rennes Emotion Map 2010-11
19 octobre 2011, par
Mis à jour : Juillet 2013
Langue : français
Type : Texte
-
Carte de Schillerkiez
13 mai 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Texte
Autres articles (54)
-
MediaSPIP version 0.1 Beta
16 avril 2011, parMediaSPIP 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, parMediaSPIP 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 2013Jolie 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 HolmesI'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 Caresiai 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 */
#include "dataReader.h"
#include <cstdlib>
#include <iostream>
#include <fstream>

#ifdef __cplusplus
extern "C" {
#endif
 #include <libavcodec></libavcodec>avcodec.h> 
 #include <libavformat></libavformat>avformat.h>
 #include <libavutil></libavutil>avutil.h>
#ifdef __cplusplus 
}
#endif

using namespace std;

/* initialization function for audioChunk */
audioChunk::audioChunk(){
 data=NULL;
 size=0;
 bitrate=0;
}

/* function to get back chunk lenght in seconds */
int audioChunk::getTimeLenght(){
 return size/bitrate;
}

/* initialization function for audioChunk_dNorm */
audioChunk_dNorm::audioChunk_dNorm(){
 data=NULL;
 size=0;
 bitrate=0;
}

/* function to get back chunk lenght in seconds */
int audioChunk_dNorm::getTimeLenght(){
 return size/bitrate;
}

/* function to normalize audioChunk into audioChunk_dNorm */
void audioChunk_dNorm::fillAudioChunk(audioChunk* cnk){

 size=cnk->size;
 bitrate=cnk->bitrate;

 double min=cnk->data[0];
 double max=cnk->data[0];

 for(int i=0;isize;i++){
 if(*(cnk->data+i)>max) max=*(cnk->data+i);
 else if(*(cnk->data+i)data+i);
 }

 data=new double[size];

 for(int i=0;i/data[i]=cnk->data[i]+256*data[i+1];
 if(data[i]!=255) data[i]=2*((cnk->data[i])-(max-min)/2)/(max-min);
 else data[i]=0;
 }
 cout<<"bitrate "<* inizialize audioChunk */
 audioChunk output;

 /* Check input times */
 if((start_time<0)||(lenght<0)) {
 cout<<"Input times should be positive";
 return output;
 }

 /* Start FFmpeg */
 av_register_all();

 /* Initialize the frame to read the data and verify memory allocation */
 AVFrame* frame = av_frame_alloc();
 if (!frame)
 {
 cout << "Error allocating the frame" << endl;
 return output;
 }

 /* Initialization of the Context, to open the file */
 AVFormatContext* formatContext = NULL;
 /* Opening the file, and check if it has opened */
 if (avformat_open_input(&formatContext, path_name, NULL, NULL) != 0)
 {
 av_frame_free(&frame);
 cout << "Error opening the file" << endl;
 return output;
 }

 /* Find the stream info, if not found, exit */
 if (avformat_find_stream_info(formatContext, NULL) < 0)
 {
 av_frame_free(&frame);
 avformat_close_input(&formatContext);
 cout << "Error finding the stream info" << endl;
 return output;
 }

 /* Check inputs to verify time input */
 if(start_time>(formatContext->duration/1000000)){
 cout<< "Error, start_time is over file duration"<* Chunk = number of samples to output */
 long long int chunk = ((formatContext->bit_rate)*lenght/8);
 /* Start = address of sample where start to read */
 long long int start = ((formatContext->bit_rate)*start_time/8);
 /* Tot_sampl = number of the samples in the file */
 long long int tot_sampl = (formatContext->bit_rate)*(formatContext->duration)/8000000;

 /* Set the lenght of chunk to avoid segfault and to read all the file */
 if (start+chunk>tot_sampl) {chunk = tot_sampl-start;}
 if (lenght==0) {start = 0; chunk = tot_sampl;}

 /* initialize the array to output */
 output.data = new unsigned char[chunk];
 output.bitrate = formatContext->bit_rate;
 output.size=chunk;

 av_dump_format(formatContext,0,NULL,0);
 cout<* Find the audio Stream, if no audio stream are found, clean and exit */
 AVCodec* cdc = NULL;
 int streamIndex = av_find_best_stream(formatContext, AVMEDIA_TYPE_AUDIO, -1, -1, &cdc, 0);
 if (streamIndex < 0)
 {
 av_frame_free(&frame);
 avformat_close_input(&formatContext);
 cout << "Could not find any audio stream in the file" << endl;
 return output;
 }

 /* Open the audio stream to read data in audioStream */
 AVStream* audioStream = formatContext->streams[streamIndex];

 /* Initialize the codec context */
 AVCodecContext* codecContext = audioStream->codec;
 codecContext->codec = cdc;
 /* Open the codec, and verify if it has opened */
 if (avcodec_open2(codecContext, codecContext->codec, NULL) != 0)
 {
 av_frame_free(&frame);
 avformat_close_input(&formatContext);
 cout << "Couldn't open the context with the decoder" << endl;
 return output;
 }

 /* Initialize buffer to store compressed packets */
 AVPacket readingPacket;
 av_init_packet(&readingPacket);


 int j=0;
 int count = 0; 

 while(av_read_frame(formatContext, &readingPacket)==0){
 if((count+readingPacket.size)>start){
 if(readingPacket.stream_index == audioStream->index){

 AVPacket decodingPacket = readingPacket;

 // Audio packets can have multiple audio frames in a single packet
 while (decodingPacket.size > 0){
 // Try to decode the packet into a frame
 // Some frames rely on multiple packets, so we have to make sure the frame is finished before
 // we can use it
 int gotFrame = 0;
 int result = avcodec_decode_audio4(codecContext, frame, &gotFrame, &decodingPacket);

 count += result;

 if (result >= 0 && gotFrame)
 {
 decodingPacket.size -= result;
 decodingPacket.data += result;
 int a;

 for(int i=0;idata[0][i];

 j++;
 if(j>=chunk) break;
 }

 // We now have a fully decoded audio frame
 }
 else
 {
 decodingPacket.size = 0;
 decodingPacket.data = NULL;
 }
 if(j>=chunk) break;
 }
 } 
 }else count+=readingPacket.size;

 // To prevent memory leak, must free packet.
 av_free_packet(&readingPacket);
 if(j>=chunk) break;
 }

 // Some codecs will cause frames to be buffered up in the decoding process. If the CODEC_CAP_DELAY flag
 // is set, there can be buffered up frames that need to be flushed, so we'll do that
 if (codecContext->codec->capabilities & CODEC_CAP_DELAY)
 {
 av_init_packet(&readingPacket);
 // Decode all the remaining frames in the buffer, until the end is reached
 int gotFrame = 0;
 int a;
 int result=avcodec_decode_audio4(codecContext, frame, &gotFrame, &readingPacket);
 while (result >= 0 && gotFrame)
 {
 // We now have a fully decoded audio frame
 for(int i=0;idata[0][i];

 j++;
 if(j>=chunk) break;
 }
 if(j>=chunk) break;
 }
 }

 // Clean up!
 av_free(frame);
 avcodec_close(codecContext);
 avformat_close_input(&formatContext);

 cout<<"Ended Reading, "<code></fstream></iostream></cstdlib>


Here is the dataReader.h


/* 
 * File: dataReader.h
 * Author: davide
 *
 * Created on 27 luglio 2015, 11.11
 */

#ifndef DATAREADER_H
#define DATAREADER_H

/* function that reads a file and outputs an array of samples
 * @ path_name = the path of the file to read
 * @ start_time = the position where to start the data reading, 0 = start
 * the time is in seconds, it can hold to 10e-6 seconds
 * @ lenght = the lenght of the frame to extract the data, 
 * 0 = read all the file (do not use with big files)
 * if lenght > of file duration, it reads through the end of file.
 * the time is in seconds, it can hold to 10e-6 seconds 
 */

#include 

class audioChunk{
public:
 uint8_t *data;
 unsigned int size;
 int bitrate;
 int getTimeLenght();
 audioChunk();
};

class audioChunk_dNorm{
public:
 double* data;
 unsigned int size;
 int bitrate;
 int getTimeLenght();
 void fillAudioChunk(audioChunk* cnk);
 audioChunk_dNorm();
};

audioChunk readData(const char* path_name, const double start_time, const double lenght);

#endif /* DATAREADER_H */



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


/* 
 * File: main.cpp
 * Author: davide
 *
 * Created on 28 luglio 2015, 17.04
 */

#include <cstdlib>
#include "dataReader.h"
#include "transforms.h"
#include "tognuplot.h"
#include <fstream>
#include <iostream>

using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {

 audioChunk *chunk1=new audioChunk;

 audioChunk_dNorm *normChunk1=new audioChunk_dNorm;

 *chunk1=readData("./audio/demo-unprocessed.wav",0,1);

 normChunk1->fillAudioChunk(chunk1);

 ofstream file1;
 file1.open("./file/2wave.txt", std::ofstream::trunc);
 if(file1.is_open()) {
 for(int i=0;isize;i++) {
 int a=chunk1->data[i];
 file1<code></iostream></fstream></cstdlib>


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 ?


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


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.


-
ffmpeg command to add moving text watermark to video [closed]
13 octobre 2023, par Imran Khan

// Constants for watermark movement, direction change intervals, fade intervals, and overlap duration
 const MOVE_SPEED = 3;
 const DIRECTION_CHANGE_MIN = 3000;
 const DIRECTION_CHANGE_MAX = 6000;
 const FADE_INTERVAL_MIN = 10000;
 const FADE_INTERVAL_MAX = 20000;
 const OVERLAP_DURATION = 2000;

 // Get references to the video container and watermarks
 const container = document.querySelector('.video-container');
 const watermark1 = document.getElementById('watermark1');
 const watermark2 = document.getElementById('watermark2');

 // Helper function to get a random integer between min and max (inclusive)
 function getRandomInt(min, max) {
 return Math.floor(Math.random() * (max - min + 1)) + min;
 }

 // Helper function to get a random direction (either 1 or -1)
 function getRandomDirection() {
 return Math.random() > 0.5 ? 1 : -1;
 }

 // Set the initial position of the watermark inside the video container
 function setInitialPosition(watermark) {
 const x = getRandomInt(0, container.offsetWidth - watermark.offsetWidth);
 const y = getRandomInt(0, container.offsetHeight - watermark.offsetHeight);
 watermark.style.left = `${x}px`;
 watermark.style.top = `${y}px`;
 watermark.style.opacity = 1;
 }

 // Function to handle continuous movement of the watermark
 function continuousMove(watermark) {
 let dx = getRandomDirection() * MOVE_SPEED;
 let dy = getRandomDirection() * MOVE_SPEED;

 // Inner function to handle the actual movement logic
 function move() {
 let x = parseInt(watermark.style.left || 0) + dx;
 let y = parseInt(watermark.style.top || 0) + dy;

 // Check boundaries and reverse direction if necessary
 if (x < 0 || x > container.offsetWidth - watermark.offsetWidth) {
 dx = -dx;
 }
 if (y < 0 || y > container.offsetHeight - watermark.offsetHeight) {
 dy = -dy;
 }

 // Apply the new position
 watermark.style.left = `${x}px`;
 watermark.style.top = `${y}px`;

 // Continue moving
 setTimeout(move, 100);
 }

 move();

 // Change direction at random intervals
 setInterval(() => {
 const randomChoice = Math.random();
 if (randomChoice < 0.33) {
 dx = getRandomDirection() * MOVE_SPEED;
 dy = 0;
 } else if (randomChoice < 0.66) {
 dy = getRandomDirection() * MOVE_SPEED;
 dx = 0;
 } else {
 dx = getRandomDirection() * MOVE_SPEED;
 dy = getRandomDirection() * MOVE_SPEED;
 }
 }, getRandomInt(DIRECTION_CHANGE_MIN, DIRECTION_CHANGE_MAX));
 }

 // Handle the fading out of the old watermark and fading in of the new watermark
 function fadeOutAndIn(oldWatermark, newWatermark) {
 setTimeout(() => {
 setInitialPosition(newWatermark);
 newWatermark.style.opacity = 1;
 }, 0);

 setTimeout(() => {
 oldWatermark.style.opacity = 0;
 }, OVERLAP_DURATION);

 // Continue the cycle
 setTimeout(() => fadeOutAndIn(newWatermark, oldWatermark), getRandomInt(FADE_INTERVAL_MIN, FADE_INTERVAL_MAX));
 }

 // Initialize the watermarks
 setInitialPosition(watermark1);
 continuousMove(watermark1);
 setTimeout(() => fadeOutAndIn(watermark1, watermark2), getRandomInt(FADE_INTERVAL_MIN, FADE_INTERVAL_MAX));
 continuousMove(watermark2);



body, html {
 height: 100%;
 margin: 0;
 font-family: Arial, sans-serif;
 display: flex;
 justify-content: center;
 align-items: center;
 background-color: #eee;
 }

 .video-container {
 width: 50vw;
 height: 50vh;
 background-color: black;
 position: relative;
 overflow: hidden;
 }

 .watermark {
 font-size: 22px;
 position: absolute;
 color: white;
 opacity: 0;
 transition: opacity 2s;
 }





 
 
 


 <div class="video-container">
 <span class="watermark">watermark</span>
 <span class="watermark">watermark</span>
 </div>
 









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.


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='Watermark':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


Here is what I want it to work.


Initial Position :
The watermark randomly placed in the video the first time they appear.


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


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


Fade In and Out :
Every 10 to 20 seconds (randomly determined), the current watermark begins to fade out.
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.
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.
These patterns and characteristics together provide a dynamic, constantly moving, and changing watermark for the video


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.