Recherche avancée

Médias (1)

Mot : - Tags -/intégration

Autres articles (99)

  • MediaSPIP 0.1 Beta version

    25 avril 2011, par

    MediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
    The zip file provided here only contains the sources of MediaSPIP in its standalone version.
    To get a working installation, you must manually install all-software dependencies on the server.
    If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...)

  • Personnaliser en ajoutant son logo, sa bannière ou son image de fond

    5 septembre 2013, par

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

  • Multilang : améliorer l’interface pour les blocs multilingues

    18 février 2011, par

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

Sur d’autres sites (11945)

  • Crash on ffmpeg avcodec_encode_video in a Console app [closed]

    11 janvier 2024, par Robel Sharma

    I want make an encoder which encode a raw image into h263 format.But after loading and initializing ffmpeg library I got crash on avcodec_encode_video for a demo image.

    



    int _tmain(int argc, _TCHAR* argv[]) {
    avcodec_register_all();
    AVCodec *codec;
    AVCodecContext *c= NULL;
    int i, ret, x, y, got_output;
    FILE *f;
    AVFrame *frame;
    AVPacket pkt;

    int out_size, size, outbuf_size;

    AVFrame *picture;
    uint8_t *outbuf, *picture_buf;

    AVRational rp;   

    rp.den = 1;
    rp.num = 25;
    uint8_t endcode[] = { 0, 0, 1, 0xb7 };

    codec = avcodec_find_encoder(CODEC_ID_H263);

    c = avcodec_alloc_context3(codec);
    picture= avcodec_alloc_frame();
    c->bit_rate = 400000;
    /* resolution must be a multiple of two */
    c->width = 352;
    c->height = 288;
    /* frames per second */
    //c->time_base= (AVRational){1,25};
    c->time_base = rp;
    c->gop_size = 10; /* emit one intra frame every ten frames */
    c->max_b_frames=1;
    c->pix_fmt = PIX_FMT_YUV420P;
    avcodec_open(c, codec);


    outbuf_size = 100000;
    outbuf = (uint8_t*)malloc(outbuf_size);
    size = c->width * c->height;
    picture_buf = (uint8_t*)malloc((size * 3) / 2); /* size for YUV 420 */

    picture->data[0] = picture_buf;
    picture->data[1] = picture->data[0] + size;
    picture->data[2] = picture->data[1] + size / 4;
    picture->linesize[0] = c->width;
    picture->linesize[1] = c->width / 2;
    picture->linesize[2] = c->width / 2;

    /* encode 1 second of video */
    for(i=0;i<25;i++) {
        fflush(stdout);
        /* prepare a dummy image */
        /* Y */
        for(y=0;yheight;y++) {
            for(x=0;xwidth;x++) {
                picture->data[0][y * picture->linesize[0] + x] = x + y + i * 3;
            }
        }
        /* Cb and Cr */
        for(y=0;yheight/2;y++) {
            for(x=0;xwidth/2;x++) {
                picture->data[1][y * picture->linesize[1] + x] = 128 + y + i * 2;
                picture->data[2][y * picture->linesize[2] + x] = 64 + x + i * 5;
            }
        }
        /* encode the image */

        **Crash is here** --->                 ///////////////////////////////////////////////////
        out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);

        printf("encoding frame %3d (size=%5d)\n", i, out_size);
        fwrite(outbuf, 1, out_size, f);
    }
    /* get the delayed frames */
    for(; out_size; i++) {
        fflush(stdout);
        out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL);
        printf("write frame %3d (size=%5d)\n", i, out_size);
        fwrite(outbuf, 1, out_size, f);
    }
    /* add sequence end code to have a real mpeg file */
    outbuf[0] = 0x00;
    outbuf[1] = 0x00;
    outbuf[2] = 0x01;
    outbuf[3] = 0xb7;
    fwrite(outbuf, 1, 4, f);
    fclose(f);
    free(picture_buf);
    free(outbuf);

    avcodec_close(c);
    av_free(c);
    av_free(picture);
    printf("\n");
    return 0;
}


    


  • How can you combine multiple video files with FFMPEG and merging the audio track as well

    19 décembre 2023, par Codrut

    I'm trying to combine multiple MP4 files in Delphi with the FFMPEG video library. I have the headers unit with all the functions. All videos are MPEG-4, and so is the destination output file.

    


    I found this question on Stack Overflow asking the same question. To combine video files while keeping the audio and video tracks.
