
Recherche avancée
Autres articles (102)
-
Personnaliser en ajoutant son logo, sa bannière ou son image de fond
5 septembre 2013, parCertains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;
-
Ecrire une actualité
21 juin 2013, parPrésentez les changements dans votre MédiaSPIP ou les actualités de vos projets sur votre MédiaSPIP grâce à la rubrique actualités.
Dans le thème par défaut spipeo de MédiaSPIP, les actualités sont affichées en bas de la page principale sous les éditoriaux.
Vous pouvez personnaliser le formulaire de création d’une actualité.
Formulaire de création d’une actualité Dans le cas d’un document de type actualité, les champs proposés par défaut sont : Date de publication ( personnaliser la date de publication ) (...) -
Organiser par catégorie
17 mai 2013, parDans MédiaSPIP, une rubrique a 2 noms : catégorie et rubrique.
Les différents documents stockés dans MédiaSPIP peuvent être rangés dans différentes catégories. On peut créer une catégorie en cliquant sur "publier une catégorie" dans le menu publier en haut à droite ( après authentification ). Une catégorie peut être rangée dans une autre catégorie aussi ce qui fait qu’on peut construire une arborescence de catégories.
Lors de la publication prochaine d’un document, la nouvelle catégorie créée sera proposée (...)
Sur d’autres sites (6435)
-
FFmpeg Concatenation Command Fails in Flutter App
18 février 2024, par PetroI'm developing a Flutter application where I need to concatenate several images into a single video file using FFmpeg. Despite following the recommended practices and trying multiple variations of the FFmpeg command, all my attempts result in failure with an exit code of 1.


FFMPEG Version :
ffmpeg_kit_flutter: ^6.0.3-LTS


All of the files are present when this happens...



Environment :
Flutter app targeting Android
Using ffmpeg-kit-flutter for FFmpeg operations


Objective :
To concatenate multiple images stored in the app's file system into a video.


Code Snippet :
I'm generating a list of image paths, writing them to a file (ffmpeg_list.txt), and using that file with FFmpeg's concat demuxer. Here's a simplified version of my code :


Future<void> _createVideoFromImages() async {
 final Directory appDir = await getApplicationDocumentsDirectory();
 final Uuid uuid = Uuid();
 final String videoFileName = uuid.v4();
 final String outputPath = '${appDir.path}/$videoFileName.mp4';
 
 final Directory tempImageDir = await Directory('${appDir.path}/tempImages').create();
 final StringBuffer ffmpegInput = StringBuffer();
 int index = 0;

 for (var image in _images) {
 String newFileName = 'img${index++}${Path.extension(image.path)}'.replaceAll(' ', '_');
 final String newPath = '${tempImageDir.path}/$newFileName';
 await image.copy(newPath);
 ffmpegInput.writeln("file '$newPath'");
 }

 final String listFilePath = '${appDir.path}/ffmpeg_list.txt';
 await File(listFilePath).writeAsString(ffmpegInput.toString());

 if(await File(listFilePath).exists()) {
 String ffmpegCommand = "-v verbose -f concat -safe 0 -i $listFilePath -vsync vfr -pix_fmt yuv420p -c:v libx264 -r 30 $outputPath";
 // Additional commands tried here...
 await FFmpegKit.execute(ffmpegCommand).then((session) async {
 // Error handling code...
 });
 }
}

Result Logs:
I/flutter: file exists at /data/user/0/com.example.app/app_flutter/ffmpeg_list.txt
I/flutter: FFmpeg command: -v verbose -f concat -safe 0 -i /data/user/0/com.example.app/app_flutter/ffmpeg_list.txt -vsync vfr -pix_fmt yuv420p -c:v libx264 -r 30 /data/user/0/com.example.app/app_flutter/58fdf92b-47b0-49d1-be93-d9c95870c733.mp4
I/flutter: Failed to create video
I/flutter: FFmpeg process exited with:1
I/flutter: FFmpeg command failed with logs: ffmpeg version n6.0 Copyright (c) 2000-2023 the FFmpeg developers...
</void>


