HEVC transform quantized coefficients using ffmpeg - ffmpeg

i'm using the HEVC codec with ffmpeg(version 2.7.2 ). Since I'm not able to write a one-line command in order to read/save the quantized transformed coefficients for each CU and frame, I would like to know if anyone can help me modify the original files in the libavcodec library?

No CLI option available to save the quantized coefficients. If you need to modify the source code for this purpose, below function is the right place to start with
hls_transform_unit() # libavcodec\hevc.c

Related

How to extract motion vectors from h264 without a full decode

I'm want to extract the motion vector information from the encoded stream without performing a full decode of the frame. I'm using ffmpeg library and aware of extracting the information using the av_frame_get_side_data. Unfortunately, it does a full decode of the frame before providing the AV_FRAME_DATA_MOTION_VECTORS. My hunch is it should be possible to parse the h264 to extract out the motion vectors only, ignoring all the other data. Any direction/pointers will be very helpful!

How can i forcing current frame to be encoded as intra frame using libavcodec

I want to change gop dynamic to adapt to player. Smaller gop help for reduce first screen cost; Big gop help to reduce bitrate to save bandwidth.
I found nvenc has a function which can solve the problem above.
https://docs.nvidia.com/video-technologies/video-codec-sdk/nvenc-video-encoder-api-prog-guide/#forcing-current-frame-to-be-encoded-as-intra-frame
But I'm using ffmpeg. Is there any similar function in ffmpeg?
If the AVFrame->pict_type is set to AV_PICTURE_TYPE_I, then the NVENC encoders, by default, will encode it as an intra frame. They also have a private option to force it as an IDR frame.
For the latter, add before opening the encoder.
av_opt_set(avctx->priv_data, "forced_idr", "1", 0);

Extract motion vectors from x265 (HEVC) encoded video with ffmpeg/libavcodec?

I know that one can extract the motion vectors from an h264 encoded via by first setting the flag
av_dict_set(&opts, "flags2", "+export_mvs", 0);
then you can query the side-data for the motion vectors by doing this
sd = av_frame_get_side_data(frame, AV_FRAME_DATA_MOTION_VECTORS);
When I looked online to see if you can do something similar with HEVC encoded videos, I wasn't able to find any information. All I found was this by the definition of "AV_FRAME_DATA_MOTION_VECTORS"
Motion vectors exported by some codecs (on demand through the
export_mvs flag set in the libavcodec AVCodecContext flags2 option).
The data is the AVMotionVector struct defined in
libavutil/motion_vector.h.
but there was no information on exactly which codecs export this motion vector information. How would I go about finding this out?
If I'm not mistaken h264 is the only codec to print Motion Estimation Vectors.
I would suggest trying out the video filter mestimate.
Also, if you want to have a better ideia what's going on in ffmpeg, check the function ff_print_debug_info2 in libavcodec/mpegvideo.c

How to detect lossless JPEG 2000 compression?

I have a motion-JPEG 2000 file that I need to determine if the creator used lossless compression to create it based on the file itself. I do not have the raw video data to compare to, and I do not have the source code of the application used to produce the file.
Based on what I have found, it looks like the best I can do is check the wavelet filter (biorthogonal 3/5) and the quantization step size (1), and assume lossless if those conditions are true.
Any suggestions on how to check for lossless compression are greatly appreciated. My working environment is MATLAB or Java, but any hints for other platforms will be helpful.
You can use ffmpeg for this purpose. Download it from here: https://ffmpeg.org/. After you installed the software and added its source folder to WIN path, you can simply do the following:
ffprobe Test.mj2
The output then shows you many details about the video, including its possible
losslessness.
See the following example output
It is possible to use 5/4 wavelet and quantization step of 1, and still truncate the code stream during encoding to get a lossy result. This is still a valid JPEG 2000 images. So, the only way of checking for lossless is to compare with original.

Motion Vectors and DC coefficients from MPEG4 stream

I need to extract information about motion vectors and DC coefficients from an MPEG4 video. I've searched relevant sites and topics and I found that a good solution is to work with the code of ffmpeg codec. Especially the ff_print_debug_info function in libavcodec/mpegvideo.c calculates relevant information.
However, I'm new on the C/C++ field and if there is any example code that describes or explains how to extract MVs and DC coefficients that would be very helpful.
In the more recent version I use (FFmpeg 0.10.2 from http://ffmpeg.org/download.html) there is another file mpeg4videodec.c. Is there any chance to retrieve the needed information by this code?
Check out this piece of code: http://www.princeton.edu/~jiasic/cos435/motion_vector.c
It gives the basic idea of accessing motion vectors withing ffmpeg-decoded frame.
As for DC coefficients, I don't see any other way than to inject your own code into the decoder to dump coefficients as you decode.

Resources