
Recherche avancée
Autres articles (58)
-
Websites made with MediaSPIP
2 mai 2011, parThis page lists some websites based on MediaSPIP.
-
MediaSPIP Core : La Configuration
9 novembre 2010, parMediaSPIP Core fournit par défaut trois pages différentes de configuration (ces pages utilisent le plugin de configuration CFG pour fonctionner) : une page spécifique à la configuration générale du squelettes ; une page spécifique à la configuration de la page d’accueil du site ; une page spécifique à la configuration des secteurs ;
Il fournit également une page supplémentaire qui n’apparait que lorsque certains plugins sont activés permettant de contrôler l’affichage et les fonctionnalités spécifiques (...) -
Creating farms of unique websites
13 avril 2011, parMediaSPIP platforms can be installed as a farm, with a single "core" hosted on a dedicated server and used by multiple websites.
This allows (among other things) : implementation costs to be shared between several different projects / individuals rapid deployment of multiple unique sites creation of groups of like-minded sites, making it possible to browse media in a more controlled and selective environment than the major "open" (...)
Sur d’autres sites (10298)
-
What causes an this error when using FFMPEG in Python ?
30 mai 2022, par VeseroI'm trying to convert MP3 to OGG but it doesn't work. What's the problem ?
The paths to the audio files are correct. "ffmpeg.exe" is in the script directory.


Code snippet from the program :


def ProcessAudio(audioPath, destPath):
 inp = ffmpeg.input(audioPath)
 au = inp.audio
 stream = ffmpeg.output(au, destPath)
 ffmpeg.run(stream)

def Convert(listofmusic, pathofmsc, pathofdest, append):
 count = 0
 if len(listofmusic) >= 100:
 for i in range(100):
 count += 1
 out = mscPath + "/" + pathofdest + "/" + "track" + str(count) + ".ogg"
 print(out)
 ProcessAudio(audioFolder + "/" + listofmusic[i], out)
 break
 count = 0
 elif len(listofmusic) < 100:
 for i in range(len(listofmusic)):
 count += 1
 mscP = mscPath.replace("/", "\\")
 out = mscP + "\\" + pathofdest + "\\" + "track" + str(count) + ".ogg"
 print(out)
 audioProc = audioFolder + "\\" + listofmusic[i]
 print(audioProc)
 ProcessAudio(audioProc, out)
 break
 count = 0



However, this code works fine :


import ffmpeg

inputfile = ffmpeg.input("example.mp3")
iAudio = inputfile.audio
stream = ffmpeg.output(iAudio, "example.ogg")
ffmpeg.run(stream)



Error :


Exception in Tkinter callback
Traceback (most recent call last):
 File "C:\Users\Santila\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
 return self.func(*args)
 File "C:\Users\Santila\Desktop\MSC_Audio_Converter.py", line 75, in pressed
 Convert(musicList, mscPath, oggFolder, cbVar.get())
 File "C:\Users\Santila\Desktop\MSC_Audio_Converter.py", line 52, in Convert
 ProcessAudio(audioProc, out)
 File "C:\Users\Santila\Desktop\MSC_Audio_Converter.py", line 32, in ProcessAudio
 ffmpeg.run(stream)
 File "C:\Users\Santila\AppData\Local\Programs\Python\Python310\lib\site-packages\ffmpeg\_run.py", line 325, in run
 raise Error('ffmpeg', out, err)
ffmpeg._run.Error: ffmpeg error (see stderr output for detail)



-
Python cv2 script that scans a giant image to a video. Raises error : Unknown C++ exception from OpenCV code
26 avril 2022, par NolreneaI wrote a script that scans a giant image to make a video. Normally I just post my scripts straight to my Code Review account, but this script is ugly, needs to be refactored, implements only horizontal scrolling and contains a bug that I can't get rid of.


It is working but not perfect, I can't get the last line at the bottom of the image, with height of
image_height % 1080
. If I ignore it, the code is working fine, if I try to fix it, it throws exceptions.

Example :


Original image (Google Drive)


Video Output (Google Drive)


As you can see from the video, everything is working properly except the fact that I can't get the bottom line.


Full working code



import cv2
import numpy as np
import random
import rpack
from fractions import Fraction
from math import prod

def resize_guide(image_size, target_area):
 aspect_ratio = Fraction(*image_size).limit_denominator()
 horizontal = aspect_ratio.numerator
 vertical = aspect_ratio.denominator
 unit_length = (target_area/(horizontal*vertical))**.5
 return (int(horizontal*unit_length), int(vertical*unit_length))

fourcc = cv2.VideoWriter_fourcc(*'h264')
FRAME = np.zeros((1080, 1920, 3), dtype=np.uint8)

def new_frame():
 return np.ndarray.copy(FRAME)

