ramiropolla / ffglitch-core

FFglitch - FFmpeg fork for glitching
http://ffglitch.org
Other
75 stars 4 forks source link

quant_index feature in MPEG-2 not working #1

Open jasonhallen opened 1 month ago

jasonhallen commented 1 month ago

Hi Ramiro,

I'm working on glitching the DCT coefficients in MPEG-2 and have run into a problem. I'd like to know the quantization table values used to multiply the coefficients. In the MPEG-2 documentation for the q_dct feature, there should be a frame.q_dct.quant_index field.

I have the following line in my JS script that is run with ffedit to process a video file. The line is within the export function glitch_frame(frame) function.

console.log('quant_index ${frame.q_dct.quant_index[0]}')

I would think it should tell me the quantization table used to for the luma plane. However, I get this error message:

[quickjs @ 0x7fe1ef808200] TypeError: cannot read property '0' of undefined [quickjs @ 0x7fe1ef808200] at (temp/transition_avg_temp.js:59) [quickjs @ 0x7fe1ef808200] at forEach (native) [quickjs @ 0x7fe1ef808200] at glitch_frame (temp/transition_avg_temp.js:95) [quickjs @ 0x7fe1ef808200]

I've also noticed in the documentation for the four DCT features, it defines the quant_index as "The index for the Quantization Table for each plane, as defined in the 'dqt' feature." However, the qdt feature is not listed for MPEG-2. I found it defined in the JPEG feature documentation. It's not clear whether dqt is actually available for MPEG-2.

Thanks for your help! Jason

ramiropolla commented 4 weeks ago

Hi Jason,

Indeed, there is a mistake in the documentation. The dqt feature is not implemented for MPEG-2.

I have to 1) fix the documentation and 2) actually implement the dqt feature for MPEG-2 (and perhaps MPEG-4 as well).

From a quick glance at the FFmpeg code, it looks like the default quantization tables are defined here: https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/mpeg12data.c#L31 https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/mpeg12data.c#L42

Ramiro