
Recherche avancée
Médias (1)
-
Rennes Emotion Map 2010-11
19 octobre 2011, par
Mis à jour : Juillet 2013
Langue : français
Type : Texte
Autres articles (77)
-
Les autorisations surchargées par les plugins
27 avril 2010, parMediaspip core
autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs -
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 -
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 (7741)
-
How to Turn image A + audio + A into Video A with the exact same attributes of Video B so both can be concatenated without encoding [closed]
13 décembre 2024, par Furkan GözükaraI have
image A
and it is PNG

I have
audio A
and it is MP3

I have
video B
that can be any format, resolution, encoding, audio, etc

Now I want to turn
image A
+audio A
intovideo A
with the exact attributes ofvideo B
so that I can concatenate them without encoding

Here my so far code which is failing. I am using Python and latest version of FFMPEG with most codecs and features


def get_video_info(video_path):
 cmd = [
 FFPROBE_PATH,
 '-v', 'quiet',
 '-print_format', 'json',
 '-show_format',
 '-show_streams',
 video_path
 ]
 result = subprocess.run(cmd, capture_output=True, text=True)
 info = json.loads(result.stdout)
 
 video_stream = next((s for s in info['streams'] if s['codec_type'] == 'video'), None)
 audio_stream = next((s for s in info['streams'] if s['codec_type'] == 'audio'), None)
 
 if not video_stream or not audio_stream:
 logging.error("Failed to find video or audio stream")
 return None

 return {
 'width': int(video_stream.get('width', 0)),
 'height': int(video_stream.get('height', 0)),
 'fps': eval(video_stream.get('r_frame_rate', '30/1')),
 'video_codec': video_stream.get('codec_name', ''),
 'audio_codec': audio_stream.get('codec_name', ''),
 'audio_sample_rate': int(audio_stream.get('sample_rate', 0)),
 'audio_channels': audio_stream.get('channels', 0),
 'pixel_format': video_stream.get('pix_fmt', ''),
 'color_space': video_stream.get('color_space', ''),
 'color_transfer': video_stream.get('color_transfer', ''),
 'color_primaries': video_stream.get('color_primaries', ''),
 }

def create_thumbnail_video(thumbnail_url, video_id, video_info, duration=40):
 output_dir = os.path.abspath('downloads')
 output_path = os.path.join(output_dir, f"{video_id}_thumbnail.mp4")
 audio_path = os.path.abspath("a.mp3")

 try:
 # 1. Download and process the image
 logging.info("Downloading thumbnail image...")
 response = requests.get(thumbnail_url, timeout=30)
 response.raise_for_status()

 # Save the original image
 original_image_path = os.path.join(output_dir, f'{video_id}_original_image.png')
 with open(original_image_path, 'wb') as f:
 f.write(response.content)

 # 2. Open and resize the image
 image = Image.open(original_image_path)
 width, height = video_info['width'], video_info['height']
 image = image.resize((width, height), Image.LANCZOS)

 # Save resized image
 resized_image_path = os.path.join(output_dir, f'{video_id}_resized_image.png')
 image.save(resized_image_path, 'PNG')

 # 3. Get properties of the main video using ffprobe
 main_video_path = os.path.join(output_dir, f"{video_id}.mp4") # Assuming main video has .mp4 extension
 main_video_info = get_video_info(main_video_path)

 if not main_video_info:
 raise Exception("Could not get information about the main video.")

 # 4. Generate video with matching encoding
 logging.info("Generating thumbnail video with matching codec and properties...")

 ffmpeg_command = [
 FFMPEG_PATH,
 '-y',
 '-loop', '1',
 '-i', resized_image_path,
 '-i', audio_path,
 '-c:v', main_video_info['video_codec'],
 '-c:a', main_video_info['audio_codec'],
 '-ar', str(main_video_info['audio_sample_rate']),
 '-pix_fmt', main_video_info['pixel_format'],
 '-color_range', main_video_info.get('color_range', '1'), # Default to tv/mpeg (limited) if not found
 '-colorspace', main_video_info['color_space'],
 '-color_trc', main_video_info['color_transfer'],
 '-color_primaries', main_video_info['color_primaries'],
 '-vf', f"fps={main_video_info['fps']},scale={width}:{height}",
 '-shortest',
 '-t', str(duration),
 output_path
 ]

 subprocess.run(ffmpeg_command, check=True, capture_output=True, text=True)
 logging.info(f"Thumbnail video created: {output_path}")

 # 5. Clean up intermediate files
 for file_path in [original_image_path, resized_image_path]:
 if os.path.exists(file_path):
 os.remove(file_path)
 logging.info(f"Removed intermediate file: {file_path}")

 return output_path

 except requests.RequestException as e:
 logging.error(f"Error downloading thumbnail: {e}")
 except subprocess.CalledProcessError as e:
 logging.error(f"FFmpeg error: {e.stderr}")
 except Exception as e:
 logging.error(f"Error in create_thumbnail_video: {e}")
 logging.error(traceback.format_exc())

 # If we've reached this point, an error occurred
 logging.warning("Thumbnail video creation failed. Returning None.")
 return None



