
Recherche avancée
Médias (1)
-
The Slip - Artworks
26 septembre 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Texte
Autres articles (31)
-
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 -
Keeping control of your media in your hands
13 avril 2011, parThe vocabulary used on this site and around MediaSPIP in general, aims to avoid reference to Web 2.0 and the companies that profit from media-sharing.
While using MediaSPIP, you are invited to avoid using words like "Brand", "Cloud" and "Market".
MediaSPIP is designed to facilitate the sharing of creative media online, while allowing authors to retain complete control of their work.
MediaSPIP aims to be accessible to as many people as possible and development is based on expanding the (...)
Sur d’autres sites (6531)
-
Python asyncio subprocess code returns "pipe closed by peer or os.write(pipe, data) raised exception."
4 novembre 2022, par Duke DougalI am trying to convert a synchronous Python process to asyncio. Any ideas what I am doing wrong ?


This is the synchronous code which successfully starts ffmpeg and converts a directory of webp files into a video.


import subprocess
import shlex
from os import listdir
from os.path import isfile, join

output_filename = 'output.mp4'
process = subprocess.Popen(shlex.split(f'ffmpeg -y -framerate 60 -i pipe: -vcodec libx265 -pix_fmt yuv420p -crf 24 output.mp4'), stdin=subprocess.PIPE)

thepath = '/home/ubuntu/webpfiles/'
thefiles = [f for f in listdir(thepath) if isfile(join(thepath, f))]
for filename in thefiles:
 absolute_path = f'{thepath}{filename}'
 with open(absolute_path, 'rb') as f:
 process.stdin.write(f.read())

process.stdin.close()
process.wait()
process.terminate()



This async code fails :


from os import listdir
from os.path import isfile, join
import shlex
import asyncio

outputfilename = 'output.mp4'

async def write_stdin(proc):
 thepath = '/home/ubuntu/webpfiles/'
 thefiles = [f for f in listdir(thepath) if isfile(join(thepath, f))]
 thefiles.sort()
 for filename in thefiles:
 absolute_path = f'{thepath}{filename}'
 with open(absolute_path, 'rb') as f:
 await proc.communicate(input=f.read())

async def create_ffmpeg_subprocess():
 bin = f'/home/ubuntu/bin/ffmpeg'
 params = f'-y -framerate 60 -i pipe: -vcodec libx265 -pix_fmt yuv420p -crf 24 {outputfilename}'
 proc = await asyncio.create_subprocess_exec(
 bin,
 *shlex.split(params),
 stdin=asyncio.subprocess.PIPE,
 stdout=asyncio.subprocess.PIPE,
 stderr=asyncio.subprocess.PIPE,
 )
 return proc

async def start():
 loop = asyncio.get_event_loop()
 proc = await create_ffmpeg_subprocess()
 task_stdout = loop.create_task(write_stdin(proc))
 await asyncio.gather(task_stdout)

if __name__ == '__main__':
 asyncio.run(start())



The output for the async code is :


pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.
pipe closed by peer or os.write(pipe, data) raised exception.



etc - one line for each webp file


-
How to pipe HLS segment to numpy array with FFmpeg
22 novembre 2022, par urico12I'm trying to extract a clip from an HLS stream and pipe the output to a numpy array. When I set the ffmpeg process to output to an mp4 file, the video looks exactly as I expect it to. However, when I output to a pipe so that I can add the data to a numpy array, the resulting video's display is off.


I'm running this ffmpeg command as a subprocess in python. I retrieve the output and send it to videowriter to create the mp4. I'm only doing the second part at the moment to test that the video data is correct.


clip_command = f"ffmpeg -y -live_start_index 0 -i master.m3u8 -ss {start} -t {duration} -pix_fmt rgb24 -f rawvideo pipe:1"
generate_clip = Popen(clip_command, shell=True, stdout=PIPE, stderr=STDOUT, bufsize=10**8)

nb_img = 300*300*3
out = cv2.VideoWriter('output.mp4', cv2.VideoWriter_fourcc(*'mp4v'), 15, (300, 300))
while True:
 buffer = generate_clip.stdout.read(nb_img)
 if len(buffer) != nb_img:
 # last frame
 break
 img = np.frombuffer(buffer, dtype='uint8').reshape(300, 300, 3)
 out.write(img)
out.release()



When I view the video that is generated frm cv2.VideoWriter, it looks something like
this.
The colors are changed from the source video and the frame repeats near the edges. I've tried setting different values for -pix_fmt but nothing seems to help. I'm not sure what I'm doing wrong or if what I'm trying to do is even feasible with Ffmpeg because I haven't been able to find much information on this particular use case.


-
Use C# to converting apng to webm with ffmpeg from pipe input and output
30 novembre 2022, par martin wangI was using ffmpeg to convert Line sticker from apng file to webm file.
And the result is weird, some of them was converted successed and some of them failed.
not sure what happend with these failed convert.


