{"id":988,"date":"2025-06-03T10:47:19","date_gmt":"2025-06-03T15:47:19","guid":{"rendered":"https:\/\/www.michelot.info\/education\/?p=988"},"modified":"2025-06-05T15:09:52","modified_gmt":"2025-06-05T20:09:52","slug":"un-script-powershell-pour-compresser-rapidement-vos-videos","status":"publish","type":"post","link":"https:\/\/www.michelot.info\/education\/2025\/06\/03\/un-script-powershell-pour-compresser-rapidement-vos-videos\/","title":{"rendered":"Un script PowerShell pour compresser rapidement vos vid\u00e9os"},"content":{"rendered":"<p>Besoin de compresser vos vid\u00e9os rapidement et sans effort? Bien que des outils comme <a href=\"https:\/\/handbrake.fr\/\" target=\"_blank\" rel=\"noopener\">HandBrake<\/a> ou <a href=\"https:\/\/github.com\/ozok\/TEncoder\" target=\"_blank\" rel=\"noopener\">TEncoder<\/a> soient excellents, ils peuvent parfois \u00eatre longs (et fastidieux!) \u00e0 utiliser. Je vous propose une m\u00e9thode simple et efficace pour compresser vos vid\u00e9os en un clin d&rsquo;\u0153il, r\u00e9duisant consid\u00e9rablement leur poids tout en gardant une qualit\u00e9 acceptable.<\/p>\n<p>Dans ce billet, d\u00e9couvrez comment cr\u00e9er un script PowerShell pour compresser vos vid\u00e9os rapidement. Plus besoin de configurations fastidieuses : glissez-d\u00e9posez simplement vos fichiers vid\u00e9o sur une ic\u00f4ne, et le tour est jou\u00e9!<!--more--><\/p>\n<h1>\u00c9tape 1. Cr\u00e9er un fichier .ps1<\/h1>\n<p>Ouvrez un \u00e9diteur de texte (p. ex. Notepad++), copiez-collez le code ci-dessous, puis enregistrez-le dans un dossier sp\u00e9cifique (p. ex. votre dossier Vid\u00e9os) avec l&rsquo;extension de fichier .ps1 (p. ex. CompressionVideo.ps1).<\/p>\n<p>N&rsquo;oubliez pas de pr\u00e9ciser le chemin complet vers votre installation ffmpeg.exe (au besoin, <a href=\"https:\/\/ffmpeg.org\/\" target=\"_blank\" rel=\"noopener\">t\u00e9l\u00e9chargez-le ici<\/a>; le logiciel est sous licence GNU\/LGPL).&nbsp;<\/p>\n<pre>param (\r\n[Parameter(Mandatory=$true)]\r\n[string]$inputFile\r\n)\r\n\r\n# D\u00e9finition du fichier de sortie avec le suffixe \"_comp\"\r\n$outputFile = [System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($inputFile), [System.IO.Path]::GetFileNameWithoutExtension($inputFile) + \"_comp\" + [System.IO.Path]::GetExtension($inputFile))\r\n\r\n# Chemin vers l'ex\u00e9cutable FFmpeg\r\n$ffmpegPath = \"<span style=\"color: #3366ff;\">INDIQUEZ ICI LE CHEMIN VERS LE DOSSIER DE VOTRE FICHIER\\FFMpeg\\<\/span>ffmpeg.exe\"\r\n\r\n# Commande FFmpeg pour compresser la vid\u00e9o (tout en s'assurant que les largeurs et hauteurs de la vid\u00e9o soient divisibles par 2)\r\n$ffmpegCommand = @(\r\n\"-i\", \"`\"$inputFile`\"\",\r\n\"-vf\", \"`\"scale=iw:ih,scale=trunc(iw\/2)*2:trunc(ih\/2)*2,setsar=1:1`\"\",\r\n\"-r\", \"24\",\r\n\"-c:v\", \"libx264\",\r\n\"-crf\", \"23\",\r\n\"-preset\", \"medium\",\r\n\"-c:a\", \"libvo_aacenc\",\r\n\"-b:a\", \"128k\",\r\n\"-movflags\", \"+faststart\",\r\n\"`\"$outputFile`\"\"\r\n)\r\n\r\n# \u00c9xecution de la commande FFmpeg\r\n&amp; $ffmpegPath $ffmpegCommand\r\n\r\nWrite-Host \"Compression termin\u00e9e. Sortie sauvegard\u00e9e dans $outputFile\"\r\nWrite-Host \"Appuyez sur une touche pour quitter le PowerShell...\"\r\n$null = $Host.UI.RawUI.ReadKey(\"NoEcho,IncludeKeyDown\")<\/pre>\n<h1>\u00c9tape 2. Cr\u00e9ez un raccourci<\/h1>\n<p>Copiez votre fichier nouvellement cr\u00e9e (clic droit, \u00ab\u00a0Copier), puis cr\u00e9ez un raccourci sur votre bureau (clic droit, \u00ab\u00a0Coller le raccourci\u00a0\u00bb).<\/p>\n<p>Une fois cr\u00e9\u00e9, modifiez le raccourci (clic droit, \u00ab\u00a0Propri\u00e9t\u00e9s\u00a0\u00bb) en modifiant le champ Cible. Pour cela ajoutez ceci \u00ab\u00a0autour\u00a0\u00bb de la cible existante et, finalement, validez.<\/p>\n<pre>C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -ExecutionPolicy Bypass -File \"<span style=\"color: #3366ff;\">CIBLE<\/span>\"<\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-991\" src=\"https:\/\/i0.wp.com\/www.michelot.info\/education\/files\/2025\/06\/Capture-decran-2025-06-03-112124.png?resize=336%2C348&#038;ssl=1\" alt=\"Propri\u00e9t\u00e9s du raccourci \u00e0 modifier\" width=\"336\" height=\"348\" srcset=\"https:\/\/i0.wp.com\/www.michelot.info\/education\/files\/2025\/06\/Capture-decran-2025-06-03-112124.png?w=632&amp;ssl=1 632w, https:\/\/i0.wp.com\/www.michelot.info\/education\/files\/2025\/06\/Capture-decran-2025-06-03-112124.png?resize=289%2C300&amp;ssl=1 289w\" sizes=\"auto, (max-width: 336px) 100vw, 336px\" \/><\/p>\n<h1>\u00c9tape 3. C&rsquo;est parti!<\/h1>\n<p>Vous pouvez maintenant glissez-d\u00e9posez votre fichier de vid\u00e9o sur l&rsquo;ic\u00f4ne du raccourci plac\u00e9e sur votre bureau. Cela lancera automatiquement le script dans votre PowerShell et enregistrera la version compress\u00e9e de votre vid\u00e9o dans le m\u00eame dossier que l&rsquo;originale.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-992\" src=\"https:\/\/i0.wp.com\/www.michelot.info\/education\/files\/2025\/06\/Enregistrement-de-lecran-2025-06-03-113950.gif?resize=400%2C225&#038;ssl=1\" alt=\"Aper\u00e7u du gliss\u00e9-d\u00e9pos\u00e9\" width=\"400\" height=\"225\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Besoin de compresser vos vid\u00e9os rapidement et sans effort? Bien que des outils comme HandBrake ou TEncoder soient excellents, ils peuvent parfois \u00eatre longs (et fastidieux!) \u00e0 utiliser. Je vous propose une m\u00e9thode simple et efficace pour compresser vos vid\u00e9os en un clin d&rsquo;\u0153il, r\u00e9duisant consid\u00e9rablement leur poids tout en gardant une qualit\u00e9 acceptable. Dans&hellip;<\/p>\n","protected":false},"author":1,"featured_media":993,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"ngg_post_thumbnail":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[224],"tags":[225,117],"class_list":["post-988","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripts-et-codes","tag-compression","tag-video"],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.michelot.info\/education\/files\/2025\/06\/gd7fc069c47b573093e2030527e5bb712c2efa5bb2de8648ecde9a12cdc3819343041d282f4f7cf00b1adc7ffa33aa47f_640-1.png?fit=640%2C490&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.michelot.info\/education\/wp-json\/wp\/v2\/posts\/988","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.michelot.info\/education\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.michelot.info\/education\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.michelot.info\/education\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.michelot.info\/education\/wp-json\/wp\/v2\/comments?post=988"}],"version-history":[{"count":4,"href":"https:\/\/www.michelot.info\/education\/wp-json\/wp\/v2\/posts\/988\/revisions"}],"predecessor-version":[{"id":1006,"href":"https:\/\/www.michelot.info\/education\/wp-json\/wp\/v2\/posts\/988\/revisions\/1006"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.michelot.info\/education\/wp-json\/wp\/v2\/media\/993"}],"wp:attachment":[{"href":"https:\/\/www.michelot.info\/education\/wp-json\/wp\/v2\/media?parent=988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.michelot.info\/education\/wp-json\/wp\/v2\/categories?post=988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.michelot.info\/education\/wp-json\/wp\/v2\/tags?post=988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}