
Recherche avancée
Médias (3)
-
Exemple de boutons d’action pour une collection collaborative
27 février 2013, par
Mis à jour : Mars 2013
Langue : français
Type : Image
-
Exemple de boutons d’action pour une collection personnelle
27 février 2013, par
Mis à jour : Février 2013
Langue : English
Type : Image
-
Collections - Formulaire de création rapide
19 février 2013, par
Mis à jour : Février 2013
Langue : français
Type : Image
Autres articles (32)
-
Multilang : améliorer l’interface pour les blocs multilingues
18 février 2011, parMultilang est un plugin supplémentaire qui n’est pas activé par défaut lors de l’initialisation de MediaSPIP.
Après son activation, une préconfiguration est mise en place automatiquement par MediaSPIP init permettant à la nouvelle fonctionnalité d’être automatiquement opérationnelle. Il n’est donc pas obligatoire de passer par une étape de configuration pour cela. -
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 (...) -
Liste des distributions compatibles
26 avril 2011, parLe tableau ci-dessous correspond à la liste des distributions Linux compatible avec le script d’installation automatique de MediaSPIP. Nom de la distributionNom de la versionNuméro de version 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
Si vous souhaitez nous aider à améliorer cette liste, vous pouvez nous fournir un accès à une machine dont la distribution n’est pas citée ci-dessus ou nous envoyer le (...)
Sur d’autres sites (7660)
-
Php-ffmpeg “Unknown encoder libfaac” on Windows
6 mars 2016, par DevI am using laravel 4.2.
I am working on a project in that user can upload a video and I need to transcode it that it can be played over all kind of devices.
For transcoding I have added php-ffmpeg package from git hub in my project. According to the instructions I have downloaded ffmpeg package from http://ffmpeg.zeranoe.com/builds and set the ffmpeg.exe’s path into the environment variable Path.
Now, I tried code below to transcode an uploaded video :
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open($video_path);
$format = new FFMpeg\Format\Video\X264();
$format->setKiloBitrate(1000)
->setAudioChannels(2)
->setAudioKiloBitrate(256);
$video->save($format, public_path().$path.$save_filename);But it gives error as below :
[ERROR] ffmpeg version N-70767-gd24af70 Copyright (c) 2000-2015 the FFmpeg developers
[ERROR] built with gcc 4.9.2 (GCC)
[ERROR] configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-decklink --enable-zlib
[ERROR] libavutil 54. 20.100 / 54. 20.100
[ERROR] libavcodec 56. 28.100 / 56. 28.100
[ERROR] libavformat 56. 25.101 / 56. 25.101
[ERROR] libavdevice 56. 4.100 / 56. 4.100
[ERROR] libavfilter 5. 12.100 / 5. 12.100
[ERROR] libswscale 3. 1.101 / 3. 1.101
[ERROR] libswresample 1. 1.100 / 1. 1.100
[ERROR] libpostproc 53. 3.100 / 53. 3.100
[ERROR]
[ERROR] Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'http://localhost/ohvideo-ftp/public/temp/5ZPlIuU1AIgz8RR4p0bs.mp4':
[ERROR] Metadata:
[ERROR] major_brand : mp42
[ERROR] minor_version : 0
[ERROR] compatible_brands: mp42mp41isomavc1
[ERROR] creation_time : 2013-11-09 00:29:52
[ERROR] Duration: 00:00:30.12, start: 0.000000, bitrate: 417 kb/s
[ERROR] Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 381 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
[ERROR] Metadata:
[ERROR] creation_time : 2013-11-09 00:29:52
[ERROR] handler_name : L-SMASH Video Handler
[ERROR] encoder : AVC Coding
[ERROR] Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 32 kb/s (default)
[ERROR] Metadata:
[ERROR] creation_time : 2013-11-09 00:29:52
[ERROR] handler_name : L-SMASH Audio Handler
[ERROR] Unknown encoder 'libfaac'
[ERROR]
{"error":{"type":"FFMpeg\\Exception\\RuntimeException","message":"Encoding failed","file":"F:\\wamp\\www\\ohvideo-ftp\\vendor\\php-ffmpeg\\php-ffmpeg\\src\\FFMpeg\\Media\\Video.php","line":168}}After searching alot, I found a link for the solution here, with note that
Zeranoe’s ffmpeg does not contain libfaac support due to that encoder
requiring —enable-nonfree which would result in a non-redistributable
build.I don’t get the solution. Can anybody help me to overcome this ?
Edit : (working code as below)
I have created a
CustomVideo
class the same like classFFMpeg\Format\Video\X264()
as below :class CustomVideo extends FFMpeg\Format\Video\DefaultVideo
{
/** @var boolean */
private $bframesSupport = true;
public function __construct($audioCodec = 'libmp3lame', $videoCodec = 'libx264')
{
$this
->setAudioCodec($audioCodec)
->setVideoCodec($videoCodec);
}
/**
* {@inheritDoc}
*/
public function supportBFrames()
{
return $this->bframesSupport;
}
/**
* @param $support
*
* @return X264
*/
public function setBFramesSupport($support)
{
$this->bframesSupport = $support;
return $this;
}
/**
* {@inheritDoc}
*/
public function getAvailableAudioCodecs()
{
return array('libmp3lame');
}
/**
* {@inheritDoc}
*/
public function getAvailableVideoCodecs()
{
return array('libx264');
}
/**
* {@inheritDoc}
*/
public function getPasses()
{
return 2;
}
/**
* @return int
*/
public function getModulus()
{
return 2;
}
}and updated the code to transcode video as below :
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open($video_path);
$format = new CustomVideo();
$format->setKiloBitrate(1000)
->setAudioChannels(2)
->setAudioKiloBitrate(256);
$video->save($format, public_path().$path.$save_filename);It has solved the
Unknown encoder libfaac
error. -
Video frame difference with FFMPEG
18 octobre 2018, par StepTNTI need to compute the frame differences between a source video and a compressed one.
For now I’m using OpenCV with Java, by extracting each frame and doing a simple difference, but it’s quite slow (working a 0.5 fps, meaning that a 500 frames video will take more than 15 mins) so I was thinking to move to FFMPEG.FFMPEG feels a lot faster (everything’s done under 1 minute) but it has one big issue that makes the results useless : when compressing the source file, done with FFMPEG too, an extra gray frame is added at the beginning and this fakes the results because different frames are compared.
This is what I’m doing now (knowing that the extra frame messes it all) :
ffmpeg -y -i src.avi -i compressed.avi -filter_complex "blend=all_mode=difference,hue=s=0" -c:v libx264 -crf 18 -c:a copy difference.avi
To fix the frame issue I was trying to remove the first frame by re-encoding the compressed video with this command
ffmpeg -y -ss 0.02 -i compressed.mpg -an -f mpeg2video compressed-cut.mpg"
(Note that
-ss
is 0.02 because it’s a 50 fps video, so I did1/FPS
as suggested here)But I get this response
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
So, finally, the question is : since extracting all the frames and then compute differences with OpenCV is really slow, how can I use FFMPEG to produce a video containing the difference between two sources while keeping in mind that one of them has an extra frame at the beginning ?
EDIT : I wanted to avoid posting endless console outputs but since you asked for it, here we go.
1) Encoding
Input
ffmpeg -i "720p50_mobcal_ter.avi" -an -f mpeg2video -y "720p50_mobcal_ter.mpg"
Output
ffmpeg version N-76684-g1fe82ab Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 5.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
libavutil 55. 6.100 / 55. 6.100
libavcodec 57. 15.100 / 57. 15.100
libavformat 57. 14.100 / 57. 14.100
libavdevice 57. 0.100 / 57. 0.100
libavfilter 6. 15.100 / 6. 15.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Input #0, avi, from '720p50_mobcal_ter.avi':
Metadata:
encoder : Lavf57.14.100
Duration: 00:00:10.08, start: 0.000000, bitrate: 552974 kb/s
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1280x720, 554059 kb/s, SAR 1:1 DAR 16:9, 50 fps, 50 tbr, 50 tbn, 50 tbc
Output #0, mpeg2video, to '720p50_mobcal_ter.mpg':
Metadata:
encoder : Lavf57.14.100
Stream #0:0: Video: mpeg2video, yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 50 fps, 50 tbn, 50 tbc
Metadata:
encoder : Lavc57.15.100 mpeg2video
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg2video (native))
Press [q] to stop, [?] for help
frame= 41 fps=0.0 q=31.0 size= 984kB time=00:00:00.78 bitrate=10330.5kbits/frame= 80 fps= 78 q=31.0 size= 1323kB time=00:00:01.56 bitrate=6948.1kbits/frame= 124 fps= 80 q=31.0 size= 1725kB time=00:00:02.44 bitrate=5790.0kbits/frame= 168 fps= 81 q=31.0 size= 2084kB time=00:00:03.32 bitrate=5142.8kbits/frame= 212 fps= 81 q=31.0 size= 2482kB time=00:00:04.20 bitrate=4841.4kbits/frame= 255 fps= 82 q=31.0 size= 2840kB time=00:00:05.06 bitrate=4597.2kbits/frame= 296 fps= 82 q=31.0 size= 3133kB time=00:00:05.88 bitrate=4364.5kbits/frame= 338 fps= 82 q=24.8 size= 3453kB time=00:00:06.72 bitrate=4209.2kbits/frame= 382 fps= 82 q=31.0 size= 3723kB time=00:00:07.60 bitrate=4013.4kbits/frame= 426 fps= 83 q=31.0 size= 4005kB time=00:00:08.48 bitrate=3869.1kbits/frame= 470 fps= 83 q=24.8 size= 4276kB time=00:00:09.36 bitrate=3742.5kbits/frame= 504 fps= 83 q=31.0 Lsize= 4469kB time=00:00:10.06 bitrate=3639.3kbits/s
video:4469kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%This adds the extra grey frame at the beginning, it just duplicates the first one
2) Removing first frame
Input
ffmpeg -y -i "720p50_mobcal_ter.mpg" -an -f mpeg2video -vf select=gte(n\,1) "CUT-720p50_mobcal_ter.mpg"
Output
ffmpeg version N-76684-g1fe82ab Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 5.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
libavutil 55. 6.100 / 55. 6.100
libavcodec 57. 15.100 / 57. 15.100
libavformat 57. 14.100 / 57. 14.100
libavdevice 57. 0.100 / 57. 0.100
libavfilter 6. 15.100 / 6. 15.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Input #0, mpegvideo, from '720p50_mobcal_ter.mpg':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: mpeg2video (Main), yuv420p(tv), 1280x720 [SAR 1:1 DAR 16:9], max. 104857 kb/s, 50 fps, 50 tbr, 1200k tbn, 100 tbc
Output #0, mpeg2video, to 'CUT-720p50_mobcal_ter.mpg':
Metadata:
encoder : Lavf57.14.100
Stream #0:0: Video: mpeg2video, yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 50 fps, 50 tbn, 50 tbc
Metadata:
encoder : Lavc57.15.100 mpeg2video
Stream mapping:
Stream #0:0 -> #0:0 (mpeg2video (native) -> mpeg2video (native))
Press [q] to stop, [?] for help
frame= 255 fps=0.0 q=31.0 size= 2781kB time=00:00:05.10 bitrate=4467.3kbits/frame= 503 fps=0.0 q=31.0 Lsize= 4415kB time=00:00:10.08 bitrate=3588.5kbits/s
video:4415kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%3) Frame difference
Input
ffmpeg -y -i "720p50_mobcal_ter.avi" -i "CUT-720p50_mobcal_ter.mpg" -filter_complex "blend=all_mode=difference,hue=s=0" -c:v libx264 -crf 18 -c:a copy "DIFF-720p50_mobcal_ter.mpg"
Output
ffmpeg version N-76684-g1fe82ab Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 5.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
libavutil 55. 6.100 / 55. 6.100
libavcodec 57. 15.100 / 57. 15.100
libavformat 57. 14.100 / 57. 14.100
libavdevice 57. 0.100 / 57. 0.100
libavfilter 6. 15.100 / 6. 15.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Input #0, avi, from '720p50_mobcal_ter.avi':
Metadata:
encoder : Lavf57.14.100
Duration: 00:00:10.08, start: 0.000000, bitrate: 552974 kb/s
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1280x720, 554059 kb/s, SAR 1:1 DAR 16:9, 50 fps, 50 tbr, 50 tbn, 50 tbc
Input #1, mpegvideo, from 'CUT-720p50_mobcal_ter.mpg':
Duration: N/A, bitrate: N/A
Stream #1:0: Video: mpeg2video (Main), yuv420p(tv), 1280x720 [SAR 1:1 DAR 16:9], max. 104857 kb/s, 50 fps, 50 tbr, 1200k tbn, 100 tbc
[libx264 @ 000002784dbeb980] using SAR=1/1
[libx264 @ 000002784dbeb980] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 000002784dbeb980] profile High, level 3.2
[mpeg @ 000002784dbeaf20] VBV buffer size not set, using default size of 130KB
If you want the mpeg file to be compliant to some specification
Like DVD, VCD or others, make sure you set the correct buffer size
Output #0, mpeg, to 'D:\DOWNLOADS\TMP\Video TDI\AVI\DIFF-720p50_mobcal_ter.mpg':
Metadata:
encoder : Lavf57.14.100
Stream #0:0: Video: h264 (libx264), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 50 fps, 90k tbn, 50 tbc (default)
Metadata:
encoder : Lavc57.15.100 libx264
Stream mapping:
Stream #0:0 (rawvideo) -> blend:top
Stream #1:0 (mpeg2video) -> blend:bottom
hue -> Stream #0:0 (libx264)
Press [q] to stop, [?] for help
frame= 504 fps= 39 q=-1.0 Lsize= 32182kB time=00:00:10.04 bitrate=26258.5kbits/s
video:32061kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.377054%
[libx264 @ 000002784dbeb980] frame I:30 Avg QP:19.69 size:149974
[libx264 @ 000002784dbeb980] frame P:299 Avg QP:23.28 size: 69423
[libx264 @ 000002784dbeb980] frame B:175 Avg QP:24.48 size: 43280
[libx264 @ 000002784dbeb980] consecutive B-frames: 30.6% 69.4% 0.0% 0.0%
[libx264 @ 000002784dbeb980] mb I I16..4: 18.3% 51.4% 30.4%
[libx264 @ 000002784dbeb980] mb P I16..4: 0.6% 5.6% 2.4% P16..4: 35.9% 22.9% 15.6% 0.0% 0.0% skip:17.0%
[libx264 @ 000002784dbeb980] mb B I16..4: 0.2% 0.5% 0.3% B16..8: 49.5% 12.4% 5.6% direct:15.5% skip:16.1% L0:47.8% L1:42.1% BI:10.1%
[libx264 @ 000002784dbeb980] 8x8 transform intra:57.5% inter:38.5%
[libx264 @ 000002784dbeb980] coded y,uvDC,uvAC intra: 90.7% 0.0% 0.0% inter: 50.3% 0.0% 0.0%
[libx264 @ 000002784dbeb980] i16 v,h,dc,p: 32% 23% 35% 10%
[libx264 @ 000002784dbeb980] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 11% 11% 41% 7% 5% 6% 5% 6% 8%
[libx264 @ 000002784dbeb980] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 14% 23% 8% 7% 7% 7% 7% 8%
[libx264 @ 000002784dbeb980] i8c dc,h,v,p: 100% 0% 0% 0%
[libx264 @ 000002784dbeb980] Weighted P-Frames: Y:33.8% UV:0.0%
[libx264 @ 000002784dbeb980] ref P L0: 58.1% 16.3% 14.2% 9.4% 2.0%
[libx264 @ 000002784dbeb980] ref B L0: 79.3% 20.7%
[libx264 @ 000002784dbeb980] kb/s:26056.02The second command made everything work while the second one in the first part didn’t (the one with the
-ss
option), so I could be quite happy about it but I’m not that sure if FFMPEG duplicates the first frame for every video or if it’s just related to the one I’m using now, so it could be better to start off with a compressed video that has the same frame count of the original one.So let’s get to one final question : why does FFMPEG add a duplicated first frame at the beginning of the compressed video and how can I avoid that ?
-
Not all portions of video play well after concatenation
24 septembre 2018, par srgbndNode.JS 8.11.4, fluent-ffmpeg 2.1.2
I need to concatenate random portions of the same length of different videos in one video file. The concatenation proceeds without errors. But when I play the final concatenated file I see some portions playing well with sound, others have video "frozen" but sounds playing.
What’s the problem ? I want all portions playing well in the final concatenated file.
Concatenation config :
trex@cave:/media/trex/safe1/Development/app$ head concat_config.txt
file /media/trex/safe1/Development/app/videos/test/417912400.mp4
inpoint 145
outpoint 155
file /media/trex/safe1/Development/app/videos/test/440386842.mp4
inpoint 59
outpoint 69
file /media/trex/safe1/Development/app/videos/test/417912400.mp4
inpoint 144
outpoint 154
...In total, I have 16 portions of 2 videos. Duration of a portion is 10 sec. In the future the number of video files and portions will be much bigger.
trex@cave:/media/trex/safe1/Development/app$ ls -lh videos/test/
total 344M
-rw-r--r-- 1 trex trex 90M set 23 12:19 417912400.mp4
-rw-r--r-- 1 trex trex 254M set 23 12:19 440386842.mp4JavaScript code for the concatentaion :
const fs = require('fs');
const path = require('path');
const _ = require('lodash');
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
const ffprobePath = require('@ffprobe-installer/ffprobe').path;
const ffmpeg = require('fluent-ffmpeg');
ffmpeg.setFfmpegPath(ffmpegPath);
ffmpeg.setFfprobePath(ffprobePath);
function getMetadata(absPathToFile) {
return new Promise(function (resolve, reject) {
ffmpeg.ffprobe(absPathToFile, function(err, metadata) {
if (err) {
reject('get video meta: ' + err.toString());
}
resolve(metadata);
});
});
}
async function getFormat(files) {
const pArray = files.map(async f => {
const meta = await getMetadata(f);
meta.format.short_filename = meta.format.filename.split('/').pop();
return meta.format;
});
return await Promise.all(pArray);
}
function getSliceValues(duration, max = 10) {
max = duration < max ? duration * 0.5 : max; // sec
const start = _.random(0, duration * 0.9);
const end = start + max > duration ? duration : start + max;
return `inpoint ${Math.floor(start)}\noutpoint ${Math.floor(end)}\n`;
}
function addPath(arr, aPath) {
return arr.map(e => path.join(aPath, e));
}
function createConfig(meta) {
return meta.map(video => `file ${video.filename}\n${getSliceValues(video.duration)}`).join('');
}
function duplicateMeta(meta) {
for (let i = 0; i < 3; i++) {
meta.push(...meta);
}
return _.shuffle(meta);
}
const videoFolder = path.join(__dirname, 'videos/test');
const finalVideo = 'final_video.mp4';
const configFile = 'concat_config.txt';
// main
(async () => {
let videos = addPath(fs.readdirSync(videoFolder), videoFolder);
let meta = await getFormat(videos);
meta = duplicateMeta(meta); // get multiple portions of videos
fs.writeFileSync(configFile, createConfig(meta));
const mpeg = ffmpeg();
mpeg.input(configFile)
.inputOptions(['-f concat', '-safe 0'])
.outputOptions('-c copy')
.save(finalVideo);
})();Video files formats :
{ streams:
[ { index: 0,
codec_name: 'h264',
codec_long_name: 'H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10',
profile: 'High',
codec_type: 'video',
codec_time_base: '1001/60000',
codec_tag_string: 'avc1',
codec_tag: '0x31637661',
width: 1920,
height: 1080,
coded_width: 1920,
coded_height: 1088,
has_b_frames: 2,
sample_aspect_ratio: '1:1',
display_aspect_ratio: '16:9',
pix_fmt: 'yuv420p',
level: 40,
color_range: 'tv',
color_space: 'bt709',
color_transfer: 'bt709',
color_primaries: 'bt709',
chroma_location: 'left',
field_order: 'unknown',
timecode: 'N/A',
refs: 1,
is_avc: 'true',
nal_length_size: 4,
id: 'N/A',
r_frame_rate: '30000/1001',
avg_frame_rate: '30000/1001',
time_base: '1/30000',
start_pts: 0,
start_time: 0,
duration_ts: 4936900,
duration: 164.563333,
bit_rate: 4323409,
max_bit_rate: 'N/A',
bits_per_raw_sample: 8,
nb_frames: 4932,
nb_read_frames: 'N/A',
nb_read_packets: 'N/A',
tags: [Object],
disposition: [Object] },
{ index: 1,
codec_name: 'aac',
codec_long_name: 'AAC (Advanced Audio Coding)',
profile: 'LC',
codec_type: 'audio',
codec_time_base: '1/48000',
codec_tag_string: 'mp4a',
codec_tag: '0x6134706d',
sample_fmt: 'fltp',
sample_rate: 48000,
channels: 2,
channel_layout: 'stereo',
bits_per_sample: 0,
id: 'N/A',
r_frame_rate: '0/0',
avg_frame_rate: '0/0',
time_base: '1/48000',
start_pts: 0,
start_time: 0,
duration_ts: 7899120,
duration: 164.565,
bit_rate: 256000,
max_bit_rate: 263232,
bits_per_raw_sample: 'N/A',
nb_frames: 7714,
nb_read_frames: 'N/A',
nb_read_packets: 'N/A',
tags: [Object],
disposition: [Object] } ],
format:
{ filename: '/media/trex/safe1/Development/app/videos/test/417912400.mp4',
nb_streams: 2,
nb_programs: 0,
format_name: 'mov,mp4,m4a,3gp,3g2,mj2',
format_long_name: 'QuickTime / MOV',
start_time: 0,
duration: 164.565,
size: 94298844,
bit_rate: 4584150,
probe_score: 100,
tags:
{ major_brand: 'mp42',
minor_version: '0',
compatible_brands: 'mp42mp41isomavc1',
creation_time: '2015-09-21T19:11:21.000000Z' } },
chapters: [] }
{ streams:
[ { index: 0,
codec_name: 'h264',
codec_long_name: 'H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10',
profile: 'High',
codec_type: 'video',
codec_time_base: '1001/48000',
codec_tag_string: 'avc1',
codec_tag: '0x31637661',
width: 2560,
height: 1440,
coded_width: 2560,
coded_height: 1440,
has_b_frames: 2,
sample_aspect_ratio: '1:1',
display_aspect_ratio: '16:9',
pix_fmt: 'yuv420p',
level: 51,
color_range: 'tv',
color_space: 'bt709',
color_transfer: 'bt709',
color_primaries: 'bt709',
chroma_location: 'left',
field_order: 'unknown',
timecode: 'N/A',
refs: 1,
is_avc: 'true',
nal_length_size: 4,
id: 'N/A',
r_frame_rate: '24000/1001',
avg_frame_rate: '24000/1001',
time_base: '1/24000',
start_pts: 0,
start_time: 0,
duration_ts: 4206200,
duration: 175.258333,
bit_rate: 11891834,
max_bit_rate: 'N/A',
bits_per_raw_sample: 8,
nb_frames: 4202,
nb_read_frames: 'N/A',
nb_read_packets: 'N/A',
tags: [Object],
disposition: [Object] },
{ index: 1,
codec_name: 'aac',
codec_long_name: 'AAC (Advanced Audio Coding)',
profile: 'LC',
codec_type: 'audio',
codec_time_base: '1/48000',
codec_tag_string: 'mp4a',
codec_tag: '0x6134706d',
sample_fmt: 'fltp',
sample_rate: 48000,
channels: 2,
channel_layout: 'stereo',
bits_per_sample: 0,
id: 'N/A',
r_frame_rate: '0/0',
avg_frame_rate: '0/0',
time_base: '1/48000',
start_pts: 0,
start_time: 0,
duration_ts: 8414160,
duration: 175.295,
bit_rate: 256000,
max_bit_rate: 262152,
bits_per_raw_sample: 'N/A',
nb_frames: 8217,
nb_read_frames: 'N/A',
nb_read_packets: 'N/A',
tags: [Object],
disposition: [Object] } ],
format:
{ filename: '/media/trex/safe1/Development/app/videos/test/440386842.mp4',
nb_streams: 2,
nb_programs: 0,
format_name: 'mov,mp4,m4a,3gp,3g2,mj2',
format_long_name: 'QuickTime / MOV',
start_time: 0,
duration: 175.295,
size: 266214940,
bit_rate: 12149345,
probe_score: 100,
tags:
{ major_brand: 'mp42',
minor_version: '0',
compatible_brands: 'mp42mp41isomavc1',
creation_time: '2015-11-15T19:30:49.000000Z' } },
chapters: [] }