
Recherche avancée
Médias (1)
-
Collections - Formulaire de création rapide
19 février 2013, par
Mis à jour : Février 2013
Langue : français
Type : Image
Autres articles (6)
-
Les vidéos
21 avril 2011, parComme les documents de type "audio", Mediaspip affiche dans la mesure du possible les vidéos grâce à la balise html5 .
Un des inconvénients de cette balise est qu’elle n’est pas reconnue correctement par certains navigateurs (Internet Explorer pour ne pas le nommer) et que chaque navigateur ne gère en natif que certains formats de vidéos.
Son avantage principal quant à lui est de bénéficier de la prise en charge native de vidéos dans les navigateur et donc de se passer de l’utilisation de Flash et (...) -
Les tâches Cron régulières de la ferme
1er décembre 2010, parLa gestion de la ferme passe par l’exécution à intervalle régulier de plusieurs tâches répétitives dites Cron.
Le super Cron (gestion_mutu_super_cron)
Cette tâche, planifiée chaque minute, a pour simple effet d’appeler le Cron de l’ensemble des instances de la mutualisation régulièrement. Couplée avec un Cron système sur le site central de la mutualisation, cela permet de simplement générer des visites régulières sur les différents sites et éviter que les tâches des sites peu visités soient trop (...) -
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
Sur d’autres sites (3561)
-
Creating HLS stream from webm 10sec chunks
23 avril 2021, par pawelmI want to make some live streaming functionality. I've got a page, where JS catches camera and sends about 10sec chunks to PHP script. It uses mediaDevices.getUserMedia(). Then my PHP script catches these chunks and save them as .webm. Next step is converting .webm chunks to .ts files and finally creating .m3u8 playlist file. Then .m3u8 playlist file is linked to video-js player with hls extension on watching page.


.ts and .m3u8 files generating works well - when I start recording and finish it ex. after 30 - 40 secs, .m3u8 ends up with '#EXT-X-ENDLIST' and JS HLS player successfully plays the whole recorded video. Problems appear in two situations :


- 

- When stream recording is in progress, .ts files are being generated and .m3u8 file is being constantly updated with every next .ts - but when I try to play the stream via HLS player it plays the first chunk and then stops with loading icon. I can see in browser console that it downloads next .ts frames and updates the .m3u8 file, but player is freezing with loading icon.
- When the stream is long, for example has 20-30 .ts files (few minutes) and I try to play it via HLS player - it tries to start from n chunk to present live video, not past fragments. I can see in browser console, that it starts downloading from ex. 10. .ts file or later, not the first one. But in player the result is black screen - it doesn't start playing.






I think that problem is in converting webm to ts - there must be some options which I don't use properly or that I don't know about. Or maybe something is wrong with created .m3u8 file, this is my code (not optimized, firstly I want it start working) :


// get params - chunk number and stream identifier
$prefix = $_GET['n'];
$num = $_GET['c'];
$isFirst = false;
$isLast = isset($_GET['f']) && $_GET['f'];

if(str_replace('0', '', $num) == '') {
 mkdir('videos/'.$prefix);
 $isFirst = true;
}

$fp = 'videos\\'.$prefix.'\\'.$num.'.webm';
$msg = 'got '.$fp;

$data = file_get_contents('php://input');
file_put_contents($fp, $data);

// we determine exact chunk length
$detailsTxt = 'videos\\'.$prefix.'\\'.$num.'.txt';
exec("ffmpeg -i .\\$fp -f null - > .\\$detailsTxt 2>&1");

preg_match('/(\d{2}:\d{2}:(\d{2}.\d{2}))/', file_get_contents($detailsTxt), $matches);
$matches = array_filter($matches);
$duration = (float)trim($matches[2], '0');

$durationTxt = 'videos\\'.$prefix.'\\'.$num.'_dur.txt';
file_put_contents($durationTxt, $duration);

// ts convertion

// counting start timestamp
$FPS = 25;
$t0 = 0;
$cursorTxt = 'videos\\'.$prefix.'\\cursor.txt';
if(file_exists($cursorTxt)) $t0 = (float)file_get_contents($cursorTxt);
file_put_contents($cursorTxt, $t0 + $duration /*+ 1/$FPS*/);

$fp2 = str_replace('.webm', '.ts', $fp);
$details2Txt = 'videos\\'.$prefix.'\\'.$num.'_conv.txt';

