Recherche avancée

Médias (91)

Autres articles (29)

  • Qualité du média après traitement

    21 juin 2013, par

    Le bon réglage du logiciel qui traite les média est important pour un équilibre entre les partis ( bande passante de l’hébergeur, qualité du média pour le rédacteur et le visiteur, accessibilité pour le visiteur ). Comment régler la qualité de son média ?
    Plus la qualité du média est importante, plus la bande passante sera utilisée. Le visiteur avec une connexion internet à petit débit devra attendre plus longtemps. Inversement plus, la qualité du média est pauvre et donc le média devient dégradé voire (...)

  • Ajouter notes et légendes aux images

    7 février 2011, par

    Pour pouvoir ajouter notes et légendes aux images, la première étape est d’installer le plugin "Légendes".
    Une fois le plugin activé, vous pouvez le configurer dans l’espace de configuration afin de modifier les droits de création / modification et de suppression des notes. Par défaut seuls les administrateurs du site peuvent ajouter des notes aux images.
    Modification lors de l’ajout d’un média
    Lors de l’ajout d’un média de type "image" un nouveau bouton apparait au dessus de la prévisualisation (...)

  • Selection of projects using MediaSPIP

    2 mai 2011, par

    The 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 (...)

Sur d’autres sites (4603)

  • ffmpeg encode video produce incorrect mediainfo encoding settings

    25 août 2021, par Foong

    I've been trying to do batch encode videos to H265 format. I am using media-autobuild_suite to build ffmpeg and have already updating ffmpeg to the latest version.

    


    ffmpeg version N-103367-g5ddb4b6a1b-g88b3e31562+1 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 10.3.0 (Rev5, Built by MSYS2 project)
configuration:  --pkg-config=pkgconf --cc='ccache gcc' --cxx='ccache g++' --ld='ccache g++' --disable-autodetect --enable-amf --enable-bzlib --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-iconv --enable-lzma --enable-nvenc --enable-schannel --enable-zlib --enable-sdl2 --enable-ffnvcodec --enable-nvdec --enable-cuda-llvm --enable-gmp --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libdav1d --enable-libaom --disable-debug --enable-libfdk-aac --extra-libs=-liconv --enable-gpl --enable-version3 --enable-nonfree
libavutil      57.  4.101 / 57.  4.101
libavcodec     59.  5.101 / 59.  5.101
libavformat    59.  4.102 / 59.  4.102
libavdevice    59.  0.101 / 59.  0.101
libavfilter     8.  3.100 /  8.  3.100
libswscale      6.  0.100 /  6.  0.100
libswresample   4.  0.100 /  4.  0.100
libpostproc    56.  0.100 / 56.  0.100


    


    However, the Writing library and Encoding settings output is incorrect. Before update ffmpeg doesn't have this issue. I wonder what have been missing that causing this issue.

    


    encoding CLI :

    


    ffmpeg -y -hide_banner -loglevel error -stats -hwaccel dxva2 -i "input.mkv" -c:v libx265 -vsync cfr -pix_fmt yuv420p10le -preset fast -tune animation -x265-params ctu=32:min-cu-size=8:max-tu-size=16:tu-intra-depth=2:tu-inter-depth=2:me=1:subme=3:merange=44:max-merge=2:keyint=250:min-keyint=23:rc-lookahead=60:lookahead-slices=6:bframes=6:bframe-bias=0:b-adapt=2:ref=6:limit-refs=3:limit-tu=1:aq-mode=3:aq-strength=0.6:rd=3:psy-rd=1.00:psy-rdoq=1.50:rdoq-level=1:deblock=-1,-1:crf=21.0:qblur=0.50:qcomp=0.60:qpmin=0:qpmax=51:frame-threads=1:strong-intra-smoothing=1:no-lossless=1:no-cu-lossless=1:constrained-intra=1:no-fast-intra=1:no-open-gop=1:no-temporal-layers=1:no-limit-modes=1:weightp=1:no-weightb=1:no-analyze-src-pics=1:no-rd-refine=1:signhide=1:sao=1:no-sao-non-deblock=1:b-pyramid=1:no-cutree=1:no-intra-refresh=1:no-amp=1:temporal-mvp=1:no-early-skip=1:no-tskip=1:no-tskip-fast=1:no-deblock=1:no-b-intra=1:no-splitrd-skip=1:no-strict-cbr=1:no-rc-grain=1:no-const-vbv=1:no-opt-qp-pps=1:no-opt-ref-list-length-pps=1:no-multi-pass-opt-rps=1:no-opt-cu-delta-qp=1:no-hdr=1:no-hdr-opt=1:no-dhdr10-opt=1:no-idr-recovery-sei=1:no-limit-sao=1:no-lowpass-dct=1:no-dynamic-refine=1:no-single-sei=1 -c:a libfdk_aac -vf "fps=fps=29.970,setdar=16/9,scale=960:540:flags=lanczos" -map 0:v:? -map 0:a:? -map_metadata:g -1 -map_chapters 0 "output.mkv"


    


    Input video info :

    


    Video
