Recherche avancée

Médias (0)

Mot : - Tags -/content

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (6)

  • Taille des images et des logos définissables

    9 février 2011, par

    Dans beaucoup d’endroits du site, logos et images sont redimensionnées pour correspondre aux emplacements définis par les thèmes. L’ensemble des ces tailles pouvant changer d’un thème à un autre peuvent être définies directement dans le thème et éviter ainsi à l’utilisateur de devoir les configurer manuellement après avoir changé l’apparence de son site.
    Ces tailles d’images sont également disponibles dans la configuration spécifique de MediaSPIP Core. La taille maximale du logo du site en pixels, on permet (...)

  • Configuration spécifique d’Apache

    4 février 2011, par

    Modules spécifiques
    Pour la configuration d’Apache, il est conseillé d’activer certains modules non spécifiques à MediaSPIP, mais permettant d’améliorer les performances : mod_deflate et mod_headers pour compresser automatiquement via Apache les pages. Cf ce tutoriel ; mode_expires pour gérer correctement l’expiration des hits. Cf ce tutoriel ;
    Il est également conseillé d’ajouter la prise en charge par apache du mime-type pour les fichiers WebM comme indiqué dans ce tutoriel.
    Création d’un (...)

  • Emballe médias : à quoi cela sert ?

    4 février 2011, par

    Ce plugin vise à gérer des sites de mise en ligne de documents de tous types.
    Il crée des "médias", à savoir : un "média" est un article au sens SPIP créé automatiquement lors du téléversement d’un document qu’il soit audio, vidéo, image ou textuel ; un seul document ne peut être lié à un article dit "média" ;

