
Recherche avancée
Autres articles (21)
-
Supporting all media types
13 avril 2011, parUnlike most software and media-sharing platforms, MediaSPIP aims to manage as many different media types as possible. The following are just a few examples from an ever-expanding list of supported formats : images : png, gif, jpg, bmp and more audio : MP3, Ogg, Wav and more video : AVI, MP4, OGV, mpg, mov, wmv and more text, code and other data : OpenOffice, Microsoft Office (Word, PowerPoint, Excel), web (html, CSS), LaTeX, Google Earth and (...)
-
Ajouter notes et légendes aux images
7 février 2011, parPour pouvoir ajouter notes et légendes aux images, la première étape est d’installer le plugin "Légendes".
Une fois le plugin activé, vous pouvez le configurer dans l’espace de configuration afin de modifier les droits de création / modification et de suppression des notes. Par défaut seuls les administrateurs du site peuvent ajouter des notes aux images.
Modification lors de l’ajout d’un média
Lors de l’ajout d’un média de type "image" un nouveau bouton apparait au dessus de la prévisualisation (...) -
List of compatible distributions
26 avril 2011, parThe table below is the list of Linux distributions compatible with the automated installation script of MediaSPIP. Distribution nameVersion nameVersion number Debian Squeeze 6.x.x Debian Weezy 7.x.x Debian Jessie 8.x.x Ubuntu The Precise Pangolin 12.04 LTS Ubuntu The Trusty Tahr 14.04
If you want to help us improve this list, you can provide us access to a machine whose distribution is not mentioned above or send the necessary fixes to add (...)
Sur d’autres sites (5860)
-
Getting Error while trying to download youtube video by using python
23 octobre 2024, par Aditya KumarCode


I'm working on a script that allows users to manually select and download separate video and audio streams from YouTube using yt-dlp. The script lists the available video and audio formats, lets the user choose their desired formats, and then merges them using FFmpeg.


Here’s the complete code :


import yt_dlp
import os
import subprocess

# Function to list and allow manual selection of video and audio formats
def download_and_merge_video_audio_with_selection(url, download_path):
 try:
 # Ensure the download path exists
 if not os.path.exists(download_path):
 os.makedirs(download_path)

 # Get available formats from yt-dlp
 ydl_opts = {'listformats': True}

 with yt_dlp.YoutubeDL(ydl_opts) as ydl:
 info_dict = ydl.extract_info(url, download=False)
 formats = info_dict.get('formats', [])

 # List available video formats (video only)
 print("\nAvailable video formats:")
 video_formats = [f for f in formats if f.get('vcodec') != 'none' and f.get('acodec') == 'none']
 for idx, f in enumerate(video_formats):
 resolution = f.get('height', 'unknown')
 filesize = f.get('filesize', 'unknown')
 print(f"{idx}: Format code: {f['format_id']}, Resolution: {resolution}p, Size: {filesize} bytes")

 # Let user select the desired video format
 video_idx = int(input("\nEnter the number corresponding to the video format you want to download: "))
 video_format_code = video_formats[video_idx]['format_id']

 # List available audio formats (audio only)
 print("\nAvailable audio formats:")
 audio_formats = [f for f in formats if f.get('acodec') != 'none' and f.get('vcodec') == 'none']
 for idx, f in enumerate(audio_formats):
 abr = f.get('abr', 'unknown') # Audio bitrate
 filesize = f.get('filesize', 'unknown')
 print(f"{idx}: Format code: {f['format_id']}, Audio Bitrate: {abr} kbps, Size: {filesize} bytes")

 # Let user select the desired audio format
 audio_idx = int(input("\nEnter the number corresponding to the audio format you want to download: "))
 audio_format_code = audio_formats[audio_idx]['format_id']

 # Video download options (based on user choice)
 video_opts = {
 'format': video_format_code, # Download user-selected video format
 'outtmpl': os.path.join(download_path, 'video.%(ext)s'), # Save video as video.mp4
 }

 # Audio download options (based on user choice)
 audio_opts = {
 'format': audio_format_code, # Download user-selected audio format
 'outtmpl': os.path.join(download_path, 'audio.%(ext)s'), # Save audio as audio.m4a
 }

 # Download the selected video format
 print("\nDownloading selected video format...")
 with yt_dlp.YoutubeDL(video_opts) as ydl_video:
 ydl_video.download([url])

 # Download the selected audio format
 print("\nDownloading selected audio format...")
 with yt_dlp.YoutubeDL(audio_opts) as ydl_audio:
 ydl_audio.download([url])

 # Paths to the downloaded video and audio files
 video_file = os.path.join(download_path, 'video.webm') # Assuming best video will be .mp4
 audio_file = os.path.join(download_path, 'audio.m4a') # Assuming best audio will be .m4a
 output_file = os.path.join(download_path, 'final_output.mp4') # Final merged file

 # FFmpeg command to merge audio and video
 ffmpeg_cmd = [
 'ffmpeg', '-i', video_file, '-i', audio_file, '-c', 'copy', output_file
 ]

 # Run FFmpeg to merge audio and video
 print("\nMerging video and audio...")
 subprocess.run(ffmpeg_cmd, check=True)

 print(f"\nDownload and merging complete! Output file: {output_file}")

 except Exception as e:
 print(f"An error occurred: {e}")