ID                          : 1
Format                      : AVC
Format/Info                 : Advanced Video Codec
Format profile              : High@L3
Format settings             : CABAC / 5 Ref Frames
Format settings, CABAC      : Yes
Format settings, Reference  : 5 frames
Codec ID                    : V_MPEG4/ISO/AVC
Bit rate                    : 1 595 kb/s
Nominal bit rate            : 2 030 kb/s
Width                       : 720 pixels
Height                      : 480 pixels
Display aspect ratio        : 16:9
Original display aspect rat : 3:2
Frame rate mode             : Variable
Original frame rate         : 29.970 FPS
Color space                 : YUV
Chroma subsampling          : 4:2:0
Bit depth                   : 8 bits
Scan type                   : Progressive
Bits/(Pixel*Frame)          : 0.196
Writing library             : x264 core 66 r1115M 11863ac
Encoding settings           : cabac=1 / ref=5 / deblock=1:1:1 / analyse=0x3:0x133 / me=esa / subme=7 / psy_rd=1.0:0.0 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=2 / deadzone=21,11 / chroma_qp_offset=-2 / threads=1 / nr=0 / decimate=0 / mbaff=0 / bframes=1 / b_pyramid=0 / b_adapt=1 / b_bias=0 / direct=3 / wpredb=1 / keyint=250 / keyint_min=25 / scenecut=40 / rc=2pass / bitrate=2030 / ratetol=1.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / ip_ratio=1.40 / pb_ratio=1.30 / aq=1:1.00
Default                     : Yes
Forced                      : No


    


    Output video info :

    


    Video
ID                          : 1
Format                      : HEVC
Format/Info                 : High Efficiency Video Coding
Format profile              : Main 10@L3.1@Main
Codec ID                    : V_MPEGH/ISO/HEVC
Duration                    : 23 min 29 s
Width                       : 960 pixels
Height                      : 540 pixels
Display aspect ratio        : 16:9
Frame rate mode             : Constant
Frame rate                  : 29.970 (29970/1000) FPS
Color space                 : YUV
Chroma subsampling          : 4:2:0
Bit depth                   : 10 bits
Writing library             : Lavc59.5.100 libx265
Encoding settings           : cabac=1 / ref=5 / deblock=1:1:1 / analyse=0x3:0x133 / me=esa / subme=7 / psy_rd=1.0:0.0 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / cqm=2 / deadzone=21,11 / chroma_qp_offset=-2 / threads=1 / nr=0 / decimate=0 / mbaff=0 / bframes=1 / b_pyramid=0 / b_adapt=1 / b_bias=0 / direct=3 / wpredb=1 / keyint=250 / keyint_min=25 / scenecut=40 / rc=2pass / bitrate=2030 / ratetol=1.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / ip_ratio=1.40 / pb_ratio=1.30 / aq=1:1.00
Default                     : Yes
Forced                      : No
Color range                 : Limited


    


    Expecting (from previous encoded videos) :

    


    Video
