
Recherche avancée
Autres articles (65)
-
Personnaliser en ajoutant son logo, sa bannière ou son image de fond
5 septembre 2013, parCertains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;
-
Publier sur MédiaSpip
13 juin 2013Puis-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 -
XMP PHP
13 mai 2011, parDixit Wikipedia, XMP signifie :
Extensible Metadata Platform ou XMP est un format de métadonnées basé sur XML utilisé dans les applications PDF, de photographie et de graphisme. Il a été lancé par Adobe Systems en avril 2001 en étant intégré à la version 5.0 d’Adobe Acrobat.
Étant basé sur XML, il gère un ensemble de tags dynamiques pour l’utilisation dans le cadre du Web sémantique.
XMP permet d’enregistrer sous forme d’un document XML des informations relatives à un fichier : titre, auteur, historique (...)
Sur d’autres sites (7401)
-
FFmpeg : What re-encoding settings can be used to achieve results similar to Google Drive's video processing ?
4 août 2023, par Mycroft_47Context :


I have a large collection of videos recorded by my phone's camera, which is taking up a significant amount of space. Recently, I noticed that when I uploaded a video to Google Drive and then downloaded it again using IDM (by clicking on the pop-up that IDM displays when it detects something that can be downloaded here's what i mean), the downloaded video retained the same visual quality but occupied much less space. Upon further research, I discovered that Google re-encodes uploaded videos using H.264 video encoding, and I believe I can achieve similar compression using FFmpeg.


Problem :


Despite experimenting with various FFmpeg commands, I haven't been able to replicate Google Drive's compression. Every attempt using
-codec:v libx264
option alone resulted in videos larger than the original files.

While adjusting the
-crf
parameter to a higher value and opting for a faster-preset
option did yield smaller file sizes, it unfortunately came at the cost of a noticeable degradation in visual quality and the appearance of some visible artifacts in the video.

Google Drive's processing, on the other hand, strikes a commendable balance, achieving a satisfactory file size without compromising visual clarity, (I should note that upon zooming in on this video, I observed some minor blurring, but it was acceptable to me).


Note :


I'm aware that using the H.265 video encoder instead of H.264 may give better results. However, to ensure fairness and avoid any potential bias, I think the optimal approach is first to find the best command using the H.264 video encoder. Once identified, I can then replace
-codec:v libx264
with-codec:v libx265
. This approach will ensure that the chosen command is really the best that FFMPEG can achieve, and that it is not solely influenced by the superior performance of H.265 when used from the outset.

Here's the FFMPEG command I am currently using :


ffmpeg -hide_banner -loglevel verbose ^
 -i input.mp4 ^
 -codec:v libx264 ^
 -crf 36 -preset ultrafast ^
 -codec:a libopus -b:a 112k ^
 -movflags use_metadata_tags+faststart -map_metadata 0 ^
 output.mp4








 Video file 

Size (bytes) 

Bit rate (bps) 

Encoder 

FFPROB - JSON 







 Original (named 'raw 1.mp4') 

31,666,777 

10,314,710 

!!! 

link 




 Without crf 

36,251,852 

11,805,216 

Lavf60.3.100 

link 




 With crf 

10,179,113 

3,314,772 

Lavf60.3.100 

link 




 Gdrive 

6,726,189 

2,190,342 

Google 

link 









Those files can be found here.


Update :


I continued my experiments with the video "raw_1.mp4" and found some interesting results that resemble those shown in this blog post, (I recommend consulting this answer).


In the following figure, I observed that using the
-preset
set to veryfast provided the most advantageous results, striking the optimal balance between compression ratio and compression time, (Note that a negative percentage in the compression variable indicates an increase in file size after processing) :


In this figure, I used the H.264 encoder and compared the compression ratio of different outputted files resulting from seven different values of the
-crf
parameter (CRF values used : 25, 27, 29, 31, 33, 35, 37),


For this figure, I've switched the encoder to H.265 while maintaining the same CRF values used in the previous figure :



Based on these results, the
-preset
veryfast and a-crf
value of 31 are my current preferred settings for FFmpeg, until they are proven to be suboptimal choices.
As a result, the FFmpeg command I'll use is as follows :

