Recherche avancée

Médias (1)

Mot : - Tags -/musée

Autres articles (65)

  • Websites made ​​with MediaSPIP

    2 mai 2011, par

    This page lists some websites based on MediaSPIP.

  • L’agrémenter visuellement

    10 avril 2011

    MediaSPIP est basé sur un système de thèmes et de squelettes. Les squelettes définissent le placement des informations dans la page, définissant un usage spécifique de la plateforme, et les thèmes l’habillage graphique général.
    Chacun peut proposer un nouveau thème graphique ou un squelette et le mettre à disposition de la communauté.

  • Contribute to a better visual interface

    13 avril 2011

    MediaSPIP is based on a system of themes and templates. Templates define the placement of information on the page, and can be adapted to a wide range of uses. Themes define the overall graphic appearance of the site.
    Anyone can submit a new graphic theme or template and make it available to the MediaSPIP community.

Sur d’autres sites (6927)

  • Correct settings for streaming audio and video to YouTube

    27 novembre 2020, par Claus

    I'm using this script to stream an .mp4 video file with a sound track in .mp3 format :

    


    ffmpeg \
-re \
-i "$VIDEO_SOURCE" \
-thread_queue_size 512 \
-i "$AUDIO_SOURCE" \
-c:v libx264  -pix_fmt yuv420p -preset $QUAL -r $FPS -g $(($FPS *2)) -b:v $VBR \
-c:a $AUDIO_ENCODER -threads 6 -ar 44100 -b:a 128k -bufsize 512k -pix_fmt yuv420p \
-f flv $YOUTUBE_URL/$YOUTUBE_KEY


    


    the video gets displayed correctly on the channel but I cannot get any audio played.

    


    No error message on the console. What am I missing ?

    


  • Getting Error while trying to download youtube video by using python

    23 octobre 2024, par Aditya Kumar

    Code

    


    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.

    


    


  • Query on ffmpeg's concat demuxer parameters to end segments at outpoint timestamps and retain most properties same as input (fps, time_base etc)

    17 octobre 2024, par code

    In order to concatenate video files of matching fps, codec, resolution, time_base (in fact some are segments from same video), ffmpeg concat demuxer (to prevent re-encoding) approach has been used.
But ffmpeg did not stop concatenating segments at outpoint time specified in input demuxer text file !

    


    (Note : From Python code programmatically via sub-process approach, ffmpeg has been invoked )

    


    input.txt file for concat demuxer contained :

    


    ffconcat version 1.0