Sur d’autres sites (3768)

  • How to record frames with ffmpeg and finish the recording

    20 février 2024, par Jorge Augusto Wilchen

    In 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&#xA;#define VIDEORECORDER_H&#xA;&#xA;#include <string>&#xA;#include <iostream>&#xA;#include <fstream>&#xA;#include <cstdlib>&#xA;#include <csignal>&#xA;#include <sys></sys>wait.h>&#xA;&#xA;extern "C" {&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;#include <libavformat></libavformat>avformat.h>&#xA;#include <libavutil></libavutil>avutil.h>&#xA;#include <libavutil></libavutil>opt.h>&#xA;#include <libswscale></libswscale>swscale.h>&#xA;#include &#xA;}&#xA;&#xA;#include <linux></linux>videodev2.h>&#xA;&#xA;#include <opencv2></opencv2>opencv.hpp>&#xA;#include <opencv2></opencv2>videoio.hpp>&#xA;#include <opencv2></opencv2>highgui/highgui.hpp>&#xA;&#xA;&#xA;class VideoRecorder&#xA;{&#xA;public:&#xA;    VideoRecorder(const std::string&amp; rtspUrl);&#xA;    ~VideoRecorder();&#xA;    bool start_record(const std::string&amp; fileName);&#xA;    bool end_record();&#xA;&#xA;private:&#xA;    std::string url;&#xA;    AVFormatContext *formatContext;&#xA;    AVStream *videoStream;&#xA;    AVCodecContext *codecContext;&#xA;    AVCodec *codec;&#xA;    SwsContext *swsContext;&#xA;    AVFrame *frame;&#xA;    AVPacket packet;&#xA;    bool recording;&#xA;    pid_t ffmpegProcessId;&#xA;    FILE* videoWriter;&#xA;};&#xA;&#xA;#endif // VIDEORECORDER_H&#xA;</csignal></cstdlib></fstream></iostream></string>

    &#xA;

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

    &#xA;

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

    &#xA;

    Recording started.&#xA;ffmpeg version 4.3.6-0&#x2B;deb11u1&#x2B;rpt5 Copyright (c) 2000-2023 the FFmpeg developers&#xA;  built with gcc 10 (Debian 10.2.1-6)&#xA;  configuration: --prefix=/usr --extra-version=0&#x2B;deb11u1&#x2B;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&#xA;  libavutil      56. 51.100 / 56. 51.100&#xA;  libavcodec     58. 91.100 / 58. 91.100&#xA;  libavformat    58. 45.100 / 58. 45.100&#xA;  libavdevice    58. 10.100 / 58. 10.100&#xA;  libavfilter     7. 85.100 /  7. 85.100&#xA;  libavresample   4.  0.  0 /  4.  0.  0&#xA;  libswscale      5.  7.100 /  5.  7.100&#xA;  libswresample   3.  7.100 /  3.  7.100&#xA;  libpostproc    55.  7.100 / 55.  7.100&#xA;Input #0, rtsp, from &#x27;rtsp://admin:[password]@[ip]:[port]/live/0/MAIN&#x27;:&#xA;  Metadata:&#xA;    title           : RTSP Server&#xA;  Duration: N/A, start: 0.280000, bitrate: N/A&#xA;    Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 1920x1080, 25 fps, 25 tbr, 90k tbn, 50 tbc&#xA;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.&#xA;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.&#xA;Stream mapping:&#xA;  Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))&#xA;Press [q] to stop, [?] for help&#xA;Output #0, avi, to &#x27;/home/guardian-tech/Pictures/output_frame.avi&#x27;:&#xA;  Metadata:&#xA;    INAM            : RTSP Server&#xA;    ISFT            : Lavf58.45.100&#xA;    Stream #0:0: Video: mjpeg (MJPG / 0x47504A4D), yuvj420p(pc), 1920x1080, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc&#xA;    Metadata:&#xA;      encoder         : Lavc58.91.100 mjpeg&#xA;    Side data:&#xA;      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A&#xA;[rtsp @ 0x5592e7bb00] max delay reached. need to consume packet&#xA;[rtsp @ 0x5592e7bb00] RTP: missed 212 packets&#xA;[h264 @ 0x5592ebb790] concealing 2192 DC, 2192 AC, 2192 MV errors in I frame&#xA;rtsp://admin:[password]@[ip]:[port]/live/0/MAIN: corrupt decoded frame in stream 0&#xA;[rtsp @ 0x5592e7bb00] max delay reached. need to consume packet&#xA;[rtsp @ 0x5592e7bb00] RTP: missed 6 packets&#xA;[rtsp @ 0x5592e7bb00] max delay reached. need to consume packet&#xA;[rtsp @ 0x5592e7bb00] RTP: missed 14 packets&#xA;[h264 @ 0x5592f1bd30] cabac decode of qscale diff failed at 42 29&#xA;[h264 @ 0x5592f1bd30] error while decoding MB 42 29, bytestream 0&#xA;[h264 @ 0x5592f1bd30] concealing 4687 DC, 4687 AC, 4687 MV errors in I frame&#xA;rtsp://admin:[password]@[ip]:[port]/live/0/MAIN: corrupt decoded frame in stream 0&#xA;Error terminating recording.&#xA;

    &#xA;

  • FFmpeg Concatenation Command Fails in Flutter App

    18 février 2024, par Petro

    I'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.

    &#xA;

    FFMPEG Version : ffmpeg_kit_flutter: ^6.0.3-LTS

    &#xA;

    All of the files are present when this happens...&#xA;enter image description here

    &#xA;

    Environment :&#xA;Flutter app targeting Android&#xA;Using ffmpeg-kit-flutter for FFmpeg operations

    &#xA;

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

    &#xA;

    Code Snippet :&#xA;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 :

    &#xA;

    Future<void> _createVideoFromImages() async {&#xA;  final Directory appDir = await getApplicationDocumentsDirectory();&#xA;  final Uuid uuid = Uuid();&#xA;  final String videoFileName = uuid.v4();&#xA;  final String outputPath = &#x27;${appDir.path}/$videoFileName.mp4&#x27;;&#xA;  &#xA;  final Directory tempImageDir = await Directory(&#x27;${appDir.path}/tempImages&#x27;).create();&#xA;  final StringBuffer ffmpegInput = StringBuffer();&#xA;  int index = 0;&#xA;&#xA;  for (var image in _images) {&#xA;    String newFileName = &#x27;img${index&#x2B;&#x2B;}${Path.extension(image.path)}&#x27;.replaceAll(&#x27; &#x27;, &#x27;_&#x27;);&#xA;    final String newPath = &#x27;${tempImageDir.path}/$newFileName&#x27;;&#xA;    await image.copy(newPath);&#xA;    ffmpegInput.writeln("file &#x27;$newPath&#x27;");&#xA;  }&#xA;&#xA;  final String listFilePath = &#x27;${appDir.path}/ffmpeg_list.txt&#x27;;&#xA;  await File(listFilePath).writeAsString(ffmpegInput.toString());&#xA;&#xA;  if(await File(listFilePath).exists()) {&#xA;    String ffmpegCommand = "-v verbose -f concat -safe 0 -i $listFilePath -vsync vfr -pix_fmt yuv420p -c:v libx264 -r 30 $outputPath";&#xA;    // Additional commands tried here...&#xA;    await FFmpegKit.execute(ffmpegCommand).then((session) async {&#xA;      // Error handling code...&#xA;    });&#xA;  }&#xA;}&#xA;&#xA;Result Logs:&#xA;I/flutter: file exists at /data/user/0/com.example.app/app_flutter/ffmpeg_list.txt&#xA;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&#xA;I/flutter: Failed to create video&#xA;I/flutter: FFmpeg process exited with:1&#xA;I/flutter: FFmpeg command failed with logs: ffmpeg version n6.0 Copyright (c) 2000-2023 the FFmpeg developers...&#xA;</void>

    &#xA;

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

    &#xA;

    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.

    &#xA;

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

    &#xA;

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

    &#xA;

    Full code :

    &#xA;

    Future<void> _createVideoFromImages() async {&#xA;    final Directory appDir = await getApplicationDocumentsDirectory();&#xA;    final Uuid uuid = Uuid();&#xA;    final String videoFileName = uuid.v4();&#xA;    final String outputPath = &#x27;${appDir.path}/$videoFileName.mp4&#x27;;&#xA;    final String singleImagePath = _images[0]!.path;&#xA;&#xA;// Create a directory to store renamed images to avoid any naming conflict&#xA;    final Directory tempImageDir = await Directory(&#x27;${appDir.path}/tempImages&#x27;).create();&#xA;&#xA;    final StringBuffer ffmpegInput = StringBuffer();&#xA;    int index = 0; // To ensure unique filenames&#xA;&#xA;    for (var image in _images) {&#xA;      // Generate a new filename by replacing spaces with underscores and adding an index&#xA;      String newFileName = &#x27;img${index&#x2B;&#x2B;}${p.extension(image!.path)}&#x27;.replaceAll(&#x27; &#x27;, &#x27;_&#x27;);&#xA;      final String newPath = &#x27;${tempImageDir.path}/$newFileName&#x27;;&#xA;&#xA;      // Copy and rename the original file to the new path&#xA;      await image!.copy(newPath);&#xA;&#xA;      // Add the new, safely named file path to the ffmpegInput&#xA;      ffmpegInput.writeln("file &#x27;$newPath&#x27;");&#xA;    }&#xA;&#xA;// Write the paths to a temporary text file for FFmpeg&#x27;s concat demuxer&#xA;    final String listFilePath = &#x27;${appDir.path}/ffmpeg_list.txt&#x27;;&#xA;    await File(listFilePath).writeAsString(ffmpegInput.toString());&#xA;&#xA;    //check if file exists&#xA;    if(await File(listFilePath).exists()) {&#xA;      print("file exists at $listFilePath");&#xA;&#xA;// Use the generated list file in the concat command&#xA;      String ffmpegCommand = "-v verbose -f concat -safe 0 -i $listFilePath -vsync vfr -pix_fmt yuv420p -c:v libx264 -r 30 $outputPath";&#xA;      String ffmpegCommand2 = "-v verbose -f concat -safe 0 -i $listFilePath -c:v libx264 $outputPath";&#xA;      String ffmpegCommand3 = "-v verbose -i $singleImagePath -frames:v 1 $outputPath";&#xA;      //print command&#xA;      print("FFmpeg command: $ffmpegCommand");&#xA;&#xA;&#xA;      await FFmpegKit.execute(ffmpegCommand).then((session) async {&#xA;        // Check the session for success or failure&#xA;        final returnCode = await session.getReturnCode();&#xA;        if (returnCode!.isValueSuccess()) {&#xA;          print("Video created successfully: $outputPath");&#xA;          //okay all set, now set the video to be this:&#xA;          _actual_video_file_ready_to_upload = File(outputPath);&#xA;          print ("video path is: ${outputPath}");&#xA;        } else {&#xA;          print("Failed to create video");&#xA;          print("FFmpeg process exited with:" &#x2B; returnCode.toString());&#xA;          // Command failed; capture and log error details&#xA;          await session.getLogsAsString().then((logs) {&#xA;            print("FFmpeg command failed with logs: $logs");&#xA;          });&#xA;          // Handle failure, e.g., by showing an error message&#xA;          showSnackBarHelperERRORWrapLongString(context, "Failed to create video");&#xA;        }&#xA;      });&#xA;&#xA;      //try command 2&#xA;      if(_actual_video_file_ready_to_upload == null) {&#xA;        await FFmpegKit.execute(ffmpegCommand2).then((session) async {&#xA;          // Check the session for success or failure&#xA;          final returnCode = await session.getReturnCode();&#xA;          if (returnCode!.isValueSuccess()) {&#xA;            print("Video created successfully: $outputPath");&#xA;            //okay all set, now set the video to be this:&#xA;            _actual_video_file_ready_to_upload = File(outputPath);&#xA;            print ("video path is: ${outputPath}");&#xA;          } else {&#xA;            print("Failed to create video");&#xA;            print("FFmpeg process exited with:" &#x2B; returnCode.toString());&#xA;            // Command failed; capture and log error details&#xA;            await session.getLogsAsString().then((logs) {&#xA;              print("FFmpeg command failed with logs: $logs");&#xA;            });&#xA;            // Handle failure, e.g., by showing an error message&#xA;            showSnackBarHelperERRORWrapLongString(context, "Failed to create video");&#xA;          }&#xA;        });&#xA;      }&#xA;      //try command 3&#xA;      if(_actual_video_file_ready_to_upload == null) {&#xA;        await FFmpegKit.execute(ffmpegCommand3).then((session) async {&#xA;          // Check the session for success or failure&#xA;          final returnCode = await session.getReturnCode();&#xA;          if (returnCode!.isValueSuccess()) {&#xA;            print("Video created successfully: $outputPath");&#xA;            //okay all set, now set the video to be this:&#xA;            _actual_video_file_ready_to_upload = File(outputPath);&#xA;            print ("video path is: ${outputPath}");&#xA;          } else {&#xA;            print("Failed to create video");&#xA;            print("FFmpeg process exited with:" &#x2B; returnCode.toString());&#xA;            // Command failed; capture and log error details&#xA;            await session.getLogsAsString().then((logs) {&#xA;              print("FFmpeg command failed with logs: $logs");&#xA;            });&#xA;            // Handle failure, e.g., by showing an error message&#xA;            showSnackBarHelperERRORWrapLongString(context, "Failed to create video");&#xA;          }&#xA;        });&#xA;      }&#xA;    }else{&#xA;      print("file does not exist at $listFilePath");&#xA;    }&#xA;  }&#xA;</void>

    &#xA;

  • Revision 30966 : eviter le moche ’doctype_ecrire’ lors de l’upgrade

    17 août 2009, par fil@… — Log

    eviter le moche ’doctype_ecrire’ lors de l’upgrade