def center(image):
 frame = new_frame()
 h, w = image.shape[:2]
 yoff = round((1080-h)/2)
 xoff = round((1920-w)/2)
 frame[yoff:yoff+h, xoff:xoff+w] = image
 return frame

def image_scanning(file, fps=60, pan_increment=64, horizontal_increment=8, fast_decrement=256):
 image = cv2.imread(file)
 height, width = image.shape[:2]
 assert width*height >= 1920*1080
 video_writer = cv2.VideoWriter(file+'.mp4', fourcc, fps, (1920, 1080))
 fit_height = True
 if height < 1080:
 width = width*1080/height
 image = cv2.resize(image, (width, 1080), interpolation = cv2.INTER_AREA)
 aspect_ratio = width / height
 zooming_needed = False
 if 4/9 <= aspect_ratio <= 16/9:
 new_width = round(width*1080/height)
 fit = cv2.resize(image, (new_width, 1080), interpolation = cv2.INTER_AREA)
 zooming_needed = True
 
 elif 16/9 < aspect_ratio <= 32/9:
 new_height = round(height*1920/width)
 fit = cv2.resize(image, (1920, new_height), interpolation = cv2.INTER_AREA)
 fit_height = False
 zooming_needed = True
 
 centered = center(fit)
 for i in range(fps):
 video_writer.write(centered)
 if fit_height:
 xoff = round((1920 - new_width)/2)
 while xoff:
 if xoff - pan_increment >= 0:
 xoff -= pan_increment
 else:
 xoff = 0
 frame = new_frame()
 frame[0:1080, xoff:xoff+new_width] = fit
 video_writer.write(frame)
 else:
 yoff = round((1080 - new_height)/2)
 while yoff:
 if yoff - pan_increment >= 0:
 yoff -= pan_increment
 else:
 yoff = 0
 frame = new_frame()
 frame[yoff:yoff+new_height, 0:1920] = fit
 video_writer.write(frame)
 
 if zooming_needed:
 if fit_height:
 width_1, height_1 = new_width, 1080
 else:
 width_1, height_1 = 1920, new_height
 new_area = width_1 * height_1
 original_area = width * height
 area_diff = original_area - new_area
 unit_diff = area_diff / fps
 for i in range(1, fps+1):
 zoomed = cv2.resize(image, resize_guide((width_1, height_1), new_area+unit_diff*i), interpolation=cv2.INTER_AREA)
 zheight, zwidth = zoomed.shape[:2]
 zheight = min(zheight, 1080)
 zwidth = min(zwidth, 1920)
 frame = new_frame()
 frame[0:zheight, 0:zwidth] = zoomed[0:zheight, 0:zwidth]
 video_writer.write(frame)
 y, x = 0, 0
 completed = False
 while y != height - 1080:
 x = 0
 while x != width - 1920:
 if x + horizontal_increment + 1920 <= width:
 x += horizontal_increment
 frame = image[y:y+1080, x:x+1920]
 video_writer.write(frame)
 else:
 x = width - 1920
 frame = image[y:y+1080, x:x+1920]
 for i in range(round(fps/3)):
 video_writer.write(frame)
 if y == height - 1080:
 completed = True
 while x != 0:
 if x - fast_decrement - 1920 >= 0:
 x -= fast_decrement
 else:
 x = 0
 frame = image[y:y+1080, x:x+1920]
 video_writer.write(frame)
 if y + 2160 <= height:
 y += 1080
 else:
 y = height - 1080
 cv2.destroyAllWindows()
 video_writer.release()
 del video_writer



The above the the code needed to produce the example video. It is working but the bottom line is missing.


Now if I change the last few lines to this :


if y + 2160 <= height:
 y += 1080
 else:
 y = height - 1080
 x = 0
 while x != width - 1920:
 if x + horizontal_increment + 1920 <= width:
 x += horizontal_increment
 frame = image[y:y+1080, x:x+1920]
 video_writer.write(frame)
 cv2.destroyAllWindows()
 video_writer.release()
 del video_writer



I expect it to include the bottom line, but it just throws exceptions instead :


OpenCV: FFMPEG: tag 0x34363268/'h264' is not supported with codec id 27 and format 'mp4 / MP4 (MPEG-4 Part 14)'
OpenCV: FFMPEG: fallback to use tag 0x31637661/'avc1'
---------------------------------------------------------------------------
error Traceback (most recent call last)
 in <module>
----> 1 image_scanning("D:/collages/91f53ebcea2a.png")

 in image_scanning(file, fps, pan_increment, horizontal_increment, fast_decrement)
 122 x += horizontal_increment
 123 frame = image[y:y+1080, x:x+1920]
--> 124 video_writer.write(frame)
 125 cv2.destroyAllWindows()
 126 video_writer.release()