ID                          : 1
Format                      : HEVC
Format/Info                 : High Efficiency Video Coding
Format profile              : Main 10@L3.1@Main
Codec ID                    : V_MPEGH/ISO/HEVC
Duration                    : 24 min 37 s
Bit rate                    : 833 kb/s
Width                       : 960 pixels
Height                      : 720 pixels
Display aspect ratio        : 4:3
Frame rate mode             : Constant
Frame rate                  : 23.976 (23976/1000) FPS
Color space                 : YUV
Chroma subsampling          : 4:2:0
Bit depth                   : 10 bits
Bits/(Pixel*Frame)          : 0.050
Stream size                 : 147 MiB
Title                       : HEVC
Writing library             : x265 3.4+28-419182243:[Windows][GCC 10.2.0][64 bit] 10bit
Encoding settings           : cpuid=1111039 / frame-threads=3 / numa-pools=12 / wpp / no-pmode / no-pme / no-psnr / no-ssim / log-level=2 / input-csp=1 / input-res=960x720 / interlace=0 / total-frames=0 / level-idc=0 / high-tier=1 / uhd-bd=0 / ref=5 / no-allow-non-conformance / no-repeat-headers / annexb / no-aud / no-hrd / info / hash=0 / no-temporal-layers / no-open-gop / min-keyint=1 / keyint=360 / gop-lookahead=0 / bframes=4 / b-adapt=2 / b-pyramid / bframe-bias=0 / rc-lookahead=20 / lookahead-slices=4 / scenecut=40 / hist-scenecut=0 / radl=0 / no-splice / no-intra-refresh / ctu=64 / min-cu-size=8 / no-rect / no-amp / max-tu-size=32 / tu-inter-depth=1 / tu-intra-depth=1 / limit-tu=0 / rdoq-level=0 / dynamic-rd=0.00 / no-ssim-rd / signhide / no-tskip / nr-intra=0 / nr-inter=0 / no-constrained-intra / strong-intra-smoothing / max-merge=2 / limit-refs=3 / no-limit-modes / me=1 / subme=3 / merange=16 / temporal-mvp / no-frame-dup / no-hme / weightp / no-weightb / no-analyze-src-pics / no-deblock / sao / no-sao-non-deblock / rd=3 / selective-sao=4 / no-early-skip / rskip / no-fast-intra / no-tskip-fast / no-cu-lossless / no-b-intra / no-splitrd-skip / rdpenalty=0 / psy-rd=0.20 / psy-rdoq=0.00 / no-rd-refine / no-lossless / cbqpoffs=0 / crqpoffs=0 / rc=crf / crf=26.0 / qcomp=0.60 / qpstep=4 / stats-write=0 / stats-read=0 / ipratio=1.40 / pbratio=1.00 / aq-mode=0 / aq-strength=0.00 / no-cutree / zone-count=0 / no-strict-cbr / qg-size=64 / no-rc-grain / qpmax=51 / qpmin=0 / no-const-vbv / sar=1 / overscan=0 / videoformat=5 / range=0 / colorprim=2 / transfer=2 / colormatrix=2 / chromaloc=0 / display-window=0 / cll=0,0 / min-luma=0 / max-luma=1023 / log2-max-poc-lsb=8 / vui-timing-info / vui-hrd-info / slices=1 / no-opt-qp-pps / no-opt-ref-list-length-pps / no-multi-pass-opt-rps / scenecut-bias=0.05 / hist-threshold=0.03 / no-opt-cu-delta-qp / no-aq-motion / no-hdr10 / no-hdr10-opt / no-dhdr10-opt / no-idr-recovery-sei / analysis-reuse-level=0 / analysis-save-reuse-level=0 / analysis-load-reuse-level=0 / scale-factor=0 / refine-intra=0 / refine-inter=0 / refine-mv=1 / refine-ctu-distortion=0 / no-limit-sao / ctu-info=0 / no-lowpass-dct / refine-analysis-type=0 / copy-pic=1 / max-ausize-factor=1.0 / no-dynamic-refine / no-single-sei / no-hevc-aq / no-svt / no-field / qp-adaptation-range=1.00 / no-scenecut-aware-qpconformance-window-offsets / right=0 / bottom=0 / decoder-max-rate=0 / no-vbv-live-multi-pass
Language                    : English
Default                     : Yes
Forced                      : No
Color range                 : Limited


    


    I have tried with simplest ffmpeg from official wedsite and encoding cli but the output still same.

    


    ffmpeg -i "input.mkv" -c:v libx265 "output.mkv"


    


    Update :