ffmpeg -hide_banner -loglevel verbose ^
 -i input.mp4 ^
 -codec:v libx264 ^
 -crf 31 -preset veryfast ^
 -codec:a libopus -b:a 112k ^
 -movflags use_metadata_tags+faststart -map_metadata 0 ^
 output.mp4



Note that these choices are based solely on the compression results obtained so far, and they do not take into account the visual quality of the outputted files.


-
How to save animations with tight layout, transparency and in high quality with matplotlib ?
29 novembre 2019, par mapfI am trying to implement an option in my GUI to save an image sequence displayed using matplotlib. The code looks something like this :
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import \
FigureCanvasQTAgg as FigureCanvas
from matplotlib.animation import FuncAnimation
from PIL import Image
plt.rcParams['savefig.bbox'] = 'tight'
class Printer:
def __init__(self, data):
self.fig, self.ax = plt.subplots()
self.canvas = FigureCanvas(self.fig)
# some irrelevant color adjustment here
#self.ax.spines['bottom'].set_color('#f9f2d7')
#self.ax.spines['top'].set_color('#f9f2d7')
#self.ax.spines['right'].set_color('#f9f2d7')
#self.ax.spines['left'].set_color('#f9f2d7')
#self.ax.tick_params(axis='both', colors='#f9f2d7')
#self.ax.yaxis.label.set_color('#f9f2d7')
#self.ax.xaxis.label.set_color('#f9f2d7')
#self.fig.subplots_adjust(left=0.1, right=0.975, bottom=0.09, top=0.98)
self.fig.patch.set_alpha(0)
self.fig.patch.set_visible(False)
self.canvas.setStyleSheet("background-color:transparent;")
self.fig.set_size_inches(10, 10, True)
self.fig.tight_layout()
self.data = data
self.image_artist = self.ax.imshow(data[0])
def animate(self, i):
self.image_artist.set_data(self.data[i])
self.canvas.draw()
def save_animation():
data = [
Image.open("test000.png"),
Image.open("test001.png"),
]
file = 'test.gif'
printer = Printer(data)
ani = FuncAnimation(
printer.fig, printer.animate, interval=100, frames=len(data),
)
# writer = animation.writers['pillow'](bitrate=1000)
ani.save(
file, writer='pillow', savefig_kwargs={'transparent': True, 'bbox_inches': 'tight'}
)
save_animation()Transparency :
As you can see I have already tried several different approaches as suggested elsewhere (1, 2), but didn’t manage to find a solution. All of the settings and arguments
patch.set_alpha(0)
,patch.set_visible(False)
,canvas.setStyleSheet("background-color:transparent;")
,savefig_kwargs={'transparent': True}
seem to have no effect at all on the transparency. I found this post but I didn’t get the code to work (for one I had to comment out this%matplotlib inline
, but then I ended up getting some error during the MovieWriter.cleanupout = TextIOWrapper(BytesIO(out)).read() TypeError: a bytes-like object is required, not 'str'
). Here, it was suggested that this is actually a bug, but the proposed workaroud doesn’t work for me since I would have to rely on third-party software. There also exists this bug report which was supposedly solved, so maybe it is unrelated.Tight layout
I actually couldn’t really find much on this, but all the things I tried (
plt.rcParams['savefig.bbox'] = 'tight'
,fig.tight_layout()
,savefig_kwargs={'bbox_inches': 'tight'}
) don’t have any effect or are even actively discarded in the case of thebbox_inches argument
. How does this work ?High quality
Since I cannot use
ImageMagick
and can’t getffmpeg
to work (more on this below), I rely on pillow to save my animation. But the only argument in terms of quality that I can pass on seems to be thebitrate
, which doesn’t have any effect. The files still have the same size and the animation still looks like mush. The only way that I found to increase the resolution was to usefig.set_size_inches(10, 10, True)
, but this still doesn’t improve the overall quality of the animation. It still looks bad. I saw that you can pass oncodec
andextra_args
so maybe that is something that might help, but I have no idea how to use these because I couldn’t find a list with allowed arguments.ffmpeg
I can’t get ffmpeg to work. I installed the python package from here and can import it into a python session but I don’t know how I can get matplotlib to use that. I also got ffmpeg from here (Windows 64-bit version) and set the
plt.rcParams['animation.ffmpeg_path']
to where I saved the files (there was no intaller to run, not sure if I did it correctly). But this didn’t help either. Also this is of course also third-party software, so if somebody else were to use my code/program it wouldn’t work. -
How to save animations with tight layout, transparency and in high quality
23 octobre 2023, par mapfI am trying to implement an option in my GUI to save an image sequence displayed using matplotlib. The code looks something like this :



