Recherche avancée

Médias (91)

Autres articles (38)

  • MediaSPIP Core : La Configuration

    9 novembre 2010, par

    MediaSPIP Core fournit par défaut trois pages différentes de configuration (ces pages utilisent le plugin de configuration CFG pour fonctionner) : une page spécifique à la configuration générale du squelettes ; une page spécifique à la configuration de la page d’accueil du site ; une page spécifique à la configuration des secteurs ;
    Il fournit également une page supplémentaire qui n’apparait que lorsque certains plugins sont activés permettant de contrôler l’affichage et les fonctionnalités spécifiques (...)

  • Encodage et transformation en formats lisibles sur Internet

    10 avril 2011

    MediaSPIP transforme et ré-encode les documents mis en ligne afin de les rendre lisibles sur Internet et automatiquement utilisables sans intervention du créateur de contenu.
    Les vidéos sont automatiquement encodées dans les formats supportés par HTML5 : MP4, Ogv et WebM. La version "MP4" est également utilisée pour le lecteur flash de secours nécessaire aux anciens navigateurs.
    Les documents audios sont également ré-encodés dans les deux formats utilisables par HTML5 :MP3 et Ogg. La version "MP3" (...)

  • Support de tous types de médias

    10 avril 2011

    Contrairement à beaucoup de logiciels et autres plate-formes modernes de partage de documents, MediaSPIP a l’ambition de gérer un maximum de formats de documents différents qu’ils soient de type : images (png, gif, jpg, bmp et autres...) ; audio (MP3, Ogg, Wav et autres...) ; vidéo (Avi, MP4, Ogv, mpg, mov, wmv et autres...) ; contenu textuel, code ou autres (open office, microsoft office (tableur, présentation), web (html, css), LaTeX, Google Earth) (...)

Sur d’autres sites (4972)

  • Revision 37301 : une image qui n’est plus nécessaire

    15 avril 2010, par kent1@… — Log

    une image qui n’est plus nécessaire

  • FFMpeg CUDA yuvj420p frame conversion to cv::Mat layers shifted

    26 février 2023, par AcidTonic

    I am trying to retrieve hardware decoded H264 frames from the cuda backend of ffmpeg and display them as a cv::Mat. I got decently far and was able to get color images but it seems the conversion is not quite right as the image I get has a green bar at the top and if you look closely the blue parts of the image are offset down and to the right a little bit making everything look a little wonky.

    


    Correct Image as shown by ffplay using the same driver