$convertCommand = [
 'ffmpeg',
 '-v', 'quiet',
 '-loglevel', 'error',
 '-i', ".\\$fp",
 '-vcodec', 'libx264',
 '-acodec', 'aac',
 '-r', $FPS,
 '-profile:v', 'baseline',
 '-b:v', '800k',
 '-b:a', '48k',
 '-f', 'mpegts',
 '-strict', 'experimental',
 '-mpegts_copyts', '1',
 '-filter:v', 'setpts=PTS+' . $t0 . '/TB', // $t0
 '-y',
 ".\\$fp2",
 "> .\\$details2Txt 2>&1"
];

exec(implode(" ", $convertCommand));

// generating m3u8 file

// counting max duration
$maxDuration = $duration;
$durationTxt = 'videos\\'.$prefix.'\\duration.txt';
if(file_exists($durationTxt)) {
 $tempDuration = (float)file_get_contents($durationTxt);
 if($tempDuration > $maxDuration) $maxDuration = $tempDuration;
 else file_put_contents($durationTxt, $maxDuration);
}else file_put_contents($durationTxt, $maxDuration);

file_put_contents($cursorTxt, $t0 + $duration);

$m3u8File = 'videos\\'.$prefix.'\\playlist.m3u8';
$m3u8Content = [];

$counter = 0;
do {
 $paddedCounter = str_pad($counter, 5, '0', STR_PAD_LEFT);
 $chunkFile = 'videos\\'.$prefix.'\\'.$paddedCounter.'.ts';
 if(!file_exists($chunkFile)) break;
 $counter++;
}while(true);

$m3u8Content[] = "#EXTM3U";
$m3u8Content[] = "#EXT-X-VERSION:3";
$m3u8Content[] = "#EXT-X-MEDIA-SEQUENCE:$counter";
$m3u8Content[] = "#EXT-X-ALLOW-CACHE:YES";
$m3u8Content[] = "#EXT-X-TARGETDURATION:".ceil($maxDuration);
$m3u8Content[] = "";

$counter = 0;
do {
 $paddedCounter = str_pad($counter, 5, '0', STR_PAD_LEFT);
 $chunkFile = 'videos\\'.$prefix.'\\'.$paddedCounter.'.ts';
 if(!file_exists($chunkFile)) break;

 $durationTxt = 'videos\\'.$prefix.'\\'.$paddedCounter.'_dur.txt';
 $duration = (float)file_get_contents($durationTxt);

 $m3u8Content[] = "#EXTINF:$duration,";
 $m3u8Content[] = "$paddedCounter.ts";

 $counter++;
}while(true);

if($isLast) $m3u8Content[] = "#EXT-X-ENDLIST";
$m3u8Content[] = "";

file_put_contents($m3u8File, implode("\n", $m3u8Content));



EDIT : I've just discovered, that everything works well when I disable audio stream recording in getUserMedia - so when I record only video stream. That's weird - like some synchronization between audio and video streams problem.


-
Merge video with ffmpeg(or alternatives) with extra properties(an overlay)
28 juin 2021, par dconixDevI'll be scraping clips from twitch and merging them to create a single video file.
I already figured out the scraping of twitch clip links(but i only get 16-20 videos because i need to scroll with selenium but i dont really mind it, if you have a working solution then make an answer about it) and also the simple merging videos.


I'm scraping links with :


#!/usr/bin/python3.9
import bs4
import requests
import time
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.firefox.options import Options

# Initialize driver and run it headless
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)

def extract_source(url):
 agent = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0"}
 source=requests.get(url, headers=agent).text
 return source

def extract_data(source):
 soup=bs4.BeautifulSoup(source, 'html.parser')
 names=soup.find_all('a', attrs={'data-a-target':'preview-card-image-link'})
 return names

driver.get('https://www.twitch.tv/directory/game/League%20of%20Legends/clips?range=24hr')

# I wait 3 seconds for the clips to get pulled in
# I'd like here to scroll down a bit so i can scrape more clips, but even after i tried some solutions my firefox(was debugging in GUI mode, not headless as it is now) wasnt scrolling
time.sleep(3)
extract_links=extract_data(driver.page_source)
for a in extract_links:
 print(a.get('href'))

driver.quit()