Here example case


Generated video from image + audio as below


General
Complete name : C:\stream\downloads\hqDA0-waGwI_thumbnail.mp4
Format : MPEG-4
Format profile : Base Media
Codec ID : isom (isom/iso2/avc1/mp41)
File size : 1.50 MiB
Duration : 40 s 0 ms
Overall bit rate mode : Variable
Overall bit rate : 315 kb/s
Frame rate : 30.000 FPS
Writing application : Lavf61.9.100

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4
Format settings : CABAC / 4 Ref Frames
Format settings, CABAC : Yes
Format settings, Reference fra : 4 frames
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 40 s 0 ms
Bit rate : 179 kb/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 30.000 FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.003
Stream size : 875 KiB (57%)
Writing library : x264 core 164
Encoding settings : cabac=1 / ref=3 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=34 / lookahead_threads=5 / 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=2 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=crf / mbtree=1 / crf=23.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Color range : Limited
Matrix coefficients : BT.709
Codec configuration box : avcC

Audio
ID : 2
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : mp4a-40-2
Duration : 40 s 0 ms
Source duration : 40 s 23 ms
Source_Duration_LastFrame : -8 ms
Bit rate mode : Variable
Bit rate : 128 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 44.1 kHz
Frame rate : 43.066 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 621 KiB (40%)
Source stream size : 621 KiB (40%)
Default : Yes
Alternate group : 1



Source video used to get video attributes


General
Complete name : C:\stream\downloads\hqDA0-waGwI.mp4
Format : MPEG-4
Format profile : Base Media
Codec ID : isom (isom/iso2/avc1/mp41)
File size : 24.9 MiB
Duration : 1 min 36 s
Overall bit rate : 2 171 kb/s
Frame rate : 30.000 FPS
Writing application : Lavf61.9.100

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4
Format settings : CABAC / 3 Ref Frames
Format settings, CABAC : Yes
Format settings, Reference fra : 3 frames
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 1 min 36 s
Bit rate : 2 036 kb/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 30.000 FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.033
Stream size : 23.3 MiB (94%)
Title : ISO Media file produced by Google Inc.
Color range : Limited
Color primaries : BT.709
Transfer characteristics : BT.709
Matrix coefficients : BT.709
Codec configuration box : avcC

Audio
ID : 2
Format : AAC LC
Format/Info : Advanced Audio Codec Low Complexity
Codec ID : mp4a-40-2
Duration : 1 min 36 s
Bit rate mode : Constant
Bit rate : 128 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 44.1 kHz
Frame rate : 43.066 FPS (1024 SPF)
Compression mode : Lossy
Stream size : 1.47 MiB (6%)
Title : ISO Media file produced by Google Inc.
Language : English
Default : Yes
Alternate group : 1



-
Data Privacy Issues to Be Aware of and How to Overcome Them
9 mai 2024, par Erin -
How (and Why) to Run a Web Accessibility Audit in 2024
7 mai 2024, par Erin