
Recherche avancée
Autres articles (48)
-
Contribute to documentation
13 avril 2011Documentation is vital to the development of improved technical capabilities.
MediaSPIP welcomes documentation by users as well as developers - including : critique of existing features and functions articles contributed by developers, administrators, content producers and editors screenshots to illustrate the above translations of existing documentation into other languages
To contribute, register to the project users’ mailing (...) -
Selection of projects using MediaSPIP
2 mai 2011, parThe examples below are representative elements of MediaSPIP specific uses for specific projects.
MediaSPIP farm @ Infini
The non profit organizationInfini develops hospitality activities, internet access point, training, realizing innovative projects in the field of information and communication technologies and Communication, and hosting of websites. It plays a unique and prominent role in the Brest (France) area, at the national level, among the half-dozen such association. Its members (...) -
Use, discuss, criticize
13 avril 2011, parTalk to people directly involved in MediaSPIP’s development, or to people around you who could use MediaSPIP to share, enhance or develop their creative projects.
The bigger the community, the more MediaSPIP’s potential will be explored and the faster the software will evolve.
A discussion list is available for all exchanges between users.
Sur d’autres sites (4819)
-
How to record frames with ffmpeg and finish the recording
20 février 2024, par Jorge Augusto WilchenIn the following code, i trying to create a class to record frames from an IP camera (RTSP), save frames on a .avi file and finish the record, but, when i kill the operation, the video file may be corrupted. Have any other more safely way to stop the ffmpeg recording ?


.cpp file :


#include "videorecorder.h"


VideoRecorder::VideoRecorder(const std::string& rtspUrl) :
 url(rtspUrl),
 recording(false)
{

}

VideoRecorder::~VideoRecorder()
{
 end_record();
}

bool VideoRecorder::start_record(const std::string &fileName)
{
 if (recording) {
 std::cerr << "Already recording." << std::endl;
 return false;
 }

 std::string command = "ffmpeg -rtsp_transport udp -i " + url
 + " -c:v mjpeg -preset fast -qp 0 " + fileName;

 videoWriter = popen(command.c_str(), "w");
 if (!videoWriter) {
 std::cerr << "Error opening ffmpeg process." << std::endl;
 return false;
 }

 recording = true;
 ffmpegProcessId = getpid();
 std::cout << "Recording started." << std::endl;
 return true;
}

bool VideoRecorder::end_record()
{
 if (recording) {
 if (videoWriter) {
 pid_t ffmpegPID = fileno(videoWriter);

 if (kill(ffmpegPID, SIGTERM) == 0) {
 std::cout << "Recording terminated successfully." << std::endl;
 } else {
 std::cerr << "Error terminating recording." << std::endl;
 return false;
 }

 int status = pclose(videoWriter);

 if (status == 0) {
 std::cout << "Recording ended successfully." << std::endl;
 } else {
 std::cerr << "Error ending recording. pclose status: " << status << std::endl;
 return false;
 }
 } else {
 std::cerr << "Error ending recording. videoWriter is nullptr." << std::endl;
 return false;
 }

 recording = false;
 return true;
 }

 return false;
}



.h file :


#ifndef VIDEORECORDER_H
#define VIDEORECORDER_H

#include <string>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <csignal>
#include <sys></sys>wait.h>

extern "C" {
#include <libavcodec></libavcodec>avcodec.h>
#include <libavformat></libavformat>avformat.h>
#include <libavutil></libavutil>avutil.h>
#include <libavutil></libavutil>opt.h>
#include <libswscale></libswscale>swscale.h>
#include 
}

#include <linux></linux>videodev2.h>

#include <opencv2></opencv2>opencv.hpp>
#include <opencv2></opencv2>videoio.hpp>
#include <opencv2></opencv2>highgui/highgui.hpp>