enter image description here
Image I am getting
enter image description here

    


    Here is the full source code in the hopes someone can help me to get the correct image here...

    


    #include &#xA;&#xA;#include &#xA;&#xA;#include &#xA;&#xA;#include &#xA;&#xA;#include &#xA;&#xA;#include &#xA;&#xA;#include <iostream>&#xA;&#xA;#include <fstream>&#xA;&#xA;#include <cstdlib>&#xA;&#xA;#include <chrono>&#xA;&#xA;#include <cstring>&#xA;&#xA;extern "C" {&#xA;&#xA;  //Linker errors if not inside extern. FFMPEG headers are not C&#x2B;&#x2B; aware&#xA;  #include <libavcodec></libavcodec>avcodec.h>&#xA;&#xA;  #include <libavformat></libavformat>avformat.h>&#xA;&#xA;  #include <libavutil></libavutil>pixdesc.h>&#xA;&#xA;  #include <libavutil></libavutil>hwcontext.h>&#xA;&#xA;  #include <libavutil></libavutil>opt.h>&#xA;&#xA;  #include <libavutil></libavutil>avassert.h>&#xA;&#xA;  #include <libavutil></libavutil>imgutils.h>&#xA;&#xA;}&#xA;&#xA;#include <iomanip>&#xA;&#xA;#include <string>&#xA;&#xA;#include <sstream>&#xA;&#xA;#include <opencv2></opencv2>opencv.hpp>&#xA;&#xA;#ifdef __cplusplus&#xA;extern "C" {&#xA;  #endif // __cplusplus&#xA;  #include <libavdevice></libavdevice>avdevice.h>&#xA;&#xA;  #include <libavfilter></libavfilter>avfilter.h>&#xA;&#xA;  #include <libavformat></libavformat>avio.h>&#xA;&#xA;  #include <libavutil></libavutil>avutil.h>&#xA;&#xA;  #include <libpostproc></libpostproc>postprocess.h>&#xA;&#xA;  #include <libswresample></libswresample>swresample.h>&#xA;&#xA;  #include <libswscale></libswscale>swscale.h>&#xA;&#xA;  #ifdef __cplusplus&#xA;} // end extern "C".&#xA;#endif // __cplusplus&#xA;&#xA;static AVBufferRef * hw_device_ctx = NULL;&#xA;static enum AVPixelFormat hw_pix_fmt;&#xA;static FILE * output_file_fd = NULL;&#xA;cv::Mat output_mat;&#xA;int bgr_size;&#xA;&#xA;static int hw_decoder_init(AVCodecContext * ctx,&#xA;  const enum AVHWDeviceType type) {&#xA;  int err = 0;&#xA;&#xA;  if ((err = av_hwdevice_ctx_create( &amp; hw_device_ctx, type,&#xA;      NULL, NULL, 0)) &lt; 0) {&#xA;    fprintf(stderr, "Failed to create specified HW device.\n");&#xA;    return err;&#xA;  }&#xA;  ctx -> hw_device_ctx = av_buffer_ref(hw_device_ctx);&#xA;&#xA;  return err;&#xA;}&#xA;&#xA;static enum AVPixelFormat get_hw_format(AVCodecContext * ctx,&#xA;  const enum AVPixelFormat * pix_fmts) {&#xA;  const enum AVPixelFormat * p;&#xA;&#xA;  for (p = pix_fmts;* p != -1; p&#x2B;&#x2B;) {&#xA;    if ( * p == hw_pix_fmt)&#xA;      return * p;&#xA;  }&#xA;&#xA;  fprintf(stderr, "Failed to get HW surface format.\n");&#xA;  return AV_PIX_FMT_NONE;&#xA;}&#xA;&#xA;static int decode_write(AVCodecContext * avctx, AVPacket * packet) {&#xA;  AVFrame * frame = NULL, * sw_frame = NULL;&#xA;  AVFrame * tmp_frame = NULL;&#xA;  uint8_t * buffer = NULL;&#xA;  int size;&#xA;  int ret = 0;&#xA;&#xA;  ret = avcodec_send_packet(avctx, packet);&#xA;  if (ret &lt; 0) {&#xA;    fprintf(stderr, "Error during decoding\n");&#xA;    return ret;&#xA;  }&#xA;&#xA;  while (1) {&#xA;    if (!(frame = av_frame_alloc()) || !(sw_frame = av_frame_alloc())) {&#xA;      fprintf(stderr, "Can not alloc frame\n");&#xA;      ret = AVERROR(ENOMEM);&#xA;      av_frame_free( &amp; frame);&#xA;      av_frame_free( &amp; sw_frame);&#xA;      av_freep( &amp; buffer);&#xA;      if (ret &lt; 0) {&#xA;        return ret;&#xA;      }&#xA;&#xA;    }&#xA;&#xA;    ret = avcodec_receive_frame(avctx, frame);&#xA;    if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {&#xA;      av_frame_free( &amp; frame);&#xA;      av_frame_free( &amp; sw_frame);&#xA;      return 0;&#xA;    } else if (ret &lt; 0) {&#xA;      fprintf(stderr, "Error while decoding\n");&#xA;      av_frame_free( &amp; frame);&#xA;      av_frame_free( &amp; sw_frame);&#xA;      av_freep( &amp; buffer);&#xA;      if (ret &lt; 0) {&#xA;        return ret;&#xA;      }&#xA;&#xA;    }&#xA;&#xA;    if (frame -> format == hw_pix_fmt) {&#xA;      /* retrieve data from GPU to CPU */&#xA;      if ((ret = av_hwframe_transfer_data(sw_frame, frame, 0)) &lt; 0) {&#xA;        fprintf(stderr, "Error transferring the data to system memory\n");&#xA;        av_frame_free( &amp; frame);&#xA;        av_frame_free( &amp; sw_frame);&#xA;        av_freep( &amp; buffer);&#xA;        if (ret &lt; 0) {&#xA;          return ret;&#xA;        }&#xA;&#xA;      }&#xA;      tmp_frame = sw_frame;&#xA;    } else {&#xA;      tmp_frame = frame;&#xA;    }&#xA;&#xA;    AVPixelFormat format_to_use = AV_PIX_FMT_YUVJ420P;&#xA;    cv::Mat mat_src = cv::Mat(sw_frame -> height &#x2B; (sw_frame -> height / 2), sw_frame -> width, CV_8UC1, sw_frame -> data[0]);&#xA;    cv::Mat out_mat;&#xA;    cv::cvtColor(mat_src, out_mat, cv::COLOR_YUV2RGB_NV21);&#xA;&#xA;    output_mat = out_mat;&#xA;&#xA;    if (output_mat.empty() == false) {&#xA;      cv::imshow("image", output_mat);&#xA;      cv::waitKey(1);&#xA;    }&#xA;&#xA;    av_frame_free( &amp; frame);&#xA;    av_frame_free( &amp; sw_frame);&#xA;    av_freep( &amp; buffer);&#xA;    return ret;&#xA;  }&#xA;}&#xA;&#xA;TEST_CASE("CUDAH264", "Tests hardware h264 decoding") {&#xA;&#xA;  AVFormatContext * input_ctx = NULL;&#xA;  int video_stream, ret;&#xA;  AVStream * video = NULL;&#xA;  AVCodecContext * decoder_ctx = NULL;&#xA;  AVCodec * decoder = NULL;&#xA;  AVPacket * packet = NULL;&#xA;  enum AVHWDeviceType type;&#xA;  int i;&#xA;&#xA;  std::string device_type = "cuda";&#xA;  std::string input_file = "rtsp://10.100.2.152"; //My H264 network stream here...&#xA;&#xA;  /* The stream data is below...&#xA;  Input #0, rtsp, from &#x27;rtsp://10.100.2.152&#x27;:&#xA;    Metadata:&#xA;      title           : VCP IPC Realtime stream&#xA;    Duration: N/A, start: 0.000000, bitrate: N/A&#xA;    Stream #0:0: Video: h264 (High), yuvj420p(pc, bt709, progressive), 1920x1080, 10 fps, 10 tbr, 90k tbn, 20 tbc&#xA;  */&#xA;&#xA;  type = av_hwdevice_find_type_by_name(device_type.c_str());&#xA;  if (type == AV_HWDEVICE_TYPE_NONE) {&#xA;    fprintf(stderr, "Device type %s is not supported.\n", device_type.c_str());&#xA;    fprintf(stderr, "Available device types:");&#xA;    while ((type = av_hwdevice_iterate_types(type)) != AV_HWDEVICE_TYPE_NONE)&#xA;      fprintf(stderr, " %s", av_hwdevice_get_type_name(type));&#xA;    fprintf(stderr, "\n");&#xA;    throw std::runtime_error("Error");&#xA;  }&#xA;&#xA;  packet = av_packet_alloc();&#xA;  if (!packet) {&#xA;    fprintf(stderr, "Failed to allocate AVPacket\n");&#xA;    throw std::runtime_error("Error");&#xA;  }&#xA;&#xA;  /* open the input file */&#xA;  if (avformat_open_input( &amp; input_ctx, input_file.c_str(), NULL, NULL) != 0) {&#xA;    fprintf(stderr, "Cannot open input file &#x27;%s&#x27;\n", input_file.c_str());&#xA;    throw std::runtime_error("Error");&#xA;  }&#xA;&#xA;  if (avformat_find_stream_info(input_ctx, NULL) &lt; 0) {&#xA;    fprintf(stderr, "Cannot find input stream information.\n");&#xA;    throw std::runtime_error("Error");&#xA;  }&#xA;&#xA;  av_dump_format(input_ctx, 0, input_file.c_str(), 0);&#xA;&#xA;  for (int i = 0; i &lt; input_ctx -> nb_streams; i&#x2B;&#x2B;) {&#xA;    auto pCodec = avcodec_find_decoder(input_ctx -> streams[i] -> codecpar -> codec_id);&#xA;    auto pCodecCtx = avcodec_alloc_context3(pCodec);&#xA;    avcodec_parameters_to_context(pCodecCtx, input_ctx -> streams[i] -> codecpar);&#xA;&#xA;    printf("Found Video stream with ID: %d\n", input_ctx -> streams[i] -> id);&#xA;    printf("\t Stream Index: %d\n", input_ctx -> streams[i] -> index);&#xA;&#xA;    AVCodecParameters * codecpar = input_ctx -> streams[i] -> codecpar;&#xA;    printf("\t Codec Type: %s\n", av_get_media_type_string(codecpar -> codec_type));&#xA;    printf("\t Side data count: %d\n", input_ctx -> streams[i] -> nb_side_data);&#xA;    printf("\t Pixel format: %i\n", input_ctx -> streams[i] -> codecpar -> format);&#xA;    printf("\t Pixel Format Name: %s\n", av_get_pix_fmt_name((AVPixelFormat) input_ctx -> streams[i] -> codecpar -> format));&#xA;    printf("\t Metadata count: %d\n", av_dict_count(input_ctx -> streams[i] -> metadata));&#xA;  }&#xA;&#xA;  /* find the video stream information */&#xA;  ret = av_find_best_stream(input_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, &amp; decoder, 0);&#xA;  if (ret &lt; 0) {&#xA;    fprintf(stderr, "Cannot find a video stream in the input file\n");&#xA;    throw std::runtime_error("Error");&#xA;  }&#xA;&#xA;  video_stream = ret;&#xA;&#xA;  for (i = 0;; i&#x2B;&#x2B;) {&#xA;    const AVCodecHWConfig * config = avcodec_get_hw_config(decoder, i);&#xA;    if (!config) {&#xA;      fprintf(stderr, "Decoder %s does not support device type %s.\n",&#xA;        decoder -> name, av_hwdevice_get_type_name(type));&#xA;      throw std::runtime_error("Error");&#xA;    }&#xA;    if (config -> methods &amp; AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX &amp;&amp;&#xA;      config -> device_type == type) {&#xA;      hw_pix_fmt = config -> pix_fmt;&#xA;      break;&#xA;    }&#xA;  }&#xA;&#xA;  if (!(decoder_ctx = avcodec_alloc_context3(decoder))) {&#xA;    throw std::runtime_error("NO MEMORY");&#xA;  }&#xA;&#xA;  video = input_ctx -> streams[video_stream];&#xA;  if (avcodec_parameters_to_context(decoder_ctx, video -> codecpar) &lt; 0) {&#xA;    throw std::runtime_error("Error");&#xA;  }&#xA;&#xA;  decoder_ctx -> get_format = get_hw_format;&#xA;&#xA;  if (hw_decoder_init(decoder_ctx, type) &lt; 0) {&#xA;    throw std::runtime_error("Error");&#xA;  }&#xA;&#xA;  if ((ret = avcodec_open2(decoder_ctx, decoder, NULL)) &lt; 0) {&#xA;    fprintf(stderr, "Failed to open codec for stream #%u\n", video_stream);&#xA;    throw std::runtime_error("Error");&#xA;  }&#xA;&#xA;  /* actual decoding and dump the raw data */&#xA;  while (ret >= 0) {&#xA;    if ((ret = av_read_frame(input_ctx, packet)) &lt; 0)&#xA;      break;&#xA;&#xA;    if (video_stream == packet -> stream_index)&#xA;      ret = decode_write(decoder_ctx, packet);&#xA;&#xA;    av_packet_unref(packet);&#xA;  }&#xA;&#xA;  /* flush the decoder */&#xA;  ret = decode_write(decoder_ctx, NULL);&#xA;&#xA;  if (output_file_fd) {&#xA;    fclose(output_file_fd);&#xA;  }&#xA;  av_packet_free( &amp; packet);&#xA;  avcodec_free_context( &amp; decoder_ctx);&#xA;  avformat_close_input( &amp; input_ctx);&#xA;  av_buffer_unref( &amp; hw_device_ctx);&#xA;&#xA;}&#xA;</sstream></string></iomanip></cstring></chrono></cstdlib></fstream></iostream>

    &#xA;

  • The 11th Hour RoQ Variation

    12 avril 2012, par Multimedia Mike — Game Hacking, dreamroq, Reverse Engineering, roq, Vector Quantization

    I have been looking at the RoQ file format almost as long as I have been doing practical multimedia hacking. However, I have never figured out how the RoQ format works on The 11th Hour, which was the game for which the RoQ format was initially developed. When I procured the game years ago, I remember finding what appeared to be RoQ files and shoving them through the open source decoders but not getting the right images out.

    I decided to dust off that old copy of The 11th Hour and have another go at it.



    Baseline
    The game consists of 4 CD-ROMs. Each disc has a media/ directory that has a series of files bearing the extension .gjd, likely the initials of one Graeme J. Devine. These are resource files which are merely headerless concatenations of other files. Thus, at first glance, one file might appear to be a single RoQ file. So that’s the source of some of the difficulty : Sending an apparent RoQ .gjd file through a RoQ player will often cause the program to complain when it encounters the header of another RoQ file.

    I have uploaded some samples to the usual place.

    However, even the frames that a player can decode (before encountering a file boundary within the resource file) look wrong.

    Investigating Codebooks Using dreamroq
    I wrote dreamroq last year– an independent RoQ playback library targeted towards embedded systems. I aimed it at a gjd file and quickly hit a codebook error.

    RoQ is a vector quantizer video codec that maintains a codebook of 256 2×2 pixel vectors. In the Quake III and later RoQ files, these are transported using a YUV 4:2:0 colorspace– 4 Y samples, a U sample, and a V sample to represent 4 pixels. This totals 6 bytes per vector. A RoQ codebook chunk contains a field that indicates the number of 2×2 vectors as well as the number of 4×4 vectors. The latter vectors are each comprised of 4 2×2 vectors.

    Thus, the total size of a codebook chunk ought to be (# of 2×2 vectors) * 6 + (# of 4×4 vectors) * 4.

    However, this is not the case with The 11th Hour RoQ files.

    Longer Codebooks And Mystery Colorspace
    Juggling the numbers for a few of the codebook chunks, I empirically determined that the 2×2 vectors are represented by 10 bytes instead of 6. Now I need to determine what exactly these 10 bytes represent.

    I should note that I suspect that everything else about these files lines up with successive generations of the format. For example if a file has 640×320 resolution, that amounts to 40×20 macroblocks. dreamroq iterates through 40×20 8×8 blocks and precisely exhausts the VQ bitstream. So that all looks valid. I’m just puzzled on the codebook format.

    Here is an example codebook dump :

    ID 0x1002, len = 0x0000014C, args = 0x1C0D
      0 : 00 00 00 00 00 00 00 00 80 80
      1 : 08 07 00 00 1F 5B 00 00 7E 81
      2 : 00 00 15 0F 00 00 40 3B 7F 84
      3 : 00 00 00 00 3A 5F 18 13 7E 84
      4 : 00 00 00 00 3B 63 1B 17 7E 85
      5 : 18 13 00 00 3C 63 00 00 7E 88
      6 : 00 00 00 00 00 00 59 3B 7F 81
      7 : 00 00 56 23 00 00 61 2B 80 80
      8 : 00 00 2F 13 00 00 79 63 81 83
      9 : 00 00 00 00 5E 3F AC 9B 7E 81
      10 : 1B 17 00 00 B6 EF 77 AB 7E 85
      11 : 2E 43 00 00 C1 F7 75 AF 7D 88
      12 : 6A AB 28 5F B6 B3 8C B3 80 8A
      13 : 86 BF 0A 03 D5 FF 3A 5F 7C 8C
      14 : 00 00 9E 6B AB 97 F5 EF 7F 80
      15 : 86 73 C8 CB B6 B7 B7 B7 85 8B
      16 : 31 17 84 6B E7 EF FF FF 7E 81
      17 : 79 AF 3B 5F FC FF E2 FF 7D 87
      18 : DC FF AE EF B3 B3 B8 B3 85 8B
      19 : EF FF F5 FF BA B7 B6 B7 88 8B
      20 : F8 FF F7 FF B3 B7 B7 B7 88 8B
      21 : FB FF FB FF B8 B3 B4 B3 85 88
      22 : F7 FF F7 FF B7 B7 B9 B7 87 8B
      23 : FD FF FE FF B9 B7 BB B7 85 8A
      24 : E4 FF B7 EF FF FF FF FF 7F 83
      25 : FF FF AC EB FF FF FC FF 7F 83
      26 : CC C7 F7 FF FF FF FF FF 7F 81
      27 : FF FF FE FF FF FF FF FF 80 80
    

    Note that 0x14C (the chunk size) = 332, 0x1C and 0x0D (the chunk arguments — count of 2×2 and 4×4 vectors, respectively) are 28 and 13. 28 * 10 + 13 * 4 = 332, so the numbers check out.

    Do you see any patterns in the codebook ? Here are some things I tried :

    • Treating the last 2 bytes as U & V and treating the first 4 as the 4 Y samples :


    • Treating the last 2 bytes as U & V and treating the first 8 as 4 16-bit little-endian Y samples :


    • Disregarding the final 2 bytes and treating the first 8 bytes as 4 RGB565 pixels (both little- and big-endian, respectively, shown here) :


    • Based on the type of data I’m seeing in these movies (which appears to be intended as overlays), I figured that some of these bits might indicate transparency ; here is 15-bit big-endian RGB which disregards the top bit of each pixel :


    These images are taken from the uploaded sample bdpuz.gjd, apparently a component of the puzzle represented in this screenshot.

    Unseen Types
    It has long been rumored that early RoQ files could contain JPEG images. I finally found one such specimen. One of the files bundled early in the uploaded fhpuz.gjd sample contains a JPEG frame. It’s a standard JFIF file and can easily be decoded after separating the bytes from the resource using ‘dd’. JPEGs serve as intraframes in the coding scheme, with successive RoQ frames moving objects on top.

    However, a new chunk type showed up as well, one identified by 0×1030. I have never encountered this type. Where could I possibly find data about this ? Fortunately, iD Games recently posted all of their open sourced games at Github. Reading through the code for their official RoQ decoder, I see that this is called a RoQ_PACKET. The name and the code behind it are both supremely unhelpful. The code is basically a no-op. The payloads of the various RoQ_PACKETs from one sample are observed to be either 8784, 14752, or 14760 bytes in length. It’s very likely that this serves the same purpose as the JPEG intraframes.

    Other Tidbits
    I read through the readme.txt on the first game disc and found this nugget :

            g)      Animations displayed normally or in SPOOKY MODE
    

    SPOOKY MODE is blue-tinted grayscale with color cursors, puzzle
    and game pieces. It is the preferred display setting of the
    developers at Trilobyte. Just for fun, try out the SPOOKY
    MODE.

    The MobyGames screenshot page has a number of screenshots labeled as being captured in spooky mode. Color tricks ?

    Meanwhile, another twist arose as I kept tweaking dreamroq to deal with more RoQ weirdness : After modifying my dreamroq code to handle these 10-byte vectors, it eventually chokes on another codebook. These codebooks happen to have 6-byte vectors again ! Fortunately, I was already working on a scheme to automatically detect which codebook is in play (plugging the numbers into a formula and seeing which vector size checks out).