Tried converting video with FFmpeg 4.4 "Rao" from https://www.ffmpeg.org/ working fine. But compiled ffmpeg from media-autobuild_suite, tried with light build and full build, Writing library and Encoding settings output still incorrect.

    


  • ffmpeg API h264 encoded video does not play on all platforms

    19 juillet 2012, par TheSHEEEP

    Edit : In the previous version I used a very old ffmpeg API. I now use the newest libraries. The problem has only changed slightly, from "Main" to "High".

    I am using the ffmpeg C API to create a mp4 video in C++.

    I want the resulting video to be of the profile "Constrained Baseline", so that the resulting video can be played on as much platforms as possible, especially mobile, but I get "High" profile every time, even though I hard coded the codec profile to be FF_PROFILE_H264_CONSTRAINED_BASELINE. As a result, the video does not play on all our testing platforms.

    This is what "ffprobe video.mp4 -show_streams" tells about my video streams :

     Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 1970-01-01 00:00:00
    encoder         : Lavf53.5.0
     Duration: 00:00:13.20, start: 0.000000, bitrate: 553 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 320x180,
    424 kb/s, 15 fps, 15 tbr, 15 tbn, 30 tbc
    Metadata:
     creation_time   : 1970-01-01 00:00:00
     handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 12
    kb/s
    Metadata:
     creation_time   : 1970-01-01 00:00:00
     handler_name    : SoundHandler
    -------VIDEO STREAM--------
    [STREAM]
    index=0
    codec_name=h264
    codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10

    profile=High <-- This should be "Constrained Baseline"

    codec_type=video
    codec_time_base=1/30
    codec_tag_string=avc1
    codec_tag=0x31637661
    width=320
    height=180
    has_b_frames=0
    sample_aspect_ratio=N/A
    display_aspect_ratio=N/A
    pix_fmt=yuv420p
    level=30
    timecode=N/A
    is_avc=1
    nal_length_size=4
    id=N/A
    r_frame_rate=15/1
    avg_frame_rate=15/1
    time_base=1/15
    start_time=0.000000
    duration=13.200000
    bit_rate=424252
    nb_frames=198
    nb_read_frames=N/A
    nb_read_packets=N/A
    TAG:creation_time=1970-01-01 00:00:00
    TAG:language=und
    TAG:handler_name=VideoHandler
    [/STREAM]
    -------AUDIO STREAM--------
    [STREAM]
    index=1
    codec_name=aac
    codec_long_name=Advanced Audio Coding
    profile=unknown
    codec_type=audio
    codec_time_base=1/44100
    codec_tag_string=mp4a
    codec_tag=0x6134706d
    sample_fmt=s16
    sample_rate=44100
    channels=2
    bits_per_sample=0
    id=N/A
    r_frame_rate=0/0
    avg_frame_rate=0/0
    time_base=1/44100
    start_time=0.000000
    duration=13.165714
    bit_rate=125301
    nb_frames=567
    nb_read_frames=N/A
    nb_read_packets=N/A
    TAG:creation_time=1970-01-01 00:00:00
    TAG:language=und
    TAG:handler_name=SoundHandler
    [/STREAM]

    This is the function I use to add a video stream. All the values that come from ptr-> are defined from outside, do those values have to be specific values to get the correct profile ? :

    static AVStream *add_video_stream( Cffmpeg_dll * ptr, AVFormatContext *oc, enum   CodecID codec_id )
    {
    AVCodecContext *c;
    AVStream *st;  
    AVCodec* codec;

    // Get correct codec
    codec = avcodec_find_encoder(codec_id);
    if (!codec) {
       av_log(NULL, AV_LOG_ERROR, "%s","Video codec not found\n");
       exit(1);
    }

    // Create stream
    st = avformat_new_stream(oc, codec);
    if (!st) {
       av_log(NULL, AV_LOG_ERROR, "%s","Could not alloc stream\n");
       exit(1);
    }

    c = st->codec;

    /* Get default values */
    codec = avcodec_find_encoder(codec_id);
    if (!codec) {
       av_log(NULL, AV_LOG_ERROR, "%s","Video codec not found (default values)\n");
       exit(1);
    }
    avcodec_get_context_defaults3(c, codec);

    c->codec_id = codec_id;
    c->codec_type = AVMEDIA_TYPE_VIDEO;

    c->bit_rate = ptr->video_bit_rate;
    av_log(NULL, AV_LOG_ERROR, " Bit rate: %i", c->bit_rate);

       c->qmin = ptr->qmin;
       c->qmax = ptr->qmax;
       c->me_method = ptr->me_method;
       c->me_subpel_quality = ptr->me_subpel_quality;
       c->i_quant_factor = ptr->i_quant_factor;
       c->qcompress = ptr->qcompress;
       c->max_qdiff = ptr->max_qdiff;

       // We need to set the level and profile to get videos that play (hopefully) on all platforms
       c->level = 30;
       c->profile = FF_PROFILE_H264_CONSTRAINED_BASELINE;

    c->width = ptr->dstWidth;
    c->height = ptr->dstHeight;

    c->time_base.den = ptr->fps;
    c->time_base.num = 1;
    c->gop_size = ptr->fps;
    c->pix_fmt = STREAM_PIX_FMT;
    c->max_b_frames = 0;

    // some formats want stream headers to be separate
    if(oc->oformat->flags & AVFMT_GLOBALHEADER)
       c->flags |= CODEC_FLAG_GLOBAL_HEADER;

    return st;
    }

    Additional info :

    As a reference video, I use the gizmo.mp4 that Mozilla serves as an example that plays on every platform/browser. It definitely has the "Constrained Baseline" profile, and definitely works on all our testing smartphones. You can download it here. Our self-created video doesn't work on all platforms and I'm convinced this is because of the profile.

    I am also using qt-faststart.exe to move the headers to the start of the file after creating the mp4, as this cannot be done in a good way in C++ directly. Could that be the problem ?

    Obviously, I am doing something wrong, but I don't know what it could be. I'd be thankful for every hint ;)

  • Subtitling Sierra VMD Files

    1er juin 2016, par Multimedia Mike — Game Hacking

    I was contacted by a game translation hobbyist from Spain (henceforth known as The Translator). He had set his sights on Sierra’s 7-CD Phantasmagoria. This mammoth game was driven by a lot of FMV files and animations that have speech. These require language translation in the form of video subtitling. He’s lucky that he found possibly the one person on the whole internet who has just the right combination of skill, time, and interest to pull this off. And why would I care about helping ? I guess I share a certain camaraderie with game hackers. Don’t act so surprised. You know what kind of stuff I like to work on.

    The FMV format used in this game is VMD, which makes an appearance in numerous Sierra titles. FFmpeg already supports decoding this format. FFmpeg also supports subtitling video. So, ideally, all that’s necessary to support this goal is to add a muxer for the VMD format which can encode raw video and audio, which the format supports. Implement video compression as extra credit.

    The pipeline that I envisioned looks like this :


    VMD Subtitling Process

    VMD Subtitling Process


    “Trivial !” I surmised. I just never learn, do I ?

    The Plan
    So here’s my initial pitch, outlining the work I estimated that I would need to do towards the stated goal :

    1. Create a new file muxer that produces a syntactically valid VMD file with bogus video and audio data. Make sure it works with both FFmpeg’s playback system as well as the proper Phantasmagoria engine.
    2. Create a new video encoder that essentially operates in pass-through mode while correctly building a palette.
    3. Create a new basic encoder for the video frames.

    A big unknown for me was exactly how subtitle handling operates in FFmpeg. Thanks to this project, I now know. I was concerned because I was pretty sure that font rendering entails anti-aliasing which bodes poorly for keeping the palette count under 256 unique colors.

    Computer Science Puzzle
    When pondering how to process the palette, I was excited for the opportunity to exercise actual computer science. FFmpeg converts frames from paletted frames to full RGB frames. Then it needs to convert them back to paletted frames. I had a vague recollection of solving this problem once before when I was experimenting with a new paletted video codec. I seem to recall that I did the palette conversion in a very naive manner. I just used a static 256-element array and processed each RGB pixel of the frame, seeing if the value already occurred in the table (O(n) lookup) and adding it otherwise.

    There are more efficient algorithms, however, such as hash tables and trees. Somewhere along the line, FFmpeg helpfully acquired a rarely-used tree data structure, which was perfect for this project.

    So I was pretty pleased with this optimization. Too bad this wouldn’t survive to the end of the effort.

    Another palette-related challenge was the fact that a group of pictures would be accumulating a new palette but that palette needed to be recorded before the group. Thus, the muxer needed to have extra logic to rewind the file when the video encoder transmitted a palette change.

    Video Compression
    VMD has a few methods in its compression toolbox. It can use interframe differencing, it has some RLE, or it can code a frame raw. It can also use a custom LZ-like format on top of these. For early prototypes, I elected to leave each frame coded raw. After the concept was proved, I implemented the frame differencing.


    VMD frame #1

    VMD frame #2

    VMD frame difference
    Top frame compared with the middle frame yields the bottom frame : red pixels indicate changes

    Encoding only those red dots in between vast runs of unchanged pixels yielded a vast measurable improvement. The next step was to try wiring up FFmpeg’s existing LZ compression facilities to the encoder. This turned out to be implausible since VMD’s LZ variant has nothing to do with anything FFmpeg already provides. Fortunately, the LZ piece is not absolutely required and the frame differencing + RLE provides plenty of compression.

    Subtitling
    I’ve never done anything, multimedia programming-wise, concerning subtitles. I guess all the entertainment I care about has always been in my native tongue. What a good excuse to program outside of my comfort zone !

    First, I needed to know how to access FFmpeg’s subtitling facilities. Fortunately, The Translator did the legwork on this matter so I didn’t have to figure it out.

    However, I intuitively had misgivings about this phase. I had heard that the subtitling process performs anti-aliasing. That means that the image would need to be promoted to a higher colorspace for this phase and that the anti-aliasing process would likely push the color count way past 256. Some quick tests revealed this to be the case, as the running color count would leap by several hundred colors as soon as the palette accounting algorithm encountered a subtitle.

    So I dug into the subtitle subsystem. I discovered that the subtitle library operates by creating a linked list of subtitle bitmaps that the client app must render. The bitmaps are comprised of 8-bit alpha transparency values that must be composited onto the target frame (i.e., 0 = transparent, 255 = 100% opaque). For example, the letter ‘H’ :

                                      (with 00s removed)
    13 F8 41 00 00 00 00 68 E4  |  13 F8 41             68 E4    
    14 FF 44 00 00 00 00 6C EC  |  14 FF 44             6C EC
    14 FF 44 00 00 00 00 6C EC  |  14 FF 44             6C EC
    14 FF 44 00 00 00 00 6C EC  |  14 FF 44             6C EC
    14 FF DC D0 D0 D0 D0 E4 EC  |  14 FF DC D0 D0 D0 D0 E4 EC
    14 FF 7E 50 50 50 50 9A EC  |  14 FF 7E 50 50 50 50 9A EC
    14 FF 44 00 00 00 00 6C EC  |  14 FF 44             6C EC
    14 FF 44 00 00 00 00 6C EC  |  14 FF 44             6C EC
    14 FF 44 00 00 00 00 6C EC  |  14 FF 44             6C EC
    11 E0 3B 00 00 00 00 5E CE  |  11 E0 3B             5E CE
    

    To get around the color explosion problem, I chose a threshold value and quantized values above and below to 255 and 0, respectively. Further, the process chooses an appropriate color from the existing palette rather than introducing any new colors.

    Muxing Matters
    In order to force VMD into a general purpose media framework, a lot of special information needs to be passed around. Like many paletted codecs, the palette needs to be transmitted from the file demuxer to the video decoder via some side channel. For re-encoding, this also implies that the palette needs to make the trip from the video encoder to the file muxer. As if this wasn’t enough, individual VMD frames have even more data that needs to be ferried between the muxer and codec levels, including frame change boundaries. FFmpeg provides methods to do these things, but I could not always rely on the systems to relay the data in all cases. I was probably doing something wrong ; I accept that. Instead, I just packed all the information at the front of an encoded frame and split it apart in the muxer.

    I could not quite figure out how to get the audio and video muxed correctly. As a result, neither FFmpeg nor the Phantasmagoria engine could replay the files correctly.

    Plan B
    Since I was having so much trouble creating an entirely new VMD file, likely due to numerous unknown bits of the file format, I thought of another angle : re-use the existing VMD file. For this approach, I kept the video encoder and file muxer that I created in the initial phase, but modified the file muxer to emit a special intermediate file. Then, I created a Python tool to repackage the original VMD file using compressed video data in the intermediate file.

    For this phase, I also implemented a command line switch for FFmpeg to disable subtitle blending, to make the feature feel like less of an unofficial hack, as though this nonsense would ever have a chance of being incorporated upstream.

    At this point, I was seeing some success with the complete, albeit roundabout, subtitling process. I constructed a subtitle file using “Spanish I Learned From Mexican Telenovelas” and the frames turned out fairly readable :


    Le puso los cuernos a él

    “she cheated on him”


    es un desgraciado

    “he’s a scumbag” … these random subtitles could fit surprisingly well !


    The few files that I tested appeared to work fine. But then I handed off my work to The Translator and he immediately found a bunch of problems. According to my notes, the problems mostly took the form of flashing, solid color frames. Further, I found tiny, mostly imperceptible flaws in my RLE compressor, usually only detectable by running strict comparison tools ; but I wasn’t satisfied.

    At this point, I think I attempted to just encode the entire palette at the front of each frame, as allowed by the format, but that did not seem to fix any problems. My notes are not completely clear on this matter (likely because I was still trying to figure out the exact problem), but I think it had to do with FFmpeg inserting extra video frames in order to even out gaps in the video framerate.

    Sigh, Plan C
    At this point, I was getting tired of trying to force FFmpeg to do this. So I decided to minimize its involvement using lessons learned up to this point.

    The next pitch :

    1. Create a new C program that can open an existing VMD file and output an identical VMD file. I know this sounds easy, but the specific method of copying entails interpreting individual parts of the file and writing those individual parts to the new file. This is in preparation for…
    2. Import the VMD video decoder functions directly into the program to decode the individual video frames and re-encode them, replacing the video frames as the file is rewritten.
    3. Wire up the subtitle system. During the adventure to disable subtitle blending, I accidentally learned enough about interfacing to the subtitle library to just invoke it directly.
    4. Rewrite the RLE method so that it is 100% correct.

    Off to work I went. That part about lifting the existing VMD decoder functions out of their libavcodec nest turned out to not be that straightforward. As an alternative, I modified the decoder to dump the raw frames to an intermediate file. In doing so, I think I was able to avoid the issue of the duplicated frames that plagued the previous efforts.

    Also, remember how I was really pleased with the palette conversion technique in which I was able to leverage computer science big-O theory ? By this stage, I had no reason to convert the paletted video to RGB in the first place ; all of the decoding, subtitling and re-encoding operates in the paletted colorspace.

    This approach seemed to work pretty well. The final program is subtitle-vmd.c. The process is still a little weird. The modifications in my own FFmpeg fork are necessary to create an intermediate file that the new C tool can operate with.

    Next Steps
    The Translator has found some assorted bugs and corner cases that still need to be ironed out. Further, for extra credit, I need find the change windows for each frame to improve compression just a little more. I don’t think I will be trying for LZ compression, though.

    However, almost as soon as I had this whole system working, The Translator informed me that there is another, different movie format in play in the Phantasmagoria engine called ROBOT, with an extension of RBT. Fortunately, enough of the algorithms have been reverse engineered and re-implemented in ScummVM that I was able to sort out enough details for another subtitling project. That will be the subject of a future post.

    See Also :