Attempts :
-Simplified the FFmpeg command by removing -vsync vfr, -pix_fmt yuv420p, and adjusting -r 30 parameters.
-Tried using the -c copy option to avoid re-encoding.
-Tested with a single image to ensure basic functionality works.
-Checked file permissions and ensured all images and the list file are accessible.


Despite these attempts, the command fails without providing specific error messages related to the command's execution. The verbose logs do not offer insights beyond the FFmpeg version and configuration.


Questions :
Are there known issues with FFmpeg's concat that might lead to such failures ?
Are there alternative approaches ?


I appreciate any insights or suggestions the community might have. Thank you !


Full code :


Future<void> _createVideoFromImages() async {
 final Directory appDir = await getApplicationDocumentsDirectory();
 final Uuid uuid = Uuid();
 final String videoFileName = uuid.v4();
 final String outputPath = '${appDir.path}/$videoFileName.mp4';
 final String singleImagePath = _images[0]!.path;

// Create a directory to store renamed images to avoid any naming conflict
 final Directory tempImageDir = await Directory('${appDir.path}/tempImages').create();

 final StringBuffer ffmpegInput = StringBuffer();
 int index = 0; // To ensure unique filenames

 for (var image in _images) {
 // Generate a new filename by replacing spaces with underscores and adding an index
 String newFileName = 'img${index++}${p.extension(image!.path)}'.replaceAll(' ', '_');
 final String newPath = '${tempImageDir.path}/$newFileName';

 // Copy and rename the original file to the new path
 await image!.copy(newPath);

 // Add the new, safely named file path to the ffmpegInput
 ffmpegInput.writeln("file '$newPath'");
 }

// Write the paths to a temporary text file for FFmpeg's concat demuxer
 final String listFilePath = '${appDir.path}/ffmpeg_list.txt';
 await File(listFilePath).writeAsString(ffmpegInput.toString());

 //check if file exists
 if(await File(listFilePath).exists()) {
 print("file exists at $listFilePath");

// Use the generated list file in the concat command
 String ffmpegCommand = "-v verbose -f concat -safe 0 -i $listFilePath -vsync vfr -pix_fmt yuv420p -c:v libx264 -r 30 $outputPath";
 String ffmpegCommand2 = "-v verbose -f concat -safe 0 -i $listFilePath -c:v libx264 $outputPath";
 String ffmpegCommand3 = "-v verbose -i $singleImagePath -frames:v 1 $outputPath";
 //print command
 print("FFmpeg command: $ffmpegCommand");


 await FFmpegKit.execute(ffmpegCommand).then((session) async {
 // Check the session for success or failure
 final returnCode = await session.getReturnCode();
 if (returnCode!.isValueSuccess()) {
 print("Video created successfully: $outputPath");
 //okay all set, now set the video to be this:
 _actual_video_file_ready_to_upload = File(outputPath);
 print ("video path is: ${outputPath}");
 } else {
 print("Failed to create video");
 print("FFmpeg process exited with:" + returnCode.toString());
 // Command failed; capture and log error details
 await session.getLogsAsString().then((logs) {
 print("FFmpeg command failed with logs: $logs");
 });
 // Handle failure, e.g., by showing an error message
 showSnackBarHelperERRORWrapLongString(context, "Failed to create video");
 }
 });

 //try command 2
 if(_actual_video_file_ready_to_upload == null) {
 await FFmpegKit.execute(ffmpegCommand2).then((session) async {
 // Check the session for success or failure
 final returnCode = await session.getReturnCode();
 if (returnCode!.isValueSuccess()) {
 print("Video created successfully: $outputPath");
 //okay all set, now set the video to be this:
 _actual_video_file_ready_to_upload = File(outputPath);
 print ("video path is: ${outputPath}");
 } else {
 print("Failed to create video");
 print("FFmpeg process exited with:" + returnCode.toString());
 // Command failed; capture and log error details
 await session.getLogsAsString().then((logs) {
 print("FFmpeg command failed with logs: $logs");
 });
 // Handle failure, e.g., by showing an error message
 showSnackBarHelperERRORWrapLongString(context, "Failed to create video");
 }
 });
 }
 //try command 3
 if(_actual_video_file_ready_to_upload == null) {
 await FFmpegKit.execute(ffmpegCommand3).then((session) async {
 // Check the session for success or failure
 final returnCode = await session.getReturnCode();
 if (returnCode!.isValueSuccess()) {
 print("Video created successfully: $outputPath");
 //okay all set, now set the video to be this:
 _actual_video_file_ready_to_upload = File(outputPath);
 print ("video path is: ${outputPath}");
 } else {
 print("Failed to create video");
 print("FFmpeg process exited with:" + returnCode.toString());
 // Command failed; capture and log error details
 await session.getLogsAsString().then((logs) {
 print("FFmpeg command failed with logs: $logs");
 });
 // Handle failure, e.g., by showing an error message
 showSnackBarHelperERRORWrapLongString(context, "Failed to create video");
 }
 });
 }
 }else{
 print("file does not exist at $listFilePath");
 }
 }