import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import \
 FigureCanvasQTAgg as FigureCanvas
from matplotlib.animation import FuncAnimation
from PIL import Image


plt.rcParams['savefig.bbox'] = 'tight' 


class Printer:
 def __init__(self, data):
 self.fig, self.ax = plt.subplots()
 self.canvas = FigureCanvas(self.fig)

 # some irrelevant color adjustment here
 #self.ax.spines['bottom'].set_color('#f9f2d7')
 #self.ax.spines['top'].set_color('#f9f2d7')
 #self.ax.spines['right'].set_color('#f9f2d7')
 #self.ax.spines['left'].set_color('#f9f2d7')
 #self.ax.tick_params(axis='both', colors='#f9f2d7')
 #self.ax.yaxis.label.set_color('#f9f2d7')
 #self.ax.xaxis.label.set_color('#f9f2d7')
 #self.fig.subplots_adjust(left=0.1, right=0.975, bottom=0.09, top=0.98)
 self.fig.patch.set_alpha(0)
 self.fig.patch.set_visible(False)
 self.canvas.setStyleSheet("background-color:transparent;")
 self.fig.set_size_inches(10, 10, True)
 self.fig.tight_layout()

 self.data = data
 self.image_artist = self.ax.imshow(data[0])

 def animate(self, i):
 self.image_artist.set_data(self.data[i])
 self.canvas.draw()


def save_animation():
 data = [
 Image.open("test000.png"),
 Image.open("test001.png"),
 ]
 file = 'test.gif'
 printer = Printer(data)

 ani = FuncAnimation(
 printer.fig, printer.animate, interval=100, frames=len(data),
 )
 # writer = animation.writers['pillow'](bitrate=1000)
 ani.save(
 file, writer='pillow', savefig_kwargs={'transparent': True, 'bbox_inches': 'tight'}
 )


save_animation()




Transparency :



As you can see I have already tried several different approaches as suggested elsewhere (1, 2), but didn't manage to find a solution. All of the settings and arguments
patch.set_alpha(0)
,patch.set_visible(False)
,canvas.setStyleSheet("background-color:transparent;")
,savefig_kwargs={'transparent': True}
seem to have no effect at all on the transparency. I found this post but I didn't get the code to work (for one I had to comment out this%matplotlib inline
, but then I ended up getting some error during the MovieWriter.cleanupout = TextIOWrapper(BytesIO(out)).read() TypeError: a bytes-like object is required, not 'str'
). Here, it was suggested that this is actually a bug, but the proposed workaroud doesn't work for me since I would have to rely on third-party software. There also exists this bug report which was supposedly solved, so maybe it is unrelated.


Tight layout



I actually couldn't really find much on this, but all the things I tried (
plt.rcParams['savefig.bbox'] = 'tight'
,fig.tight_layout()
,savefig_kwargs={'bbox_inches': 'tight'}
) don't have any effect or are even actively discarded in the case of thebbox_inches argument
. How does this work ?


High quality



Since I cannot use
ImageMagick
and can't getffmpeg
to work (more on this below), I rely on pillow to save my animation. But the only argument in terms of quality that I can pass on seems to be thebitrate
, which doesn't have any effect. The files still have the same size and the animation still looks like mush. The only way that I found to increase the resolution was to usefig.set_size_inches(10, 10, True)
, but this still doesn't improve the overall quality of the animation. It still looks bad. I saw that you can pass oncodec
andextra_args
so maybe that is something that might help, but I have no idea how to use these because I couldn't find a list with allowed arguments.


ffmpeg



I can't get ffmpeg to work. I installed the python package from here and can import it into a python session but I don't know how I can get matplotlib to use that. I also got ffmpeg from here (Windows 64-bit version) and set the
plt.rcParams['animation.ffmpeg_path']
to where I saved the files (there was no intaller to run, not sure if I did it correctly). But this didn't help either. Also this is of course also third-party software, so if somebody else were to use my code/program it wouldn't work.