I have translated the answers to Delphi, and while the code is executed successfully, the output file is invalid and cannot be played.

    


    Here is my implementation :

    


    var&#xA;  Files: TArray<pansichar>;&#xA;  Output: PAnsiChar;&#xA;&#xA;  I, S: integer;&#xA;&#xA;  i_fmt_ctx: PAVFormatContext;&#xA;  i_video_stream: PAVStream;&#xA;  o_fmt_ctx: PAVFormatContext;&#xA;  o_video_stream: PAVStream;&#xA;&#xA;  P: PPAVStream;&#xA;begin&#xA;  SetLength(Files, 2);&#xA;  Files[0] := PAnsiChar(&#x27;.\Clips\file9.mp4&#x27;);&#xA;  Files[1] := PAnsiChar(&#x27;.\Clips\file10.mp4&#x27;);&#xA;  Output := &#x27;.\Output\out.mp4&#x27;;&#xA;&#xA;  avcodec_register_all();   &#xA;  av_register_all();&#xA;&#xA;  (* should set to NULL so that avformat_open_input() allocate a new one *)&#xA;  i_fmt_ctx := nil;&#xA;&#xA;  if avformat_open_input(@i_fmt_ctx, Files[0], nil, nil) &lt;> 0 then&#xA;    raise Exception.Create(&#x27;Could not open file&#x27;);&#xA;&#xA;  if avformat_find_stream_info(i_fmt_ctx, nil) &lt; 0 then&#xA;    raise Exception.Create(&#x27;Could not find stream info&#x27;);&#xA;                &#xA;  (* Find 1st video stream *)&#xA;  i_video_stream := nil;&#xA;  P := i_fmt_ctx.streams;&#xA;  for i := 0 to i_fmt_ctx.nb_streams-1 do begin&#xA;    if P^.codec.codec_type = AVMEDIA_TYPE_VIDEO then&#xA;      begin&#xA;        i_video_stream := P^;&#xA;        Break;&#xA;      end;&#xA;    Inc(P);&#xA;  end;&#xA;  if i_video_stream = nil then&#xA;    raise Exception.Create(&#x27;Could not find video stream&#x27;);&#xA;&#xA;  avformat_alloc_output_context2(@o_fmt_ctx, nil, nil, Output);&#xA;&#xA;  (*&#xA;  since all input files are supposed to be identical (framerate, dimension, color format, ...)&#xA;  we can safely set output codec values from first input file&#xA;  *)&#xA;  o_video_stream := avformat_new_stream(o_fmt_ctx, nil);&#xA;  &#xA;  var c: PAVCodecContext;&#xA;  c := o_video_stream.codec;&#xA;  c.bit_rate := 400000;&#xA;  c.codec_id := i_video_stream.codec.codec_id;&#xA;  c.codec_type := i_video_stream.codec.codec_type;&#xA;  c.time_base.num := i_video_stream.time_base.num;&#xA;  c.time_base.den := i_video_stream.time_base.den;&#xA;  //fprintf(stderr, "time_base.num = %d time_base.den = %d\n", c->time_base.num, c->time_base.den);&#xA;  c.width := i_video_stream.codec.width;&#xA;  c.height := i_video_stream.codec.height;&#xA;  c.pix_fmt := i_video_stream.codec.pix_fmt;&#xA;  //printf("%d %d %d", c->width, c->height, c->pix_fmt);&#xA;  c.flags := i_video_stream.codec.flags;&#xA;  c.flags := c.flags or CODEC_FLAG_GLOBAL_HEADER;&#xA;  c.me_range := i_video_stream.codec.me_range;&#xA;  c.max_qdiff := i_video_stream.codec.max_qdiff;&#xA;&#xA;  c.qmin := i_video_stream.codec.qmin;&#xA;  c.qmax := i_video_stream.codec.qmax;&#xA;&#xA;  c.qcompress := i_video_stream.codec.qcompress;&#xA;&#xA;  c.extradata := i_video_stream.codec.extradata;&#xA;  c.extradata_size := i_video_stream.codec.extradata_size;&#xA;&#xA;  avio_open(@o_fmt_ctx.pb, Output, AVIO_FLAG_WRITE);&#xA;&#xA;  (* yes! this is redundant *)&#xA;  avformat_close_input(@i_fmt_ctx);&#xA;&#xA;  avformat_write_header(o_fmt_ctx, nil);&#xA;&#xA;  var last_pts: integer; last_pts := 0;&#xA;  var last_dts: integer; last_dts := 0;&#xA;  for i := 1 to High(Files) do begin&#xA;    i_fmt_ctx := nil;&#xA;&#xA;    if avformat_open_input(@i_fmt_ctx, Files[i], nil, nil) &lt;> 0 then&#xA;      raise Exception.Create(&#x27;Could not open input file&#x27;);&#xA;&#xA;    if avformat_find_stream_info(i_fmt_ctx, nil) &lt; 0 then&#xA;      raise Exception.Create(&#x27;Could not find stream info&#x27;);&#xA;&#xA;    av_dump_format(i_fmt_ctx, 0, Files[i], 0);&#xA;    &#xA;    (* we only use first video stream of each input file *)&#xA;    i_video_stream := nil;&#xA;&#xA;    P := i_fmt_ctx.streams;&#xA;    for S := 0 to i_fmt_ctx.nb_streams-1 do&#xA;      begin&#xA;        if (P^.codec.codec_type = AVMEDIA_TYPE_VIDEO) then&#xA;          begin&#xA;            i_video_stream := P^;&#xA;            break;&#xA;          end;&#xA;        &#xA;        Inc(P);&#xA;      end;&#xA;&#xA;    if i_video_stream = nil then&#xA;      raise Exception.Create(&#x27;Could not find video stream&#x27;);&#xA;    &#xA;    var pts, dts: int64;&#xA;    pts := 0; dts := 0;&#xA;    while true do begin&#xA;      var i_pkt: TAVPacket;&#xA;      av_init_packet( @i_pkt );&#xA;      i_pkt.size := 0;&#xA;      i_pkt.data := nil;&#xA;&#xA;      if av_read_frame(i_fmt_ctx, @i_pkt) &lt; 0 then&#xA;        break;&#xA;      (*&#xA;        pts and dts should increase monotonically&#xA;        pts should be >= dts&#xA;      *)&#xA;      i_pkt.flags := i_pkt.flags or AV_PKT_FLAG_KEY;&#xA;      pts := i_pkt.pts;&#xA;      Inc(i_pkt.pts, last_pts);&#xA;      dts := i_pkt.dts;&#xA;      Inc(i_pkt.dts, last_dts);&#xA;      i_pkt.stream_index := 0;&#xA;&#xA;      // Write&#xA;      av_interleaved_write_frame(o_fmt_ctx, @i_pkt);&#xA;    end;&#xA;&#xA;    Inc(last_dts, dts);&#xA;    Inc(last_pts, pts);  &#xA;  &#xA;    avformat_close_input(@i_fmt_ctx)&#xA;  end;&#xA;&#xA;  av_write_trailer(o_fmt_ctx);&#xA;&#xA;  avcodec_close(o_fmt_ctx.streams^.codec);&#xA;  av_freep(&amp;o_fmt_ctx.streams^.codec);&#xA;  av_freep(&amp;o_fmt_ctx.streams);&#xA;&#xA;  avio_close(o_fmt_ctx.pb);&#xA;  av_free(o_fmt_ctx);&#xA;</pansichar>

    &#xA;

    Which is a translation of Михаил Чеботарев's answer.

    &#xA;

    Even if the code worked, I see no handling of the AVMEDIA_TYPE_AUDIO stream, which means this answer is 1/2 of the problem, since It only combines the video stream.

    &#xA;

    Another approach I tried was using the UBitmaps2Video FFMPEG implementation, which is successfully able to merge the video files, but only the video stream, no audio.

    &#xA;

    I tried manually converting the audio stream with the Bass Audio Library. It was able to read the audio and write It in a single WAV file, which then I converted to MP3. Finally muxing the combined video file and the MP3 file with MuxStreams2. Unfortunately, the audio and video do not align properly. I was unable to pinpoint the issue.

    &#xA;

    Currently, the only functional option is using the precompiled FFMPEG Executables and using ShellExecute with the according parameters to combine the videos.&#xA;This more exactly :

    &#xA;

    ffmpeg -f concat -safe 0 -i video-list.txt -c copy output.mp4&#xA;

    &#xA;

    But I would still rather use the FFMPEG headers in Delphi to combine the videos that way, as that gives the option for Progress indicatiors, more control of the playback and the ability to pause the thread at any point.

    &#xA;

    So, why does my implementation to merge video files not work. And what is a good method to include the audio stream as well ?

    &#xA;

  • TS video copied to MP4, missing 3 first frames when programmatically read (ffmpeg bug)

    3 septembre 2023, par Vasilis Lemonidis

    Running :

    &#xA;

    ffmpeg -i test.ts -fflags &#x2B;genpts -c copy -y test.mp4&#xA;

    &#xA;

    for this test.ts, which has 30 frames, readable by opencv, I end up with 28 frames, out of which 27 are readable by opencv. More specifically :

    &#xA;

    ffprobe -v error -select_streams v:0 -count_packets  -show_entries stream=nb_read_packets -of csv=p=0 tmp.ts &#xA;

    &#xA;

    returns 30.

    &#xA;

    ffprobe -v error -select_streams v:0 -count_packets     -show_entries stream=nb_read_packets -of csv=p=0 tmp.mp4&#xA;

    &#xA;

    returns 28.

    &#xA;

    Using OpenCV in that manner

    &#xA;

    cap = cv2.VideoCapture(tmp_path)&#xA;readMat = []&#xA;while cap.isOpened():&#xA;        ret, frame = cap.read()&#xA;        if not ret:&#xA;            break&#xA;        readMat.append(frame)&#xA;

    &#xA;

    I get for the ts file 30 frames, while for the mp4 27 frames.

    &#xA;

    Could someone explain why the discrepancies ? I get no error during the transformation from ts to mp4 :

    &#xA;

    ffmpeg version N-111746-gd53acf452f Copyright (c) 2000-2023 the FFmpeg developers&#xA;  built with gcc 11.3.0 (GCC)&#xA;  configuration: --ld=g&#x2B;&#x2B; --bindir=/bin --extra-libs=&#x27;-lpthread -lm&#x27; --pkg-config-flags=--static --enable-static --enable-gpl --enable-libaom --enable-libass --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libsvtav1 --enable-libdav1d --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree --enable-cuda-nvcc --enable-cuvid --enable-nvenc --enable-libnpp &#xA;  libavutil      58. 16.101 / 58. 16.101&#xA;  libavcodec     60. 23.100 / 60. 23.100&#xA;  libavformat    60. 10.100 / 60. 10.100&#xA;  libavdevice    60.  2.101 / 60.  2.101&#xA;  libavfilter     9. 10.100 /  9. 10.100&#xA;  libswscale      7.  3.100 /  7.  3.100&#xA;  libswresample   4. 11.100 /  4. 11.100&#xA;  libpostproc    57.  2.100 / 57.  2.100&#xA;[mpegts @ 0x4237240] DTS discontinuity in stream 0: packet 5 with DTS 306003, packet 6 with DTS 396001&#xA;Input #0, mpegts, from &#x27;tmp.ts&#x27;:&#xA;  Duration: 00:00:21.33, start: 3.400000, bitrate: 15 kb/s&#xA;  Program 1 &#xA;    Metadata:&#xA;      service_name    : Service01&#xA;      service_provider: FFmpeg&#xA;  Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 300x300, 1 fps, 3 tbr, 90k tbn&#xA;Output #0, mp4, to &#x27;test.mp4&#x27;:&#xA;  Metadata:&#xA;    encoder         : Lavf60.10.100&#xA;  Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 300x300, q=2-31, 1 fps, 3 tbr, 90k tbn&#xA;Stream mapping:&#xA;  Stream #0:0 -> #0:0 (copy)&#xA;Press [q] to stop, [?] for help&#xA;[out#0/mp4 @ 0x423e280] video:25kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 4.192123%&#xA;frame=   30 fps=0.0 q=-1.0 Lsize=      26kB time=00:00:21.00 bitrate=  10.3kbits/s speed=1e&#x2B;04x &#xA;

    &#xA;

    Additional information

    &#xA;

    The origin of the video I am processing comes from a continuous stitching operation of still images ts videos, produced by this class update method :

    &#xA;

    import cv2&#xA;import os&#xA;import subprocess&#xA;from tempfile import NamedTemporaryFile&#xA;class VideoUpdater:&#xA;    def __init__(&#xA;        self, video_path: str, framerate: int, timePerFrame: Optional[int] = None&#xA;    ):&#xA;        """&#xA;        Video updater takes in a video path, and updates it using a supplied frame, based on a given framerate.&#xA;        Args:&#xA;            video_path: str: Specify the path to the video file&#xA;            framerate: int: Set the frame rate of the video&#xA;        """&#xA;        if not video_path.endswith(".mp4"):&#xA;            LOGGER.warning(&#xA;                f"File type {os.path.splitext(video_path)[1]} not supported for streaming, switching to ts"&#xA;            )&#xA;            video_path = os.path.splitext(video_path)[0] &#x2B; ".mp4"&#xA;&#xA;        self._ps = None&#xA;        self.env = {&#xA;            &#xA;        }&#xA;        self.ffmpeg = "/usr/bin/ffmpeg "&#xA;&#xA;        self.video_path = video_path&#xA;        self.ts_path = video_path.replace(".mp4", ".ts")&#xA;        self.tfile = None&#xA;        self.framerate = framerate&#xA;        self._video = None&#xA;        self.last_frame = None&#xA;        self.curr_frame = None&#xA;&#xA;&#xA;    def update(self, frame: np.ndarray):&#xA;        if len(frame.shape) == 2:&#xA;            frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR)&#xA;        else:&#xA;            frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)&#xA;        self.writeFrame(frame)&#xA;&#xA;    def writeFrame(self, frame: np.ndarray):&#xA;        """&#xA;        The writeFrame function takes a frame and writes it to the video file.&#xA;        Args:&#xA;            frame: np.ndarray: Write the frame to a temporary file&#xA;        """&#xA;&#xA;&#xA;        tImLFrame = NamedTemporaryFile(suffix=".png")&#xA;        tVidLFrame = NamedTemporaryFile(suffix=".ts")&#xA;&#xA;        cv2.imwrite(tImLFrame.name, frame)&#xA;        ps = subprocess.Popen(&#xA;            self.ffmpeg&#xA;            &#x2B; rf"-loop 1 -r {self.framerate} -i {tImLFrame.name} -t {self.framerate} -vcodec libx264 -pix_fmt yuv420p -y {tVidLFrame.name}",&#xA;            env=self.env,&#xA;            shell=True,&#xA;            stdout=subprocess.PIPE,&#xA;            stderr=subprocess.PIPE,&#xA;        )&#xA;        ps.communicate()&#xA;        if os.path.isfile(self.ts_path):&#xA;            # this does not work to watch, as timestamps are not updated&#xA;            ps = subprocess.Popen(&#xA;                self.ffmpeg&#xA;                &#x2B; rf&#x27;-i "concat:{self.ts_path}|{tVidLFrame.name}" -c copy -y {self.ts_path.replace(".ts", ".bak.ts")}&#x27;,&#xA;                env=self.env,&#xA;                shell=True,&#xA;                stdout=subprocess.PIPE,&#xA;                stderr=subprocess.PIPE,&#xA;            )&#xA;            ps.communicate()&#xA;            shutil.move(self.ts_path.replace(".ts", ".bak.ts"), self.ts_path)&#xA;&#xA;        else:&#xA;            shutil.copyfile(tVidLFrame.name, self.ts_path)&#xA;        # fixing timestamps, we dont have to wait for this operation&#xA;        ps = subprocess.Popen(&#xA;            self.ffmpeg&#xA;            &#x2B; rf"-i {self.ts_path} -fflags &#x2B;genpts -c copy -y {self.video_path}",&#xA;            env=self.env,&#xA;            shell=True,&#xA;            # stdout=subprocess.PIPE,&#xA;            # stderr=subprocess.PIPE,&#xA;        )&#xA;        tImLFrame.close()&#xA;        tVidLFrame.close()&#xA;

    &#xA;