# I tried scrolling using this but didnt work, not sure why
# this script is supposed to scroll until youre at the end of the page
# SCROLL_PAUSE_TIME = 0.5

# # Get scroll height
# last_height = driver.execute_script("return document.body.scrollHeight")

# for i in range(3):
 # # Scroll down to bottom
 # driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

 # # Wait to load page
 # time.sleep(SCROLL_PAUSE_TIME)

 # # Calculate new scroll height and compare with last scroll height
 # new_height = driver.execute_script("return document.body.scrollHeight")
 # if new_height == last_height:
 # break
 # last_height = new_height



I'm joining videos together after downloading(with youtube-dl) with ffmpeg :


ffmpeg -safe 0 -f concat -segment_time_metadata 1 -i videos.txt -vf select=concatdec_select -af aselect=concatdec_select,aresample=async=1 out.mp4


Where videos.txt is as follows :


file 'video_file1.mp4'
file 'video_file2.mp4'
...



I can't really find answers on how to add a watermark(different for each video, although i found this it doesnt explain how to add a unique watermark to individual videos but the same watermark to two videos) without having to render each and every video twice but doing so in one go.


I think I stumbled upon some people who made their
videos.txt
as follows in purpose of adding extra options to each video :

file 'video_file1.mp4'
option 1(for video_file1.mp4)
option 2(for video_file1.mp4)
file 'video_file2.mp4'
option 1(for video_file2.mp4)
option 2(for video_file2.mp4)
...



Would this work for unique watermarks for each videos(lets suppose watermarks are named video_file1.png, ... meaning the same as the videos, also the watermark is transparent in case that needs more configuration)


-
Video not clear when concatinate videos thogther using ffmpeg
5 février 2018, par no nameI have 3 types of the video first is start video played when the video start, the main video which is the main content of the video and last is the end video I want to add them together they have different resolutions so I use a text file to write the videos name like this.
file start.mp4
file main.mp4
file end.mp4then I use this command with FFmpeg
FFmpeg -f concat -i ffmpeg-sound.txt -c copy final_output.mp4
the problem is when I start watching the video the first video image is appearing in all the video duration I tried different player every one shows me a crashed photo but the sound is working fine.
also, the main video is created from mp3 file and image with subtitle it’s not original or downloaded from anywhere and I want to concatenate them.
what i tried when i make some searches and i thought it’s the problem that they have different resolution so i tried this command on both 3 videos to make them have the same resolution so no problem show after the concatenateFFmpeg -y -i end.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts end.mp4.ts
and try to add the 3 files again with ts formate and the same problem shown too so please any help to solve this
Update
i tried to use this command to change all the three videos to 1280x720FFmpeg -i a.mp4 -vf scale=1280:720 a1.mp4
after testing the problem exactly i found that the first video only works then when it go to next video to show it, the screen is a freeze on the last image from the first video. I don’t know why this problem even after i make them same scale !
here is the output offfmpeg -i start.mp4 -i a.mp4 -i end.mp4
output this before edit all the videos resulution to 1280x720
ffmpeg version N-89940-gb1af0e23a3 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libmfx --enable-amf --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth
libavutil 56. 7.100 / 56. 7.100
libavcodec 58. 9.100 / 58. 9.100
libavformat 58. 7.100 / 58. 7.100
libavdevice 58. 0.101 / 58. 0.101
libavfilter 7. 11.101 / 7. 11.101
libswscale 5. 0.101 / 5. 0.101
libswresample 3. 0.101 / 3. 0.101
libpostproc 55. 0.100 / 55. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'start.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
title : Tunepro
artist : Kiran Khan
album_artist : Kiran Khan
encoder : Lavf57.83.100
description : This video is about Tunepro
keywords : tunepro,new
Duration: 00:00:03.15, start: 0.000000, bitrate: 863 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 729 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 129 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'a.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.7.100
Duration: 00:05:21.24, start: 0.000000, bitrate: 188 kb/s
Stream #1:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuvj444p(pc), 300x300 [SAR 1:1 DAR 1:1], 53 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'end.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
title : Tunepro
artist : Kiran Khan
album_artist : Kiran Khan
encoder : Lavf57.83.100
description : This video is about Tunepro
keywords : tunepro,new
Duration: 00:00:30.03, start: 0.000000, bitrate: 8051 kb/s
Stream #2:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 7923 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #2:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
At least one output file must be specified