</void>


-
Split video with ffmpeg segment option is missing frame
9 février 2024, par DanI’m trying to get the ffmpeg “segment” option to split my video into segments at the Iframes. I'm using ffmpeg V6.1.1.


First I added time stamps to each frame of my video so that when it plays, I can see exactly which frame is being displayed. I used this command :


ffmpeg -i In.mp4 -vf "drawtext=fontfile='C :\Windows\Fonts\Arial.ttf' : text='%frame_num :~ %pts':fontsize=200 : r=25 : x=(w-tw)/2 : y=h-(2*lh) : fontcolor=white : box=1 : boxcolor=0x00000099" -y Out.mp4


Then I used ffprobe to confirm that the video is 30 FPS and the Iframes are as follows :


0.000000
4.933333
10.000000
11.533333
18.866667
24.966667


Based on these Iframe times, I’d expect the following segments :







 Start Frame 

Start Time 

End Frame 

End Time 







 0 

0 

147 

4.900000 




 148 

4.933333 

299 

9.966667 




 300 

10.000000 

345 

11.500000 




 346 

11.533333 

565 

18.833334 




 566 

18.866667 

748 

24.933334 




 749 

24.966667 

867 

28.906667 









When I use ffmpeg to split the video into segments with the following command, I get six files as expected :


ffmpeg -i Out.mp4 -f segment -c copy -reset_timestamps 1 -map 0 "Out %d.mp4"


When I play the segments, they are all correct except the first segment file (Out 0.mp4). It seems to be missing the last frame. It contains frames 0 to 146 (4.866667 sec) but should also include frame 147 (4.9 sec). All the other segment files are as expected.


I’ve tried this on several different mp4 videos and they all are missing the last frame on the first segments.


Any idea why my first segment files is missing the last frame of the segment ?


Could this be an ffmpeg bug ?


Thanks for the help !
Dan


Here is my console session with all output :


C:\> ffprobe Out.mp4
ffprobe version 2023-12-21-git-1e42a48e37-full_build-www.gyan.dev Copyright (c) 2007-2023 the FFmpeg developers
 built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
 configuration: --enable-gpl --enable-version3 --enable-static --pkg-config=pkgconf --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-dxva2 --enable-d3d11va --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
 libavutil 58. 36.100 / 58. 36.100
 libavcodec 60. 36.100 / 60. 36.100
 libavformat 60. 20.100 / 60. 20.100
 libavdevice 60. 4.100 / 60. 4.100
 libavfilter 9. 14.100 / 9. 14.100
 libswscale 7. 6.100 / 7. 6.100
 libswresample 4. 13.100 / 4. 13.100
 libpostproc 57. 4.100 / 57. 4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Out.mp4':
 Metadata:
 major_brand : isom
 minor_version : 512
 compatible_brands: isomiso2avc1mp41
 title : Short 4k video sample - 4K Ultra HD (3840x2160)
 date : 2014:05:24 19:00:00
 encoder : Lavf60.20.100
 Duration: 00:00:28.96, start: 0.000000, bitrate: 3181 kb/s
 Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 3045 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
 Metadata:
 handler_name : VideoHandler
 vendor_id : [0][0][0][0]
 encoder : Lavc60.36.100 libx264
 Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
 Metadata:
 handler_name : SoundHandler
 vendor_id : [0][0][0][0]

