Recherche avancée

Médias (91)

Autres articles (75)

  • Participer à sa traduction

    10 avril 2011

    Vous pouvez nous aider à améliorer les locutions utilisées dans le logiciel ou à traduire celui-ci dans n’importe qu’elle nouvelle langue permettant sa diffusion à de nouvelles communautés linguistiques.
    Pour ce faire, on utilise l’interface de traduction de SPIP où l’ensemble des modules de langue de MediaSPIP sont à disposition. ll vous suffit de vous inscrire sur la liste de discussion des traducteurs pour demander plus d’informations.
    Actuellement MediaSPIP n’est disponible qu’en français et (...)

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

  • Le profil des utilisateurs

    12 avril 2011, par

    Chaque utilisateur dispose d’une page de profil lui permettant de modifier ses informations personnelle. Dans le menu de haut de page par défaut, un élément de menu est automatiquement créé à l’initialisation de MediaSPIP, visible uniquement si le visiteur est identifié sur le site.
    L’utilisateur a accès à la modification de profil depuis sa page auteur, un lien dans la navigation "Modifier votre profil" est (...)

Sur d’autres sites (8591)

  • Dumping and playing h264 bytestream from RTSP webcam

    18 octobre 2011, par thek

    My goal is to connect (rtsp) to camera, get h264 stream from rtp packages, save it as a bytestream to file and be able to play it (with ffplay or vlc). The only problem is that my result stream gives me errors (and a nice gray rectangle, sometimes with something moving - like only P frames are decoded) while playing.

    Here is my DESCRIBE response from rtsp server (ip replaced with ) :

       10:04:18.387 [New I/O client worker #1-1] INFO  rtsp.WebcamClientResponseHandler - Sending DESCRIBE request: DESCRIBE rtsp://<server>:<port>/channel1 RTSP/1.0
    -------status---------
    200 OK
    -------headers---------
    CSeq : 2
    Date : Wed, Jan 07 2009 19:05:09 GMT
    Content-Base : rtsp://<server>/channel1/
    Content-Type : application/sdp
    Content-Length : 433
    -------content---------
    v=0
    o=- 515949295799 1 IN IP4 <server>
    s=Session streamed by stream
    i=1
    t=0 0
    a=tool:LIVE555 Streaming Media v2009.01.26
    a=type:broadcast
    a=control:*
    a=range:npt=0-
    a=x-qt-text-nam:Session streamed by stream
    a=x-qt-text-inf:1
    m=video 0 RTP/AVP 96
    c=IN IP4 0.0.0.0
    b=AS:128
    a=rtpmap:96 H264/90000
    a=fmtp:96 packetization-mode=1;profile-level-id=420028;sprop-parameter-sets=Z0IAKOkCg/I=,aM44gA==
    a=control:tracks
    </server></server></port></server>

    And server sends me RTP packages with non IDR frames and fragmented (type=28) IDR frames. First ones are written to file, fragmented are unpacked.
    The result byte stream is :

    NAL SPS NAL PPS NAL FRAME1 NAL FRAME2 ... NAL FRAMEN

    where NAL is (hex) 00 00 01
    and SPS is (decoded Z0IAKOkCg/I= from sprop-parameter-sets): 67 42 00 28 e9 02 83 f2
    and PPS is (decoded aM44gA==): 68 ce 38 80

    I found similar topic with same steps taken :
    how-to-process-raw-udp-packets-so-that-they-can-be-decoded-by-a-decoder-filter-i
    but I can't see what am I missing.

    Could anyone give me some clue what may be wrong ?

    This is a link to generated h264 file :
    a.h264

    Below I'm attaching some more information from playing my stream.


    Playing my video with ffplay -f h264 a.h264 gives me following output (and a gray rectangle) :

    ffplay version 0.8.4-4:0.8.4-0ubuntu1~jon1, Copyright (c) 2003-2011 the FFmpeg developers
     built on Sep 25 2011 09:45:09 with gcc 4.4.3
     configuration: --extra-version=&#39;4:0.8.4-0ubuntu1~jon1&#39; --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
     libavutil    51.  9. 1 / 51.  9. 1
     libavcodec   53.  7. 0 / 53.  7. 0
     libavformat  53.  4. 0 / 53.  4. 0
     libavdevice  53.  1. 1 / 53.  1. 1
     libavfilter   2. 23. 0 /  2. 23. 0
     libswscale    2.  0. 0 /  2.  0. 0
     libpostproc  52.  0. 0 / 52.  0. 0
    [h264 @ 0x184d4c0] Missing reference picture
    [h264 @ 0x184d4c0] decode_slice_header error                                                                                                                                                                                                
    [h264 @ 0x184d4c0] concealing 300 DC, 300 AC, 300 MV errors                                                                                                                                                                                
    [h264 @ 0x1822640] max_analyze_duration 5000000 reached at 5000000
    [h264 @ 0x1822640] Estimating duration from bitrate, this may be inaccurate                                                                                                                                                                
    Input #0, h264, from &#39;a.h264&#39;:                                                                                                                                                                                                              
     Duration: N/A, bitrate: N/A
    Stream #0.0: Video: h264 (Baseline), yuv420p, 320x240, 25 fps, 25 tbr, 1200k tbn, 50 tbc
    [h264 @ 0x184d4c0] Missing reference pictureq=    3KB sq=    0B f=0/0  
    [h264 @ 0x184d4c0] decode_slice_header error                                                                                                                                                                                                
    [h264 @ 0x184d4c0] concealing 300 DC, 300 AC, 300 MV errors                                                                                                                                                                                
    [h264 @ 0x184d4c0] QP 4294967283 out of rangeKB sq=    0B f=0/0   0/0  
    [h264 @ 0x184d4c0] decode_slice_header error                                                                                                                                                                                                
    [h264 @ 0x184d4c0] concealing 300 DC, 300 AC, 300 MV errors                                                                                                                                                                                
    [h264 @ 0x184d4c0] Missing reference picture
    [h264 @ 0x184d4c0] decode_slice_header error                                                                                                                                                                                                
    [h264 @ 0x184d4c0] mmco: unref short failure                                                                                                                                                                                                
    [h264 @ 0x184d4c0] concealing 300 DC, 300 AC, 300 MV errors                                                                                                                                                                                
    [h264 @ 0x184d4c0] P sub_mb_type 5 out of range at 8 0
    [h264 @ 0x184d4c0] error while decoding MB 8 0                                                                                                                                                                                              
    [h264 @ 0x184d4c0] concealing 300 DC, 300 AC, 300 MV errors                                                                                                                                                                                
    [h264 @ 0x184d4c0] QP 4294967283 out of range
    [h264 @ 0x184d4c0] decode_slice_header error                                                                                                                                                                                                
    [h264 @ 0x184d4c0] concealing 300 DC, 300 AC, 300 MV errors

    Running h264_analyse (http://h264bitstream.sourceforge.net/) on my stream gives me :

    ./h264_analyze a.h264
    !! Found NAL at offset 3 (0x0003), size 8 (0x0008)
    ==================== NAL ====================
    forbidden_zero_bit : 0
    nal_ref_idc : 3
    nal_unit_type : 7 ( Sequence parameter set )
    ======= SPS =======
    profile_idc : 66
    constraint_set0_flag : 0
    constraint_set1_flag : 0
    constraint_set2_flag : 0
    constraint_set3_flag : 0
    reserved_zero_4bits : 0
    level_idc : 40
    seq_parameter_set_id : 0
    chroma_format_idc : 0
    residual_colour_transform_flag : 0
    bit_depth_luma_minus8 : 0
    bit_depth_chroma_minus8 : 0
    qpprime_y_zero_transform_bypass_flag : 0
    seq_scaling_matrix_present_flag : 0
    log2_max_frame_num_minus4 : 0
    pic_order_cnt_type : 0
     log2_max_pic_order_cnt_lsb_minus4 : 1
     delta_pic_order_always_zero_flag : 0
     offset_for_non_ref_pic : 0
     offset_for_top_to_bottom_field : 0
     num_ref_frames_in_pic_order_cnt_cycle : 0
    num_ref_frames : 1
    gaps_in_frame_num_value_allowed_flag : 0
    pic_width_in_mbs_minus1 : 19
    pic_height_in_map_units_minus1 : 14
    frame_mbs_only_flag : 1
    mb_adaptive_frame_field_flag : 0
    direct_8x8_inference_flag : 1
    frame_cropping_flag : 0
     frame_crop_left_offset : 0
     frame_crop_right_offset : 0
     frame_crop_top_offset : 0
     frame_crop_bottom_offset : 0
    vui_parameters_present_flag : 0                                                                                                                                                                                                            
    === VUI ===                                                                                                                                                                                                                                  
    aspect_ratio_info_present_flag : 0                                                                                                                                                                                                          
     aspect_ratio_idc : 0                                                                                                                                                                                                                      
    sar_width : 0                                                                                                                                                                                                                          
    sar_height : 0                                                                                                                                                                                                                          
    overscan_info_present_flag : 0                                                                                                                                                                                                              
     overscan_appropriate_flag : 0                                                                                                                                                                                                            
    video_signal_type_present_flag : 0                                                                                                                                                                                                          
     video_format : 0                                                                                                                                                                                                                          
     video_full_range_flag : 0                                                                                                                                                                                                                
     colour_description_present_flag : 0                                                                                                                                                                                                      
    colour_primaries : 0                                                                                                                                                                                                                    
     transfer_characteristics : 0                                                                                                                                                                                                              
     matrix_coefficients : 0                                                                                                                                                                                                                  
    chroma_loc_info_present_flag : 0                                                                                                                                                                                                            
     chroma_sample_loc_type_top_field : 0                                                                                                                                                                                                      
     chroma_sample_loc_type_bottom_field : 0                                                                                                                                                                                                  
    timing_info_present_flag : 0                                                                                                                                                                                                                
     num_units_in_tick : 0                                                                                                                                                                                                                    
     time_scale : 0                                                                                                                                                                                                                            
     fixed_frame_rate_flag : 0                                                                                                                                                                                                                
    nal_hrd_parameters_present_flag : 0                                                                                                                                                                                                        
    vcl_hrd_parameters_present_flag : 0                                                                                                                                                                                                        
     low_delay_hrd_flag : 0                                                                                                                                                                                                                    
    pic_struct_present_flag : 0
    bitstream_restriction_flag : 0
     motion_vectors_over_pic_boundaries_flag : 0
     max_bytes_per_pic_denom : 0
     max_bits_per_mb_denom : 0
     log2_max_mv_length_horizontal : 0
     log2_max_mv_length_vertical : 0
     num_reorder_frames : 0
     max_dec_frame_buffering : 0
    === HRD ===
    cpb_cnt_minus1 : 0
    bit_rate_scale : 0
    cpb_size_scale : 0
    initial_cpb_removal_delay_length_minus1 : 0
    cpb_removal_delay_length_minus1 : 0
    dpb_output_delay_length_minus1 : 0
    time_offset_length : 0
    !! Found NAL at offset 14 (0x000E), size 4 (0x0004)
    ==================== NAL ====================
    forbidden_zero_bit : 0
    nal_ref_idc : 3
    nal_unit_type : 8 ( Picture parameter set )
    ======= PPS =======
    pic_parameter_set_id : 0
    seq_parameter_set_id : 0
    entropy_coding_mode_flag : 0
    pic_order_present_flag : 0
    num_slice_groups_minus1 : 0
    slice_group_map_type : 0
    num_ref_idx_l0_active_minus1 : 0
    num_ref_idx_l1_active_minus1 : 0
    weighted_pred_flag : 0
    weighted_bipred_idc : 0
    pic_init_qp_minus26 : 0
    pic_init_qs_minus26 : 0
    chroma_qp_index_offset : 0
    deblocking_filter_control_present_flag : 0
    constrained_intra_pred_flag : 0
    redundant_pic_cnt_present_flag : 0
    transform_8x8_mode_flag : 1
    pic_scaling_matrix_present_flag : 0
    second_chroma_qp_index_offset : 16
    !! Found NAL at offset 21 (0x0015), size 480 (0x01E0)
    ==================== NAL ====================
    forbidden_zero_bit : 0
    nal_ref_idc : 2
    nal_unit_type : 1 ( Coded slice of a non-IDR picture )
    ======= Slice Header =======
    first_mb_in_slice : 0
    slice_type : 5 ( P slice only )
    pic_parameter_set_id : 0
    frame_num : 1
    field_pic_flag : 0
    bottom_field_flag : 0
    idr_pic_id : 0
    pic_order_cnt_lsb : 2
    delta_pic_order_cnt_bottom : 0
    redundant_pic_cnt : 0
    direct_spatial_mv_pred_flag : 0
    num_ref_idx_active_override_flag : 0
    num_ref_idx_l0_active_minus1 : 0
    num_ref_idx_l1_active_minus1 : 0
    cabac_init_idc : 0
    slice_qp_delta : -7
    sp_for_switch_flag : 0
    slice_qs_delta : 0
    disable_deblocking_filter_idc : 0
    slice_alpha_c0_offset_div2 : 0
    slice_beta_offset_div2 : 0
    slice_group_change_cycle : 0
    === Prediction Weight Table ===
    luma_log2_weight_denom : 0
    chroma_log2_weight_denom : 0
    luma_weight_l0_flag : 0
    chroma_weight_l0_flag : 0
    luma_weight_l1_flag : 0
    chroma_weight_l1_flag : 0
    === Ref Pic List Reordering ===
    ref_pic_list_reordering_flag_l0 : 0
    ref_pic_list_reordering_flag_l1 : 0
    === Decoded Ref Pic Marking ===
    no_output_of_prior_pics_flag : 0
    long_term_reference_flag : 0
    adaptive_ref_pic_marking_mode_flag : 0
    !! Found NAL at offset 504 (0x01F8), size 324 (0x0144)
    ==================== NAL ====================
    forbidden_zero_bit : 0
    nal_ref_idc : 2
    nal_unit_type : 1 ( Coded slice of a non-IDR picture )
    ======= Slice Header =======
    first_mb_in_slice : 0
    slice_type : 5 ( P slice only )
    pic_parameter_set_id : 0
    frame_num : 2
    field_pic_flag : 0
    bottom_field_flag : 0
    idr_pic_id : 0
    pic_order_cnt_lsb : 4
    delta_pic_order_cnt_bottom : 0
    redundant_pic_cnt : 0
    direct_spatial_mv_pred_flag : 0
    num_ref_idx_active_override_flag : 0
    num_ref_idx_l0_active_minus1 : 0
    num_ref_idx_l1_active_minus1 : 0
    cabac_init_idc : 0
    slice_qp_delta : -7
    sp_for_switch_flag : 0
    slice_qs_delta : 0
    disable_deblocking_filter_idc : 0
    slice_alpha_c0_offset_div2 : 0
    slice_beta_offset_div2 : 0
    slice_group_change_cycle : 0
    === Prediction Weight Table ===
    luma_log2_weight_denom : 0
    chroma_log2_weight_denom : 0
    luma_weight_l0_flag : 0
    chroma_weight_l0_flag : 0
    luma_weight_l1_flag : 0
    chroma_weight_l1_flag : 0
    === Ref Pic List Reordering ===
    ref_pic_list_reordering_flag_l0 : 0
    ref_pic_list_reordering_flag_l1 : 0
    === Decoded Ref Pic Marking ===
    no_output_of_prior_pics_flag : 0
    long_term_reference_flag : 0
    adaptive_ref_pic_marking_mode_flag : 0
    !! Found NAL at offset 831 (0x033F), size 300 (0x012C)
    ==================== NAL ====================
    forbidden_zero_bit : 0
    nal_ref_idc : 2
    nal_unit_type : 1 ( Coded slice of a non-IDR picture )
    ======= Slice Header =======
    first_mb_in_slice : 0
    slice_type : 5 ( P slice only )
    pic_parameter_set_id : 0
    frame_num : 3
    field_pic_flag : 0
    bottom_field_flag : 0
    idr_pic_id : 0
    pic_order_cnt_lsb : 6
    delta_pic_order_cnt_bottom : 0
    redundant_pic_cnt : 0
    direct_spatial_mv_pred_flag : 0
    num_ref_idx_active_override_flag : 0
    num_ref_idx_l0_active_minus1 : 0
    num_ref_idx_l1_active_minus1 : 0
    cabac_init_idc : 0
    slice_qp_delta : -7
    sp_for_switch_flag : 0
    slice_qs_delta : 0
    disable_deblocking_filter_idc : 0
    slice_alpha_c0_offset_div2 : 0
    slice_beta_offset_div2 : 0
    slice_group_change_cycle : 0
    === Prediction Weight Table ===
    luma_log2_weight_denom : 0
    chroma_log2_weight_denom : 0
    luma_weight_l0_flag : 0
    chroma_weight_l0_flag : 0
    luma_weight_l1_flag : 0
    chroma_weight_l1_flag : 0
    === Ref Pic List Reordering ===
    ref_pic_list_reordering_flag_l0 : 0
    ref_pic_list_reordering_flag_l1 : 0
    === Decoded Ref Pic Marking ===
    no_output_of_prior_pics_flag : 0
    long_term_reference_flag : 0
    adaptive_ref_pic_marking_mode_flag : 0
    !! Found NAL at offset 1134 (0x046E), size 825 (0x0339)
    ==================== NAL ====================
    forbidden_zero_bit : 0
    nal_ref_idc : 2
    nal_unit_type : 1 ( Coded slice of a non-IDR picture )
    ======= Slice Header =======
    first_mb_in_slice : 0
    slice_type : 5 ( P slice only )
    pic_parameter_set_id : 0
    frame_num : 4
    field_pic_flag : 0
    bottom_field_flag : 0
    idr_pic_id : 0
    pic_order_cnt_lsb : 8
    delta_pic_order_cnt_bottom : 0
    redundant_pic_cnt : 0
    direct_spatial_mv_pred_flag : 0
    num_ref_idx_active_override_flag : 0
    num_ref_idx_l0_active_minus1 : 0
    num_ref_idx_l1_active_minus1 : 0
    cabac_init_idc : 0
    slice_qp_delta : -9
    sp_for_switch_flag : 0
    slice_qs_delta : 0
    disable_deblocking_filter_idc : 0
    slice_alpha_c0_offset_div2 : 0
    slice_beta_offset_div2 : 0
    slice_group_change_cycle : 0
    === Prediction Weight Table ===
    luma_log2_weight_denom : 0
    chroma_log2_weight_denom : 0
    luma_weight_l0_flag : 0
    chroma_weight_l0_flag : 0
    luma_weight_l1_flag : 0
    chroma_weight_l1_flag : 0
    === Ref Pic List Reordering ===
    ref_pic_list_reordering_flag_l0 : 0
    ref_pic_list_reordering_flag_l1 : 0
    === Decoded Ref Pic Marking ===
    no_output_of_prior_pics_flag : 0
    long_term_reference_flag : 0
    adaptive_ref_pic_marking_mode_flag : 0
    !! Found NAL at offset 1962 (0x07AA), size 754 (0x02F2)
    ==================== NAL ====================
    forbidden_zero_bit : 0
    nal_ref_idc : 2
    nal_unit_type : 1 ( Coded slice of a non-IDR picture )
    ======= Slice Header =======
    first_mb_in_slice : 0
    slice_type : 5 ( P slice only )
    pic_parameter_set_id : 0
    frame_num : 5
    field_pic_flag : 0
    bottom_field_flag : 0
    idr_pic_id : 0
    pic_order_cnt_lsb : 10
    delta_pic_order_cnt_bottom : 0
    redundant_pic_cnt : 0
    direct_spatial_mv_pred_flag : 0
    num_ref_idx_active_override_flag : 0
    num_ref_idx_l0_active_minus1 : 0
    num_ref_idx_l1_active_minus1 : 0
    cabac_init_idc : 0
    slice_qp_delta : -9
    sp_for_switch_flag : 0
    slice_qs_delta : 0
    disable_deblocking_filter_idc : 0
    slice_alpha_c0_offset_div2 : 0
    slice_beta_offset_div2 : 0
    slice_group_change_cycle : 0
    === Prediction Weight Table ===
    luma_log2_weight_denom : 0
    chroma_log2_weight_denom : 0
    luma_weight_l0_flag : 0
    chroma_weight_l0_flag : 0
    luma_weight_l1_flag : 0
    chroma_weight_l1_flag : 0
    === Ref Pic List Reordering ===
    ref_pic_list_reordering_flag_l0 : 0
    ref_pic_list_reordering_flag_l1 : 0
    === Decoded Ref Pic Marking ===
    no_output_of_prior_pics_flag : 0
    long_term_reference_flag : 0
    adaptive_ref_pic_marking_mode_flag : 0
    !! Found NAL at offset 2719 (0x0A9F), size 824 (0x0338)
    ==================== NAL ====================
    forbidden_zero_bit : 0
    nal_ref_idc : 2
    nal_unit_type : 1 ( Coded slice of a non-IDR picture )
    ======= Slice Header =======
    first_mb_in_slice : 0
    slice_type : 5 ( P slice only )
    pic_parameter_set_id : 0
    frame_num : 6
    field_pic_flag : 0
    bottom_field_flag : 0
    idr_pic_id : 0
    pic_order_cnt_lsb : 12
    delta_pic_order_cnt_bottom : 0
    redundant_pic_cnt : 0
    direct_spatial_mv_pred_flag : 0
    num_ref_idx_active_override_flag : 0
    num_ref_idx_l0_active_minus1 : 0
    num_ref_idx_l1_active_minus1 : 0
    cabac_init_idc : 0
    slice_qp_delta : -9
    sp_for_switch_flag : 0
    slice_qs_delta : 0
    disable_deblocking_filter_idc : 0
    slice_alpha_c0_offset_div2 : 0
    slice_beta_offset_div2 : 0
    slice_group_change_cycle : 0
    === Prediction Weight Table ===
    luma_log2_weight_denom : 0
    chroma_log2_weight_denom : 0
    luma_weight_l0_flag : 0
    chroma_weight_l0_flag : 0
    luma_weight_l1_flag : 0
    chroma_weight_l1_flag : 0
    === Ref Pic List Reordering ===
    ref_pic_list_reordering_flag_l0 : 0
    ref_pic_list_reordering_flag_l1 : 0
    === Decoded Ref Pic Marking ===
    no_output_of_prior_pics_flag : 0
    long_term_reference_flag : 0
    adaptive_ref_pic_marking_mode_flag : 0
    !! Found NAL at offset 3546 (0x0DDA), size 628 (0x0274)
    ==================== NAL ====================
    [...]
  • Basic Video Palette Conversion

    20 août 2011, par Multimedia Mike — General, Python

    How do you take a 24-bit RGB image and convert it to an 8-bit paletted image for the purpose of compression using a codec that requires 8-bit input images ? Seems simple enough and that’s what I’m tackling in this post.

    Ask FFmpeg/Libav To Do It
    Ideally, FFmpeg / Libav should be able to handle this automatically. Indeed, FFmpeg used to be able to, at least at the time I wrote this post about ZMBV and was unhappy with FFmpeg’s default results. Somewhere along the line, FFmpeg and Libav lost the ability to do this. I suspect it got removed during some swscale refactoring.

    Still, there’s no telling if the old system would have computed palettes correctly for QuickTime files.

    Distance Approach
    When I started writing my SMC video encoder, I needed to convert RGB (from PNG files) to PAL8 colorspace. The path of least resistance was to match the pixels in the input image to the default 256-color palette that QuickTime assumes (and is hardcoded into FFmpeg/Libav).

    How to perform the matching ? Find the palette entry that is closest to a given input pixel, where "closest" is the minimum distance as computed by the usual distance formula (square root of the sum of the squares of the diffs of all the components).



    That means for each pixel in an image, check the pixel against 256 palette entries (early termination is possible if an acceptable threshold is met). As you might imagine, this can be a bit time-consuming. I wondered about a faster approach...

    Lookup Table
    I think this is the approach that FFmpeg used to use, but I went and derived it for myself after studying the default QuickTime palette table. There’s a pattern there— all of the RGB entries are comprised of combinations of 6 values — 0x00, 0x33, 0x66, 0x99, 0xCC, and 0xFF. If you mix and match these for red, green, and blue values, you come up with 6 * 6 * 6 = 216 different colors. This happens to be identical to the web-safe color palette.

    The first (0th) entry in the table is (FF, FF, FF), followed by (FF, FF, CC), (FF, FF, 99), and on down to (FF, FF, 00) when the green component gets knocked down and step and the next color is (FF, CC, FF). The first 36 palette entries in the table all have a red component of 0xFF. Thus, if an input RGB pixel has a red color closest to 0xFF, it must map to one of those first 36 entries.

    I created a table which maps indices 0..215 to values from 5..0. Each of the R, G, and B components of an input pixel are used to index into this table and derive 3 indices ri, gi, and bi. Finally, the index into the palette table is given by :

      index = ri * 36 + gi * 6 + bi
    

    For example, the pixel (0xFE, 0xFE, 0x01) would yield ri, gi, and bi values of 0, 0, and 5. Therefore :

      index = 0 * 36 + 0 * 6 + 5
    

    The palette index is 5, which maps to color (0xFF, 0xFF, 0x00).

    Validation
    So I was pretty pleased with myself for coming up with that. Now, ideally, swapping out one algorithm for another in my SMC encoder should yield identical results. That wasn’t the case, initially.

    One problem is that the regulation QuickTime palette actually has 40 more entries above and beyond the typical 216-entry color cube (rounding out the grand total of 256 colors). Thus, using the distance approach with the full default table provides for a little more accuracy.

    However, there still seems to be a problem. Let’s check our old standby, the Big Buck Bunny logo image :



    Distance approach using the full 256-color QuickTime default palette


    Distance approach using the 216-color palette


    Table lookup approach using the 216-color palette

    I can’t quite account for that big red splotch there. That’s the most notable difference between images 1 and 2 and the only visible difference between images 2 and 3.

    To prove to myself that the distance approach is equivalent to the table approach, I wrote a Python script to iterate through all possible RGB combinations and verify the equivalence. If you’re not up on your base 2 math, that’s 224 or 16,777,216 colors to run through. I used Python’s multiprocessing module to great effect and really maximized a Core i7 CPU with 8 hardware threads.

    So I’m confident that the palette conversion techniques are sound. The red spot is probably attributable to a bug in my WIP SMC encoder.

    Source Code
    Update August 23, 2011 : Here’s the Python code I used for proving equivalence between the 2 approaches. In terms of leveraging multiple CPUs, it’s possibly the best program I have written to date.

    PYTHON :
    1. # !/usr/bin/python
    2.  
    3. from multiprocessing import Pool
    4.  
    5. palette = []
    6. pal8_table = []
    7.  
    8. def process_r(r) :
    9.  counts = []
    10.  
    11.  for i in xrange(216) :
    12.   counts.append(0)
    13.  
    14.  print "r = %d" % (r)
    15.  for g in xrange(256) :
    16.   for b in xrange(256) :
    17.    min_dsqrd = 0xFFFFFFFF
    18.    best_index = 0
    19.    for i in xrange(len(palette)) :
    20.     dr = palette[i][0] - r
    21.     dg = palette[i][1] - g
    22.     db = palette[i][2] - b
    23.     dsqrd = dr * dr + dg * dg + db * db
    24.     if dsqrd <min_dsqrd :
    25.      min_dsqrd = dsqrd
    26.      best_index = i
    27.    counts[best_index] += 1
    28.  
    29.    # check if the distance approach deviates from the table-based approach
    30.    i = best_index
    31.    r = palette[i][0]
    32.    g = palette[i][1]
    33.    b = palette[i][2]
    34.    ri = pal8_table[r]
    35.    gi = pal8_table[g]
    36.    bi = pal8_table[b]
    37.    table_index = ri * 36 + gi * 6 + bi ;
    38.    if table_index != best_index :
    39.     print "(0x%02X 0x%02X 0x%02X) : distance index = %d, table index = %d" % (r, g, b, best_index, table_index)
    40.  
    41.  return counts
    42.  
    43. if __name__ == ’__main__’ :
    44.  counts = []
    45.  for i in xrange(216) :
    46.   counts.append(0)
    47.  
    48.  # initialize reference palette
    49.  color_steps = [ 0xFF, 0xCC, 0x99, 0x66, 0x33, 0x00 ]
    50.  for r in color_steps :
    51.   for g in color_steps :
    52.    for b in color_steps :
    53.     palette.append([r, g, b])
    54.  
    55.  # initialize palette conversion table
    56.  for i in range(0, 26) :
    57.   pal8_table.append(5)
    58.  for i in range(26, 77) :
    59.   pal8_table.append(4)
    60.  for i in range(77, 128) :
    61.   pal8_table.append(3)
    62.  for i in range(128, 179) :
    63.   pal8_table.append(2)
    64.  for i in range(179, 230) :
    65.   pal8_table.append(1)
    66.  for i in range(230, 256) :
    67.   pal8_table.append(0)
    68.  
    69.  # create a pool of worker threads and break up the overall job
    70.  pool = Pool()
    71.  it = pool.imap_unordered(process_r, range(256))
    72.  try :
    73.   while 1 :
    74.    partial_counts = it.next()
    75.    for i in xrange(216) :
    76.     counts[i] += partial_counts[i]
    77.  except StopIteration :
    78.   pass
    79.  
    80.  print "index, count, red, green, blue"
    81.  for i in xrange(len(counts)) :
    82.   print "%d, %d, %d, %d, %d" % (i, counts[i], palette[i][0], palette[i][1], palette[i][2])
  • VP8 Documentation and Test Vector Contributions

    14 octobre 2010, par noreply@blogger.com (John Luther)

    Janne Salonen of the WebM team in Oulu, Finland (formerly On2 Finland) has added a tabular description of the VP8 syntax to the VP8 Bitstream Guide. The new annex provides a concise reference of the elements in the bitstream and we hope will make implementing and testing VP8 decoders easier. The updated document and source can be downloaded from our documentation page.

    We’re working on more improvements to the bitstream guide and invite other community members to help. As with the VP8 code, we gladly give attribution credit to documentation contributors and have added an AUTHORS file to the bitstream-guide Git repository.

    New VP8 Test Vectors

    The Oulu team has also produced some new VP8 test vectors. We analyzed a large set of WebM videos and produced two important corner use cases. The first produces the worst-case memory bandwidth (i.e., lots of global motion, all fractional motion vectors). The second produces the worst-case boolean decoder bin rate over dozens of consecutive frames. These vectors have been added to the VP8 test repository. Our team will consider other corner cases in the next batch of streams we add to the repository.

    Aki Kuusela is Hantro Embedded Engineering Manager at Google.