error: Unknown C++ exception from OpenCV code
</module>


(If you can't get the example code working I can't help you, but I am using Python 3.9.10 x64 on Windows 10, and I have this file : "C :\Windows\System32\openh264-1.8.0-win64.dll", the '.avi' format generates video files with Gibibytes (binary unit, not SI Gigabyte) of size)


How to get rid of the exception ?


-
Having problem in video stegano, the hiden message always lost
5 avril 2022, par user7025125friend, i am currently looking for a way to video stegano. I successfully in splitting frames from video file and hide messages inside them. But when i combine these frames into video and trying to extract info from the hiden video, i always failed. I guess here is problem with video compression.


Here is my code.


from stegano import lsb
from os.path import isfile, join

import time # install time ,opencv,numpy modules
import cv2
import numpy as np
import math
import os
import shutil
from moviepy.editor import *
from subprocess import call, STDOUT


def split_string(s_str, count=10):
 per_c = math.ceil(len(s_str)/count)
 c_cout = 0
 out_str = ''
 split_list = []
 for s in s_str:
 out_str += s
 c_cout += 1
 if c_cout == per_c:
 split_list.append(out_str)
 out_str = ''
 c_cout = 0
 if c_cout != 0:
 split_list.append(out_str)
 return split_list


def frame_extraction(video):
 if not os.path.exists("./tmp"):
 os.makedirs("tmp") 
 temp_folder = "./tmp"
 print("[INFO] tmp directory is created")

 vidcap = cv2.VideoCapture(video)
 count = 0

 while True:
 success, image = vidcap.read()
 if not success:
 break
 cv2.imwrite(os.path.join(temp_folder, "{:d}.png".format(count)), image)
 count += 1
 print("[INFO] frame {} is extracted".format(count))


def encode_string(input_string, root="./tmp/"):
 split_string_list = split_string(input_string)
 for i in range(0, len(split_string_list)):
 f_name = "{}{}.png".format(root, i)
 secret_enc = lsb.hide(f_name, split_string_list[i])
 secret_enc.save(f_name)
 print("[INFO] frame {} holds {}".format(f_name, lsb.reveal(f_name)))


def decode_string(video):
 frame_extraction(video)
 secret = []
 root = "./tmp/"
 for i in range(len(os.listdir(root))):
 f_name = "{}{}.png".format(root, i)
 print("[INFO] frame {} is decoding".format(f_name))
 secret_dec = lsb.reveal(f_name)
 if secret_dec == None:
 break
 secret.append(secret_dec)
 print("[INFO] secret is {}".format("".join(secret)))
 print(''.join([i for i in secret]))
 # clean_tmp()


def clean_tmp(path="./tmp"):
 if os.path.exists(path):
 shutil.rmtree(path)
 print("[INFO] tmp files are cleaned up")


def main():
 input_string = input("Enter the input string: ")
 f_name = input("enter the name of video: ")

 # 从源文件分离出帧
 frame_extraction(f_name)
 
 # 分离文件路径和扩展名
 file_path, file_extraction = os.path.splitext(f_name)
 
 # 创建输出音频文件
 audio_path = file_path + "_temp.mp3"
 video = VideoFileClip(f_name)
 video.audio.write_audiofile(audio_path)

 # 加密字符
 encode_string(input_string)

 # 从tmp文件夹的图片创建没有声音的视频
 fps=30
 img_root = r"./tmp/"
 # fourcc = cv2.VideoWriter_fourcc(*'mp4v')
 fourcc = cv2.VideoWriter_fourcc(*'XVID')
 video_file_path = file_path + "_temp.avi"
 # 获取tmp文件夹第一张视频的尺寸
 img = cv2.imread(img_root + "0.png")
 height, width, layers = img.shape
 size=(width,height)
 videoWriter = cv2.VideoWriter(video_file_path,fourcc=fourcc,fps=fps,frameSize=size)
 for i in range(len(os.listdir(img_root))):
 frame = cv2.imread(img_root+str(i)+'.png')
 videoWriter.write(frame)
 videoWriter.release()

 # 合并视频和音频 audio_path video_file_path
 video = VideoFileClip(video_file_path)
 audio_clip = AudioFileClip(audio_path)
 video = video.set_audio(audio_clip)
 video.write_videofile(file_path + "_hide.avi")
 clean_tmp()


if __name__ == "__main__":
 while True:
 print("1.Hide a message in video 2.Reveal the secret from video")
 print("any other value to exit")
 choice = input()
 if choice == '1':
 main()
 elif choice == '2':
 decode_string(input("enter the name of video with extension: "))
 else:
 break




I have tried mp4, avi, wov format. But none of them worked.


IF YOU HAVE ANY IDEA OR SUGGESTION GIVEN TO ME, I WOULD BE VERY GRATEFUL