class VideoRecorder
{
public:
 VideoRecorder(const std::string& rtspUrl);
 ~VideoRecorder();
 bool start_record(const std::string& fileName);
 bool end_record();

private:
 std::string url;
 AVFormatContext *formatContext;
 AVStream *videoStream;
 AVCodecContext *codecContext;
 AVCodec *codec;
 SwsContext *swsContext;
 AVFrame *frame;
 AVPacket packet;
 bool recording;
 pid_t ffmpegProcessId;
 FILE* videoWriter;
};

#endif // VIDEORECORDER_H
</csignal></cstdlib></fstream></iostream></string>


I'm using the ffmpeg lib becouse i need max speed on frames recording, and OpenCV and AV Lib is much slowness than ffmpeg.


This my terminal output after recording during 10 seconds (generated a file with 23 seconds duration) :


Recording started.
ffmpeg version 4.3.6-0+deb11u1+rpt5 Copyright (c) 2000-2023 the FFmpeg developers
 built with gcc 10 (Debian 10.2.1-6)
 configuration: --prefix=/usr --extra-version=0+deb11u1+rpt5 --toolchain=hardened --incdir=/usr/include/aarch64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --disable-mmal --enable-neon --enable-v4l2-request --enable-libudev --enable-epoxy --enable-sand --libdir=/usr/lib/aarch64-linux-gnu --arch=arm64 --enable-pocketsphinx --enable-libdc1394 --enable-libdrm --enable-vout-drm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
 libavutil 56. 51.100 / 56. 51.100
 libavcodec 58. 91.100 / 58. 91.100
 libavformat 58. 45.100 / 58. 45.100
 libavdevice 58. 10.100 / 58. 10.100
 libavfilter 7. 85.100 / 7. 85.100
 libavresample 4. 0. 0 / 4. 0. 0
 libswscale 5. 7.100 / 5. 7.100
 libswresample 3. 7.100 / 3. 7.100
 libpostproc 55. 7.100 / 55. 7.100
Input #0, rtsp, from 'rtsp://admin:[password]@[ip]:[port]/live/0/MAIN':
 Metadata:
 title : RTSP Server
 Duration: N/A, start: 0.280000, bitrate: N/A
 Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 1920x1080, 25 fps, 25 tbr, 90k tbn, 50 tbc
Codec AVOption preset (Configuration preset) specified for output file #0 (/home/guardian-tech/Pictures/output_frame.avi) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
Codec AVOption qp (Constant quantization parameter rate control method) specified for output file #0 (/home/guardian-tech/Pictures/output_frame.avi) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream.
Stream mapping:
 Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))
Press [q] to stop, [?] for help
Output #0, avi, to '/home/guardian-tech/Pictures/output_frame.avi':
 Metadata:
 INAM : RTSP Server
 ISFT : Lavf58.45.100
 Stream #0:0: Video: mjpeg (MJPG / 0x47504A4D), yuvj420p(pc), 1920x1080, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
 Metadata:
 encoder : Lavc58.91.100 mjpeg
 Side data:
 cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
[rtsp @ 0x5592e7bb00] max delay reached. need to consume packet
[rtsp @ 0x5592e7bb00] RTP: missed 212 packets
[h264 @ 0x5592ebb790] concealing 2192 DC, 2192 AC, 2192 MV errors in I frame
rtsp://admin:[password]@[ip]:[port]/live/0/MAIN: corrupt decoded frame in stream 0
[rtsp @ 0x5592e7bb00] max delay reached. need to consume packet
[rtsp @ 0x5592e7bb00] RTP: missed 6 packets
[rtsp @ 0x5592e7bb00] max delay reached. need to consume packet
[rtsp @ 0x5592e7bb00] RTP: missed 14 packets
[h264 @ 0x5592f1bd30] cabac decode of qscale diff failed at 42 29
[h264 @ 0x5592f1bd30] error while decoding MB 42 29, bytestream 0
[h264 @ 0x5592f1bd30] concealing 4687 DC, 4687 AC, 4687 MV errors in I frame
rtsp://admin:[password]@[ip]:[port]/live/0/MAIN: corrupt decoded frame in stream 0
Error terminating recording.



-
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>


-
Linear Attribution Model : What Is It and How Does It Work ?
16 février 2024, par Erin