file 'numbered.mp4'
inpoint  2.083333
outpoint 2.166667



    


    (the time stamps provided above are of 50th (frame pts 49 in video, this is a keyframe) to 52nd (frame pts 51 in video, non-key frame), total 3 consecutive frames, inpoints given in this query are of a key-frame

    


    (video file referred in it i.e 'numbered.mp4' has each frame displaying its frame number ; it has h264 high coded 480p resolution, 10-seconds long with 240 frames and 24fps , <1MB in size shared at : https://filetransfer.io/data-package/F5caZ0xT#link )

    &#xA;

    ffmpeg command invoked programmatically with parameters :

    &#xA;

    &#xA;

    ffmpeg -f concat -safe 0 -fflags +genpts -i -c copy -video_track_timescale 24

    &#xA;

    &#xA;

    Output snippet contained :

    &#xA;

    &#xA;

    frame= 5 fps=0.0 q=-1.0 Lsize= 28KiB time=00:00:00.12 bitrate=1857.8kbits/s speed= 56x

    &#xA;

    &#xA;

    Problem 1 : It Shows there are 5 frames ! ffmpeg has concatenated 2 more frames beyond outpoint timestamp !

    &#xA;

    Query 1) : What are right parameter values to be given to ffmpeg concat demuxer method(or in concat demuxer input file) to make ffmpeg concatenate segments accurately till frames matching outpoint timestamp without overshooting or concatenating frames beyond outpoint timestamps ?

    &#xA;

    Problem2 : When another segment from same input file is referenced in concat demuxer input file, frame pts and timestamps were messed up in resultant output !

    &#xA;

    concat demuxer input file content(updated) :

    &#xA;

    ffconcat version 1.0&#xA;file &#x27;numbered.mp4&#x27;&#xA;inpoint  0&#xA;outpoint 0.125000&#xA;file &#x27;numbered.mp4&#x27;&#xA;inpoint  2.083333&#xA;outpoint 2.166667&#xA;&#xA;

    &#xA;

    command invoked was :

    &#xA;

    ffmpeg -f **concat **-safe 0 -fflags &#x2B;genpts   -i \ -c copy &#xA;  -video_track_timescale 24  \&#xA;

    &#xA;

    ffprobe output (on above output file, edited to reduce size) :

    &#xA;

    &#xA;key_frame=1, pts=0&#xA;    pts_time=0.000000&#xA;key_frame=0, pts=1&#xA;    pts_time=0.041667&#xA;key_frame=0, pts=2&#xA;    pts_time=0.083333&#xA;key_frame=0, pts=3&#xA;    pts_time=0.125000&#xA;key_frame=0, pts=4&#xA;    pts_time=0.166667&#xA;key_frame=1, pts=3&#xA;    pts_time=0.125000&#xA;key_frame=0, pts=6&#xA;    pts_time=0.250000&#xA;key_frame=0, pts=5&#xA;    pts_time=0.208333&#xA;key_frame=0, pts=7&#xA;    pts_time=0.291667&#xA;key_frame=0, pts=7&#xA;    pts_time=0.291667&#xA;

    &#xA;

    Confirms both pts and pts_time values are messed up (though segments referred in demuxer input file were several frames away with no overlapping ).

    &#xA;

    Query 2) What are accurate parameters to be given to concatenate segments represented by input demuxer file without causing this pts or pts_time issues ?

    &#xA;

    (In this test, all segments referred by demuxer have same parameters and are different segments of same video file itself ! so mismatch in codec parameters may not be the cause )

    &#xA;

    problem 3 : while input video had bitrate of 412654 (412.654kbps), concat demuxer resulted in output file with bitrate 1318777 (1.318 Mbps) over 3x the input bitrate.

    &#xA;

    Query 3) : What are accurate parameters to be given to retain all (almost) codec parameters same as input video and only perform concatenation without modifying time_base or framerate ?

    &#xA;

    Note : when -video_track_timescale 24 parameter is not provided as input parameter to concat demuxer, time_base in resultant output was different value (1/1000 ) instead of input files' time_base 1/24 !

    &#xA;

    ( when the Pts times are messed up, Non-monotonic DTS .. errors were observed in output : [vost#0:0/copy @ 000002c1b9b41140] Non-monotonic DTS ; previous : 2, current : 1 ; changing to 3. This may result in incorrect timestamps in the output file..)

    &#xA;

    To clarify, reason to use concat demuxer is to prevent re-encoding video, final usage would be to concatenate some segments of input video file with a few more video files all containing same codec parameters like fps,resolution,time_base etc.

    &#xA;

    Query 4) : Is it accurate at frame level to take pts_time values from ffprobe output and use these in ffmpeg concat demuxer input file for inpoint/outpoint values ?

    &#xA;

    (as ffprobe pts_time values possibly might be aligned with ffmpeg expectations, thought of taking pts_time values from ffprobe command output instead of venturing into computing frame start time)

    &#xA;

    the small (<1MB) input video file used in this test has been shared at : https://filetransfer.io/data-package/F5caZ0xT#link

    &#xA;

    input video file's ffprobe output has been pasted(trimmed to save space) :

    &#xA;

    "codec_name": "h264",&#xA;"codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",&#xA;"profile": "High",&#xA;"codec_type": "video",&#xA;"codec_tag_string": "avc1",&#xA;"codec_tag": "0x31637661",&#xA;"width": 640,&#xA;"height": 480,&#xA;"coded_width": 640,&#xA;"coded_height": 480,&#xA;"closed_captions": 0,&#xA;"film_grain": 0,&#xA;"has_b_frames": 2,&#xA;"sample_aspect_ratio": "1:1",&#xA;"display_aspect_ratio": "4:3",&#xA;"pix_fmt": "yuv420p",&#xA;"level": 41,&#xA;"color_range": "tv",&#xA;"color_space": "smpte170m",&#xA;"chroma_location": "left",&#xA;"field_order": "progressive",&#xA;"refs": 1,&#xA;"is_avc": "true",&#xA;"nal_length_size": "4",&#xA;"id": "0x1",&#xA;"r_frame_rate": "24/1",&#xA;"avg_frame_rate": "24/1",&#xA;"time_base": "1/24",&#xA;"start_pts": 0,&#xA;"start_time": "0.000000",&#xA;"duration_ts": 240,&#xA;"duration": "10.000000",&#xA;"bit_rate": "409628",&#xA;"bits_per_raw_sample": "8",&#xA;"nb_frames": "240",&#xA;"extradata_size": 49,&#xA;

    &#xA;

    Searched quite a lot online for a solution but searches didnot result in finding a fix for this concat demuxer situation&#xA;I seek helpful answers to the queries presented above, Thanks All

    &#xA;

    (while some workarounds like converting to raw h264 and then applying time scale again to each segment is suggested in other discussions, in current scenario, the input video file is just 1 so it appears accurate parameters to ffmpeg concat demuxer method are needed and be helpful to others facing similar issue)

    &#xA;