# Example usage
video_url = "https://www.youtube.com/watch?v=SOwk8FhfEZY" # Replace with your desired video URL
download_path = 'C:/Users/vinod/Downloads/VideoDownload' # Replace with your desired download path
download_and_merge_video_audio_with_selection(video_url, download_path)




Explanation :


The script first lists all available video formats (video-only) and audio formats (audio-only) from a given YouTube URL.


It allows the user to manually select their preferred video and audio formats.


After downloading the selected formats, it merges the video and audio streams into a single file using FFmpeg.


Error


while trying to run above mentioned code , I am getting this error :


Merging video and audio...
An error occurred: [WinError 2] The system cannot find the file specified



Requirements :




yt-dlp :
pip install yt-dlp






FFmpeg : Make sure you have FFmpeg installed and added to your system's PATH.




-
Video created in FFMPEG on YouTube doesn't work
10 mars 2023, par MarkThere is a problem when working with FFMPEG and then uploading to YouTube.


I have a video that is 4:15 long (255 seconds). When I create such a video in Adobe Premiere and upload it to YouTube, everything is fine. The problem occurs when I create such a video in FFMPEG. Before the HD versions are processed (>= 1080p) the video works fine, but when the HD versions appear, its duration on the scrollbar becomes 4:00 (240 seconds). If you go to the end of the video at 4:00, it continues to play for another 15 seconds.


Here is an example of such a video clip : https://youtu.be/G_tMctEklM4


Screenshot : https://i.stack.imgur.com/HxWs5.png


I would be grateful for your help.


UPD


I think I figured out what the problem was.


I took 5 video files of 25 seconds each and merged them. The resulting file is 125 seconds long, I uploaded it to YouTube - everything is fine. Then I tried to build my project - again, problems. Apparently, the problem is that I merged 42 files : 2 files for 20 seconds and 40 files for 5-6 seconds. These are not integers, here are some of the files :


06.143000, 05.983000, 06.488000, 06.018000, 05.809000


So, I understand FFMPEG rounds them down to integer number, and due to the fact that there are a lot of such files - 42, so there is a shift of 15-20 seconds (about 0.5 seconds from each file). But what to do with it I still do not understand.


Related topic : https://www.reddit.com/r/ffmpeg/comments/e1o3hv/ffconcat_filter_with_millisecond_precision_how/f8qvztl/


and this (???) : ffmpeg - avoid duration approximation of generated files


-
Download youtube video as stream Readable object
26 décembre 2023, par Abraam Emadin this function it download youtube video as a file out.mp4 on hard disk i need to download it as a Readable Object to upload it


