JuliaIO / VideoIO.jl

Reading and writing of video files in Julia via ffmpeg
https://juliaio.github.io/VideoIO.jl/stable
Other
125 stars 53 forks source link

how to obtain frame data and side_data in decode() #377

Closed zsz00 closed 7 months ago

zsz00 commented 1 year ago

I want to obtain frame data at ahead and behind line 446 in avio.jl https://github.com/JuliaIO/VideoIO.jl/blob/e4f619ab917810d93454d50fc2c40c7383f21058/src/avio.jl#L446

how to output the AVFrame data ? It's contain metadata and side_data what i want to get.

zsz00 commented 9 months ago

I know what's going on.

modification: avio.jl # 301

opts = AVDict("flags2" => "+export_mvs") 
ret = avcodec_open2(codec_context, codec, opts)  # C_NULL

modification : avio.jl: # 449 decode()

frame = graph_input_frame(r)
fret = avcodec_receive_frame(r.codec_context, frame)  # 解码获取frame. 
if fret >= 0
    sd = av_frame_get_side_data(frame, AV_FRAME_DATA_MOTION_VECTORS)  
    if sd != C_NULL
        sd_1 = unsafe_load(sd)   # pointer(sd.data)
        size_1 = sd_1.size
        mvs = Ptr{AVMotionVector}(sd_1.data)
        mvs_num = Int(size_1 ÷ sizeof(AVMotionVector))
        for i in 1:mvs_num
            mv = unsafe_load(mvs, i)
            println("mv:", join((mv.source, mv.w, mv.h, mv.src_x, mv.src_y, mv.dst_x, mv.dst_y, mv.flags), ','))
        end
    end
end