C:\ ffprobe -loglevel error -skip_frame nokey -select_streams v:0 -show_entries frame=pts_time -of csv=print_section=0 Out.mp4
0.000000,
4.933333
10.000000
11.533333
18.866667
24.966667

C:\ ffmpeg -i Out.mp4 -f segment -c copy -reset_timestamps 1 -map 0 "Out %1d.mp4"
ffmpeg version 2023-12-21-git-1e42a48e37-full_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
 built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
 configuration: --enable-gpl --enable-version3 --enable-static --pkg-config=pkgconf --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-dxva2 --enable-d3d11va --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
 libavutil 58. 36.100 / 58. 36.100
 libavcodec 60. 36.100 / 60. 36.100
 libavformat 60. 20.100 / 60. 20.100
 libavdevice 60. 4.100 / 60. 4.100
 libavfilter 9. 14.100 / 9. 14.100
 libswscale 7. 6.100 / 7. 6.100
 libswresample 4. 13.100 / 4. 13.100
 libpostproc 57. 4.100 / 57. 4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Out.mp4':
 Metadata:
 major_brand : isom
 minor_version : 512
 compatible_brands: isomiso2avc1mp41
 title : Short 4k video sample - 4K Ultra HD (3840x2160)
 date : 2014:05:24 19:00:00
 encoder : Lavf60.20.100
 Duration: 00:00:28.96, start: 0.000000, bitrate: 3181 kb/s
 Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 3045 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
 Metadata:
 handler_name : VideoHandler
 vendor_id : [0][0][0][0]
 encoder : Lavc60.36.100 libx264
 Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
 Metadata:
 handler_name : SoundHandler
 vendor_id : [0][0][0][0]
Stream mapping:
 Stream #0:0 -> #0:0 (copy)
 Stream #0:1 -> #0:1 (copy)
[segment @ 00000195bbc52940] Opening 'Out 0.mp4' for writing
Output #0, segment, to 'Out %1d.mp4':
 Metadata:
 major_brand : isom
 minor_version : 512
 compatible_brands: isomiso2avc1mp41
 title : Short 4k video sample - 4K Ultra HD (3840x2160)
 date : 2014:05:24 19:00:00
 encoder : Lavf60.20.100
 Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 3045 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
 Metadata:
 handler_name : VideoHandler
 vendor_id : [0][0][0][0]
 encoder : Lavc60.36.100 libx264
 Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
 Metadata:
 handler_name : SoundHandler
 vendor_id : [0][0][0][0]
Press [q] to stop, [?] for help
[segment @ 00000195bbc52940] Opening 'Out 1.mp4' for writing
[segment @ 00000195bbc52940] Opening 'Out 2.mp4' for writing
[segment @ 00000195bbc52940] Opening 'Out 3.mp4' for writing
[segment @ 00000195bbc52940] Opening 'Out 4.mp4' for writing
[segment @ 00000195bbc52940] Opening 'Out 5.mp4' for writing
[out#0/segment @ 00000195bc3e8cc0] video:10757kB audio:456kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
size=N/A time=00:00:28.86 bitrate=N/A speed= 322x



-
PHP-FFMPEG Waveform is not clean, is it a bug ?
6 février 2024, par MaxiI made a waveform through sample code :


$waveform = $audio->waveform(2000, 500, array('#FFA500'));
$waveform->save('waveform.png');



But result has some noise in top & bottom of edges.
How can make it better ?


PHP-FFMpeg : 23 | FFMpeg : 2023-02-27-git-891ed24f77 (Win X64) | PHP : 8.3