Recherche avancée

Médias (0)

Mot : - Tags -/utilisateurs

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

Autres articles (69)

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

  • Support audio et vidéo HTML5

    10 avril 2011

    MediaSPIP utilise les balises HTML5 video et audio pour la lecture de documents multimedia en profitant des dernières innovations du W3C supportées par les navigateurs modernes.
    Pour les navigateurs plus anciens, le lecteur flash Flowplayer est utilisé.
    Le lecteur HTML5 utilisé a été spécifiquement créé pour MediaSPIP : il est complètement modifiable graphiquement pour correspondre à un thème choisi.
    Ces technologies permettent de distribuer vidéo et son à la fois sur des ordinateurs conventionnels (...)

  • De l’upload à la vidéo finale [version standalone]

    31 janvier 2010, par

    Le chemin d’un document audio ou vidéo dans SPIPMotion est divisé en trois étapes distinctes.
    Upload et récupération d’informations de la vidéo source
    Dans un premier temps, il est nécessaire de créer un article SPIP et de lui joindre le document vidéo "source".
    Au moment où ce document est joint à l’article, deux actions supplémentaires au comportement normal sont exécutées : La récupération des informations techniques des flux audio et video du fichier ; La génération d’une vignette : extraction d’une (...)

Sur d’autres sites (11142)

  • FFmpeg with Nvidia GPU - full HW transcode with 50i to 50p deinterlacing

    5 janvier 2018, par Jernej Stopinšek

    I’m trying to do a full hardware transcode of an udp stream to hls
    with 50i to 50p deinterlacing.

    I’m using ffmpeg and Nvidia GPU.

    Since HLS requires deinterlacing

    https://developer.apple.com/library/content/documentation/General/Reference/HLSAuthoringSpec/Requirements.html

    I would like to deinterlace an interlaced source stream and preserve
    as much smooth motion and picture quality as possible.

    My hardware, software and driver info :

    GPU : Tesla P100-PCIE-12GB
    Nvidia Driver Version : 387.26
    Cuda compilation tools, release 9.1, V9.1.85
    FFmpeg from git on 20171218

    ffmpeg version N-89520-g3f88744067 Copyright (c) 2000-2017 the FFmpeg
    developers built with gcc 6.3.0 (Debian 6.3.0-18) 20170516
    configuration : —enable-gpl
    —enable-cuda-sdk —enable-libx264 —enable-libx265 —enable-nonfree —enable-libnpp —enable-opengl —enable-opencl —enable-libfreetype —enable-openssl —enable-libzvbi —enable-libfontconfig —enable-libfreetype —enable-libfribidi —extra-cflags=-I/usr/local/cuda/include —extra-ldflags=-L/usr/local/cuda/lib64 —arch=x86_64

    libavutil 56. 6.100 / 56. 6.100
    libavcodec 58. 8.100 / 58.
    8.100
    libavformat 58. 3.100 / 58. 3.100
    libavdevice 58. 0.100 / 58. 0.100
    libavfilter 7. 7.100 / 7. 7.100
    libswscale 5.
    0.101 / 5. 0.101
    libswresample 3. 0.101 / 3. 0.101
    libpostproc 55. 0.100 / 55. 0.100

    Input stream info :

    ffmpeg -t 00:05:00 -i udp://xxx.xxx.xxx.xxx:xxxx -map 0:0 -vf idet -c rawvideo -y -f rawvideo /dev/null

    Input #0, mpegts, from ’udp ://xxx.xxx.xxx.xxx:xxxx’ :
    Duration :
    N/A, start : 49634.159411, bitrate : N/A
    Program xxxxx
    Metadata : service_name :
    service_provider : Stream
    #0:0[0x44d] : Video : h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, top first), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 50 tbr, 90k
    tbn, 50 tbc
    Stream #0:10x19de : Audio : mp2 ([3][0][0][0] /
    0x0003), 48000 Hz, stereo, s16p, 192 kb/s
    Stream
    #0:20x19e1 : Subtitle : dvb_subtitle ([6][0][0][0] / 0x0006)

    Output #0, rawvideo, to ’/dev/null’ :
    Metadata :
    encoder :
    Lavf58.3.100
    Stream #0:0 : Video : rawvideo (I420 / 0x30323449),
    yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 622080 kb/s, 25 fps, 25
    tbn, 25 tbc
    Metadata :
    encoder : Lavc58.8.100 rawvideo
    frame= 7538 fps= 25 q=-0.0 Lsize=22896675kB time=00:05:01.52
    bitrate=622080.0kbits/s dup=38 drop=0 speed=1.02x
    video:22896675kB audio:0kB subtitle:0kB other streams:0kB global
    headers:0kB muxing overhead : 0.000000%
    [Parsed_idet_0 @
    0x56370b3c5080] Repeated Fields : Neither : 7458 Top : 24 Bottom : 18
    [Parsed_idet_0 @ 0x56370b3c5080] Single frame detection : TFF : 281 BFF :
    13 Progressive : 5639 Undetermined : 1567
    [Parsed_idet_0 @
    0x56370b3c5080] Multi frame detection : TFF : 380 BFF : 0 Progressive :
    7120 Undetermined : 0


    This is my command for adaptive hardware deinterlacing. It gives great results with picture, but sound is out of sync.

    ffmpeg -y -err_detect ignore_err -loglevel debug -vsync -1 -hwaccel cuvid -hwaccel_device 1 -c:v h264_cuvid -deint adaptive -r:v 50 -gpu:v 1 -i "udp://xxx.xxx.xxx.xxx:xxxx=?overrun_nonfatal=1&fifo_size=84450&buffer_size=33554432" -map 0:0 -map 0:1 -c:a aac -b:a 196k -c:v h264_nvenc -flags -global_header+cgop -gpu:v 1 -g:v 50 -bf:v 4 -coder:v cabac -b_adapt:v false -b:v 5184000 -minrate:v 5184000 -maxrate:v 5184000 -bufsize:v 2488320 -rc:v cbr_hq -2pass:v true -rc-lookahead:v 25 -no-scenecut:v 1 -profile:v high -preset:v slow -color_range:v 1 -color_trc:v 1 -color_primaries:v 1 -colorspace:v 1 -f hls -hls_time 5 -hls_list_size 3 -start_number 0 -hls_flags delete_segments /srv/hls/program_01/1080p/index.m3u8

    If I add option "-drop_second_field 1" to h264_cuvid and remove -r:v 50 from input and put it to h264_nvenc - then transcoded stream has synced audio, but I think I’m losing quality due to drop_second_field option.

    ffmpeg -y -err_detect ignore_err -loglevel debug -vsync -1 -hwaccel cuvid -hwaccel_device 1 -c:v h264_cuvid -deint adaptive -drop_second_field 1 -gpu:v 1 -i "udp://xxx.xxx.xxx.xxx:xxxx=?overrun_nonfatal=1&fifo_size=84450&buffer_size=33554432" -map 0:0 -map 0:1 -c:a aac -b:a 196k -c:v h264_nvenc -flags -global_header+cgop -gpu:v 1 -g:v 50 -r:v 50 -bf:v 4 -coder:v cabac -b_adapt:v false -b:v 5184000 -minrate:v 5184000 -maxrate:v 5184000 -bufsize:v 2488320 -rc:v cbr_hq -2pass:v true -rc-lookahead:v 25 -no-scenecut:v 1 -profile:v high -preset:v slow -color_range:v 1 -color_trc:v 1 -color_primaries:v 1 -colorspace:v 1 -f hls -hls_time 5 -hls_list_size 3 -start_number 0 -hls_flags delete_segments /srv/hls/program_01/1080p/index.m3u8

    Could someone please point me in the right direction how to properly deinterlace with cuvid and minimal possible loss of quality ?

  • ffmpeg capture from ip camera video in h264 stream [closed]

    23 mars 2023, par Иванов Иван

    I can't read the frames from the camera and then write them to a video file (any). The fact is that I even get crooked frames, they seem to have violated the coordinates of the position of each point, the video is crooked, distorted

    


    c++ code.

    


    https://drive.google.com/file/d/1W2sZMR5D5pvVmnhiQyhiaQhC9frhdeII/view?usp=sharing

    


     #define INBUF_SIZE 4096&#xA;&#xA;&#xA;    //writing the minimal required header for a pgm file format&#xA;    //portable graymap format-> https://en.wikipedia.org/wiki/Netpbm_format#PGM_example&#xA;    fprintf (f, "P5\n%d %d\n%d\n", xsize, ysize, 255);&#xA;&#xA;    //writing line by line&#xA;    for (i = 0; i /contains data on a configuration of media content, such as bitrate, &#xA;        //frame rate, sampling frequency, channels, height and many other things.&#xA;        AVCodecContext * AVCodecContext_ = NULL;&#xA;        AVCodecParameters * AVCodecParametr_ = NULL;&#xA;        FILE * f;&#xA;        //This structure describes decoded (raw) audio- or video this.&#xA;        AVFrame * frame;&#xA;        uint8_t inbuf [INBUF_SIZE &#x2B; AV_INPUT_BUFFER_PADDING_SIZE];&#xA;        uint8_t * data;&#xA;        size_t data_size;&#xA;        int ret;&#xA;        int eof;&#xA;        AVFormatContext * AVfc = NULL;&#xA;        int ERRORS;&#xA;        //AVCodec * codec;&#xA;        char buf [1024];&#xA;        const char * FileName;&#xA;    &#xA;        //https://habr.com/ru/post/137793/&#xA;        //Stores the compressed one shot.&#xA;        AVPacket * pkt;&#xA;    &#xA;        //**********************************************************************&#xA;        //Beginning of reading video from the camera. &#xA;        //**********************************************************************&#xA;    &#xA;        avdevice_register_all ();&#xA;    &#xA;        filename = "rtsp://admin: 754HG@192.168.1.75:554/11";&#xA;        //filename = "c:\\1.avi";&#xA;        outfilename = "C:\\2.MP4";&#xA;    &#xA;        //We open a flow of video (it is the file or the camera). &#xA;        ERRORS = avformat_open_input (&amp; AVfc, filename, NULL, NULL);&#xA;        if (ERRORS &lt;0) {&#xA;            fprintf (stderr, "ffmpeg: could not open file \n");&#xA;            return-1;&#xA;        }&#xA;    &#xA;        //After opening, we can print out information on the video file (iformat = the name of a format; &#xA;        //duration = duration). But as I connected the camera to me wrote: Duration: N/A, &#xA;        //start: 0.000000, bitrate: N/A&#xA;        printf ("Format %s, duration %lld us", AVfc-> iformat-> long_name, AVfc-> duration);&#xA;    &#xA;    &#xA;        ERRORS = avformat_find_stream_info (AVfc, NULL);&#xA;        if (ERRORS &lt;0) {&#xA;            fprintf (stderr, "ffmpeg: Unable to find stream info\n");&#xA;            return-1;&#xA;        }&#xA;    &#xA;    &#xA;        int CountStream;&#xA;    &#xA;        //We learn quantity of streams. &#xA;        CountStream = AVfc-> nb_streams;&#xA;    &#xA;        //Let&#x27;s look for the codec. &#xA;        int video_stream;&#xA;        for (video_stream = 0; video_stream  nb_streams; &#x2B;&#x2B; video_stream) {&#xA;            if (AVfc-> streams[video_stream]-> codecpar-> codec_type == AVMEDIA_TYPE_VIDEO) {&#xA;                break;&#xA;            }&#xA;    &#xA;        }&#xA;    &#xA;        if (video_stream == AVfc-> nb_streams) {&#xA;            fprintf (stderr, "ffmpeg: Unable to find video stream\n");&#xA;            return-1;&#xA;        }&#xA;    &#xA;        //Here we define a type of the codec, for my camera it is equal as AV_CODEC_ID_HEVC (This that in what is broadcast by my camera)&#xA;        codec = avcodec_find_decoder(AVfc-> streams [video_stream]-> codecpar-> codec_id);&#xA;        //--------------------------------------------------------------------------------------&#xA;    &#xA;        //Functions for inquiry of opportunities of libavcodec,&#xA;        AVCodecContext_ = avcodec_alloc_context3(codec);&#xA;        if (! AVCodecContext _) {&#xA;            fprintf (stderr, "Was not succeeded to allocate a video codec context, since it not poddrerzhivayetsya\n");&#xA;            exit(1);&#xA;        }&#xA;    &#xA;        //This function is used for initialization &#xA;        //AVCodecContext of video and audio of the codec. The announcement of avcodec_open2 () is in libavcodecavcodec.h&#xA;        //We open the codec. &#xA;    &#xA;        ERRORS = avcodec_open2 (AVCodecContext _, codec, NULL);&#xA;        if (ERRORS &lt;0) {&#xA;            fprintf (stderr, "ffmpeg: It is not possible to open codec \n");&#xA;            return-1;&#xA;        }&#xA;    &#xA;        //It for processing of a sound - a reserve.&#xA;        //swr_alloc_set_opts ()&#xA;        //swr_init (); &#xA;    &#xA;        //To output all information on the video file. &#xA;        av_dump_format (AVfc, 0, argv[1], 0);&#xA;    &#xA;        //=========================================================================================&#xA;        //Further, we receive frames. before we only received all infomration about the entering video.&#xA;        //=========================================================================================&#xA;    &#xA;        //Now we are going to read packages from a stream and to decode them in shots, but at first &#xA;        //we need to mark out memory for both components (AVPacket and AVFrame).&#xA;        frame = av_frame_alloc ();&#xA;    &#xA;        if (! frame) {&#xA;            fprintf (stderr, "Is not possible to mark out memory for video footage \n");&#xA;            exit(1);&#xA;        }&#xA;        //We mark out memory for a package &#xA;        pkt = av_packet_alloc ();&#xA;        //We define a file name for saving the picture.&#xA;        const char * FileName1 = "C:\\Users\\Павел\\Desktop\\NyFile.PGM";&#xA;        //Data reading if they is. &#xA;        while (av_read_frame (AVfc, pkt)> = 0) {&#xA;            //It is a package from a video stream? Because there is still a soundtrack.&#xA;            if (pkt-> stream_index == video_stream) {&#xA;                int ret;&#xA;    &#xA;                //Transfer of the raw package data as input data in the decoder&#xA;                ret = avcodec_send_packet (AVCodecContext _, pkt);&#xA;                if (ret &lt;0 | | ret == AVERROR(EAGAIN) | | ret == AVERROR_EOF) {&#xA;                    std:: cout &lt;&lt;"avcodec_send_packet:" &lt;<ret while="while"> = 0) {&#xA;    &#xA;                    //Returns the decoded output data from the decoder or the encoder&#xA;                    ret = avcodec_receive_frame (AVCodecContext _, frame);&#xA;                    if (ret == AVERROR(EAGAIN) | | ret == AVERROR_EOF) {&#xA;                        //std:: cout &lt;&lt;"avcodec_receive_frame:" &lt;<ret cout="cout"> of frame_number &lt;/============================================================================================&#xA;    &#xA;                    //Experimentally - we will keep a shot in the picture. &#xA;    &#xA;                    save_gray_frame(frame-> data [0], frame-> linesize [0], frame-> width, frame-> height, (char *) FileName1);&#xA;                }&#xA;            }&#xA;        }&#xA;    &#xA;        //av_parser_close(parser);&#xA;        avcodec_free_context (&amp; AVCodecContext _);&#xA;        av_frame_free (&amp; frame);&#xA;        av_packet_free (&amp; pkt);&#xA;    &#xA;        return 0;&#xA;</ret></ret>

    &#xA;

  • ffmpeg-next potential bug in write_header causes timebase to bet set to Rational(1/15360)

    7 septembre 2024, par Huhngut

    I am trying to encode a video using the ffmpeg_next crate. I got everything working and it successfully creates an output video.&#xA;The only problem is that the time_base of my stream is wrongly written to the file.&#xA;I can confirm that I set the timebase correctly for both the encoder as well as the stream.

    &#xA;

    By debug prints I was able to narrow the problem down. octx.write_header().unwrap(); causes the stream timebase to be reset from Rational(1/30) to Rational(1/15360). Changing the timebase back afterwards has no effect. The wrong value must have been written to the header.

    &#xA;

    I modified the src code of ffmpeg-next and recompiled it. I can confirm that the correct value is set before the call to avformat_write_header

    &#xA;

    pub fn write_header(&amp;mut self) -> Result&lt;(), Error> {&#xA;        println!(&#xA;            "_________________ {:?}",&#xA;            self.stream(0).unwrap().time_base()&#xA;        );&#xA;        unsafe {&#xA;            match avformat_write_header(self.as_mut_ptr(), ptr::null_mut()) {&#xA;                0 => Ok(()),&#xA;                e => Err(Error::from(e)),&#xA;            }&#xA;        }&#xA;    }&#xA;

    &#xA;

    To my understanding this must be a bug in the crate but I dont want to accuse someone with my non existing knowledge about ffmpeg. Also the examples in the github repo seem not to have this problem. My fault then ? Unfortunately I was not able to get the transcode-x264 to run. Most of my code comes from this example.

    &#xA;

    Relevant code bits are these. I dont know how much the set_parameters influences anything. My testing said it has no influence. I also tried to set the timebase at the very end of the function if it gets reset my the parameters. This is not working

    &#xA;

    let mut ost = octx.add_stream(codec)?;&#xA;ost.set_time_base(Rational::new(1, FPS));&#xA;&#xA;ost.set_parameters(&amp;encoder);&#xA;encoder.set_time_base(Rational::new(1, FPS));&#xA;ost.set_parameters(&amp;opened_encoder);&#xA;

    &#xA;

    By default and in the above example the streams timebase is 0/0. If I leave it out or change it to this manually it has no effect.

    &#xA;

    I also noticed that changing the value inside set_pts influences the output fps. Although not the timebase. I think this is more of a sideeffect.

    &#xA;

    I will leave a minimal reproducible example below. Any help or hints would be appreciated

    &#xA;

    abstract main function

    &#xA;

    fn main() {&#xA;    let output_file = "output.mp4";&#xA;    let x264_opts = parse_opts("preset=medium".to_string()).expect("invalid x264 options string");&#xA;&#xA;    ffmpeg_next::init().unwrap();&#xA;    let mut octx = format::output(output_file).unwrap();&#xA;&#xA;    let mut encoder = Encoder::new(&amp;mut octx, x264_opts).unwrap();&#xA;&#xA;    format::context::output::dump(&amp;octx, 0, Some(&amp;output_file));&#xA;    //This line somehow clears the streams time base&#xA;    octx.write_header().unwrap();&#xA;&#xA;    // Without this line, the next logs returns Rational(1/30) Rational(1/15360) indicating streams timebase is wrong. even thought I set it above&#xA;    // this line changes it back but only for the print but not the actual output. Because the faulty data is written into the header&#xA;    // octx.stream_mut(0)&#xA;    //     .unwrap()&#xA;    //     .set_time_base(Rational::new(1, FPS));&#xA;&#xA;    println!(&#xA;        "---------------- {:?} {:?}",&#xA;        encoder.encoder.time_base(),&#xA;        octx.stream(0).unwrap().time_base(),&#xA;    );&#xA;&#xA;    for frame_num in 0..100 {&#xA;        let mut frame = encoder.create_frame();&#xA;        frame.set_pts(Some(frame_num));&#xA;        encoder.add_frame(&amp;frame, &amp;mut octx);&#xA;    }&#xA;&#xA;    encoder.close(&amp;mut octx);&#xA;    octx.write_trailer().unwrap();&#xA;}&#xA;

    &#xA;

    Encoder struct containing the implementation logic

    &#xA;

    struct Encoder {&#xA;    encoder: encoder::Video,&#xA;}&#xA;&#xA;impl Encoder {&#xA;    fn new(&#xA;        octx: &amp;mut format::context::Output,&#xA;        x264_opts: Dictionary,&#xA;    ) -> Result {&#xA;        let set_header = octx&#xA;            .format()&#xA;            .flags()&#xA;            .contains(ffmpeg_next::format::flag::Flags::GLOBAL_HEADER);&#xA;&#xA;        let codec = encoder::find(codec::Id::H264);&#xA;        let mut ost = octx.add_stream(codec)?;&#xA;        ost.set_time_base(Rational::new(1, FPS));&#xA;&#xA;        let mut encoder = codec::context::Context::new_with_codec(&#xA;            encoder::find(codec::Id::H264)&#xA;                .ok_or(ffmpeg_next::Error::InvalidData)&#xA;                .unwrap(),&#xA;        )&#xA;        .encoder()&#xA;        .video()&#xA;        .unwrap();&#xA;        ost.set_parameters(&amp;encoder);&#xA;&#xA;        encoder.set_width(WIDTH);&#xA;        encoder.set_height(HEIGHT);&#xA;        encoder.set_aspect_ratio(WIDTH as f64 / HEIGHT as f64);&#xA;        encoder.set_format(util::format::Pixel::YUV420P);&#xA;        encoder.set_frame_rate(Some(Rational::new(FPS, 1)));&#xA;        encoder.set_time_base(Rational::new(1, FPS));&#xA;&#xA;        if set_header {&#xA;            encoder.set_flags(ffmpeg_next::codec::flag::Flags::GLOBAL_HEADER);&#xA;        }&#xA;&#xA;        let opened_encoder = encoder&#xA;            .open_with(x264_opts.to_owned())&#xA;            .expect("error opening x264 with supplied settings");&#xA;        ost.set_parameters(&amp;opened_encoder);&#xA;&#xA;        println!(&#xA;            "\nost time_base: {}; encoder time_base: {}; encoder frame_rate: {}\n",&#xA;            ost.time_base(),&#xA;            &amp;opened_encoder.time_base(),&#xA;            &amp;opened_encoder.frame_rate()&#xA;        );&#xA;&#xA;        Ok(Self {&#xA;            encoder: opened_encoder,&#xA;        })&#xA;    }&#xA;&#xA;    fn add_frame(&amp;mut self, frame: &amp;frame::Video, octx: &amp;mut format::context::Output) {&#xA;        self.encoder.send_frame(frame).unwrap();&#xA;        self.process_packets(octx);&#xA;    }&#xA;&#xA;    fn close(&amp;mut self, octx: &amp;mut format::context::Output) {&#xA;        self.encoder.send_eof().unwrap();&#xA;        self.process_packets(octx);&#xA;    }&#xA;&#xA;    fn process_packets(&amp;mut self, octx: &amp;mut format::context::Output) {&#xA;        let mut encoded = Packet::empty();&#xA;        while self.encoder.receive_packet(&amp;mut encoded).is_ok() {&#xA;            encoded.set_stream(0);&#xA;            encoded.write_interleaved(octx).unwrap();&#xA;        }&#xA;    }&#xA;&#xA;    fn create_frame(&amp;self) -> frame::Video {&#xA;        return frame::Video::new(&#xA;            self.encoder.format(),&#xA;            self.encoder.width(),&#xA;            self.encoder.height(),&#xA;        );&#xA;    }&#xA;}&#xA;

    &#xA;

    other util stuff

    &#xA;

    use ffmpeg_next::{&#xA;    codec::{self},&#xA;    encoder, format, frame, util, Dictionary, Packet, Rational,&#xA;};&#xA;&#xA;const FPS: i32 = 30;&#xA;const WIDTH: u32 = 720;&#xA;const HEIGHT: u32 = 1080;&#xA;&#xA;fn parse_opts&lt;&#x27;a>(s: String) -> Option> {&#xA;    let mut dict = Dictionary::new();&#xA;    for keyval in s.split_terminator(&#x27;,&#x27;) {&#xA;        let tokens: Vec&lt;&amp;str> = keyval.split(&#x27;=&#x27;).collect();&#xA;        match tokens[..] {&#xA;            [key, val] => dict.set(key, val),&#xA;            _ => return None,&#xA;        }&#xA;    }&#xA;    Some(dict)&#xA;}&#xA;

    &#xA;