Here is my c# code to convert Line sticker to webm,
and I use CliWrap to run ffmpeg command line.


async Task Main()
{

 var downloadUrl = @"http://dl.stickershop.LINE.naver.jp/products/0/0/1/23303/iphone/stickerpack@2x.zip";
 var arg = @$"-i pipe:.png -vf scale=512:512:force_original_aspect_ratio=decrease:flags=lanczos -pix_fmt yuva420p -c:v libvpx-vp9 -cpu-used 5 -minrate 50k -b:v 350k -maxrate 450k -to 00:00:02.900 -an -y -f webm pipe:1";

 var errorCount = 0;
 try
 {
 using (var hc = new HttpClient())
 {
 var imgsZip = await hc.GetStreamAsync(downloadUrl);

 using (ZipArchive zipFile = new ZipArchive(imgsZip))
 {
 var files = zipFile.Entries.Where(entry => Regex.IsMatch(entry.FullName, @"animation@2x\/\d+\@2x.png"));
 foreach (var entry in files)
 {
 try
 {
 using (var fileStream = File.Create(Path.Combine("D:", "Projects", "ffmpeg", "Temp", $"{Path.GetFileNameWithoutExtension(entry.Name)}.webm")))
 using (var pngFileStream = File.Create(Path.Combine("D:", "Projects", "ffmpeg", "Temp", $"{entry.Name}")))
 using (var entryStream = entry.Open())
 using (MemoryStream ms = new MemoryStream())
 {
 entry.Open().CopyTo(pngFileStream);

 var result = await Cli.Wrap("ffmpeg")
 .WithArguments(arg)
 .WithStandardInputPipe(PipeSource.FromStream(entryStream))
 .WithStandardOutputPipe(PipeTarget.ToStream(ms))
 .WithStandardErrorPipe(PipeTarget.ToFile(Path.Combine("D:", "Projects", "ffmpeg", "Temp", $"{Path.GetFileNameWithoutExtension(entry.Name)}Info.txt")))
 .WithValidation(CommandResultValidation.ZeroExitCode)
 .ExecuteAsync();
 ms.Seek(0, SeekOrigin.Begin);
 ms.WriteTo(fileStream);
 }
 }
 catch (Exception ex)
 {
 entry.FullName.Dump();
 ex.Dump();
 errorCount++;
 }
 }
 }

 }
 }
 catch (Exception ex)
 {
 ex.Dump();
 }
 $"Error Count:{errorCount.Dump()}".Dump();

}



This is the failed convert file's error information from ffmpeg :




And the successed convert file from ffmpeg infromation :



It's strange when I was manually converted these failed convert file from command line, and it will be converted successed.



The question is the resource of images are all the same apng file,
so I just can't understan why some of files will convert failed from my c# code
but also when I manually use command line will be converted successed ?



I have written same exampe from C# to Python...
and here is python code :


from io import BytesIO
import os
import re
import subprocess
import zipfile

import requests


downloadUrl = "http://dl.stickershop.LINE.naver.jp/products/0/0/1/23303/iphone/stickerpack@2x.zip"
args = [
 'ffmpeg',
 '-i', 'pipe:',
 '-vf', 'scale=512:512:force_original_aspect_ratio=decrease:flags=lanczos',
 '-pix_fmt', 'yuva420p',
 '-c:v', 'libvpx-vp9',
 '-cpu-used', '5',
 '-minrate', '50k',
 '-b:v', '350k',
 '-maxrate', '450k', '-to', '00:00:02.900', '-an', '-y', '-f', 'webm', 'pipe:1'
]


imgsZip = requests.get(downloadUrl)
with zipfile.ZipFile(BytesIO(imgsZip.content)) as archive:
 files = [file for file in archive.infolist() if re.match(
 "animation@2x\/\d+\@2x.png", file.filename)]
 for entry in files:
 fileName = entry.filename.replace(
 "animation@2x/", "").replace(".png", "")
 rootPath = 'D:\\' + os.path.join("Projects", "ffmpeg", "Temp")
 # original file
 apngFile = os.path.join(rootPath, fileName+'.png')
 # output file
 webmFile = os.path.join(rootPath, fileName+'.webm')
 # output info
 infoFile = os.path.join(rootPath, fileName+'info.txt')

 with archive.open(entry) as file, open(apngFile, 'wb') as output_apng, open(webmFile, 'wb') as output_webm, open(infoFile, 'wb') as output_info:
 p = subprocess.Popen(args, stdin=subprocess.PIPE,
 stdout=subprocess.PIPE, stderr=output_info)
 outputBytes = p.communicate(input=file.read())[0]

 output_webm.write(outputBytes)
 file.seek(0)
 output_apng.write(file.read())




And you can try it,the result will be the as same as C#.