private async downloadVideo(videoId: string) {
// Buildin with nodejs
const cp = require('child_process');
const readline = require('readline');
// External modules
const ytdl = require('ytdl-core');
const ffmpeg = require('ffmpeg-static');
// Global constants
const ref = `https://www.youtube.com/watch?v=${videoId}`;
const tracker = {
 start: Date.now(),
 audio: { downloaded: 0, total: Infinity },
 video: { downloaded: 0, total: Infinity },
 merged: { frame: 0, speed: '0x', fps: 0 },
};

// Get audio and video streams
const audio = ytdl(ref, { quality: 'highestaudio' })
 .on('progress', (_, downloaded, total) => {
 tracker.audio = { downloaded, total };
 });
const video = ytdl(ref, { quality: 'highestvideo' })
 .on('progress', (_, downloaded, total) => {
 tracker.video = { downloaded, total };
 });

// Prepare the progress bar
let progressbarHandle = null;
const progressbarInterval = 1000;
const showProgress = () => {
 readline.cursorTo(process.stdout, 0);
 const toMB = i => (i / 1024 / 1024).toFixed(2);

 process.stdout.write(`Audio | ${(tracker.audio.downloaded / tracker.audio.total * 100).toFixed(2)}% processed `);
 process.stdout.write(`(${toMB(tracker.audio.downloaded)}MB of ${toMB(tracker.audio.total)}MB).${' '.repeat(10)}\n`);

 process.stdout.write(`Video | ${(tracker.video.downloaded / tracker.video.total * 100).toFixed(2)}% processed `);
 process.stdout.write(`(${toMB(tracker.video.downloaded)}MB of ${toMB(tracker.video.total)}MB).${' '.repeat(10)}\n`);

 process.stdout.write(`Merged | processing frame ${tracker.merged.frame} `);
 process.stdout.write(`(at ${tracker.merged.fps} fps => ${tracker.merged.speed}).${' '.repeat(10)}\n`);

 process.stdout.write(`running for: ${((Date.now() - tracker.start) / 1000 / 60).toFixed(2)} Minutes.`);
 readline.moveCursor(process.stdout, 0, -3);
};

// Start the ffmpeg child process
const ffmpegProcess = cp.spawn(ffmpeg, [
 // Remove ffmpeg's console spamming
 '-loglevel', '8', '-hide_banner',
 // Redirect/Enable progress messages
 '-progress', 'pipe:3',
 // Set inputs
 '-i', 'pipe:4',
 '-i', 'pipe:5',
 // Map audio & video from streams
 '-map', '0:a',
 '-map', '1:v',
 // Keep encoding
 '-c:v', 'copy',
 // Define output file
 '-f', 'mpegts', // Use MPEG-TS format for streaming
 'out.mp4'
], {
 windowsHide: true,
 stdio: [
 /* Standard: stdin, stdout, stderr */
 'inherit', 'inherit', 'inherit',
 /* Custom: pipe:3, pipe:4, pipe:5 */
 'pipe', 'pipe', 'pipe',
 ],
});
ffmpegProcess.on('close', () => {
 console.log('done');
 // Cleanup
 process.stdout.write('\n\n\n\n');
 clearInterval(progressbarHandle);
});
// Link streams
// FFmpeg creates the transformer streams and we just have to insert / read data
ffmpegProcess.stdio[3].on('data', chunk => {
 // Start the progress bar
 if (!progressbarHandle) progressbarHandle = setInterval(showProgress, progressbarInterval);
 // Parse the param=value list returned by ffmpeg
 const lines = chunk.toString().trim().split('\n');
 const args: any = {};
 for (const l of lines) {
 const [key, value] = l.split('=');
 args[key.trim()] = value.trim();
 }
 tracker.merged = args;
});
audio.pipe(ffmpegProcess.stdio[4]);
video.pipe(ffmpegProcess.stdio[5]);



}`