add motion vector extraction from side data#33
Conversation
Codecov Report
@@ Coverage Diff @@
## master #33 +/- ##
==========================================
- Coverage 32.11% 31.79% -0.33%
==========================================
Files 4 4
Lines 2525 2551 +26
==========================================
Hits 811 811
- Misses 1667 1693 +26
Partials 47 47
Continue to review full report at Codecov.
|
| return int64(C.av_frame_get_pkt_duration(f.CAVFrame)) | ||
| } | ||
|
|
||
| func (f *Frame) GetSideData() *FrameSideData { |
There was a problem hiding this comment.
In go I like to avoid Get... as much as possible.
Please rename to SideData.
Also, please make it accept the type of side data:
func (f *Frame) SideData(dataType FrameSideDataType) *FrameSideDataPlease define them on the top of the file as something like this:
Please use these values:
https://www.ffmpeg.org/doxygen/3.0/frame_8h_source.html#l00048
type FrameSideDataType C.enum_AVFrameSideDataType
const (
FrameSideDataTypePanScan FrameSideDataType = C.AV_FRAME_DATA_PANSCAN
...
FrameSideDataTypeMotionVectors FrameSideDataType = C.AV_FRAME_DATA_MOTION_VECTORS
...
)| // } | ||
| // return 0; | ||
| //} | ||
| //static const AVMotionVector *go_motion_vector(const AVFrameSideData *sd, int num) { |
There was a problem hiding this comment.
An extra line here between functions please.
| // const AVMotionVector *mvs = (const AVMotionVector *)sd->data; | ||
| // return &mvs[num]; | ||
| //} | ||
| //static int go_motion_vector_size(const AVFrameSideData *sd) { |
| type FrameSideData struct { | ||
| CFrameSideData *C.AVFrameSideData | ||
| } | ||
|
|
There was a problem hiding this comment.
Since I am following this pattern, can you follow it too?
func NewFrameSideDataFromC(cFrameSideData unsafe.Pointer) * FrameSideData {
return &FrameSideData{CFrameSideData: (*C.AVFrameSideData)(cFrameSideData)}
}and then call it inside Frame.SideData() ?
| type MotionVector struct { | ||
| CMotionVector *C.AVMotionVector | ||
| } | ||
|
|
There was a problem hiding this comment.
can you do the same here for NewMotionVectorFromC ?
| return int64(mv.CMotionVector.source) | ||
| } | ||
|
|
||
| func (mv *MotionVector) Width() int64 { |
There was a problem hiding this comment.
Any reason why you use int64?
libav returns int8 for this: https://www.ffmpeg.org/doxygen/3.0/structAVMotionVector.html#ae208462700b6b52d22ed38e9d62cf2cf
I think we should use int8 too. Same for Height
| return int64(mv.CMotionVector.dst_x), int64(mv.CMotionVector.dst_y) | ||
| } | ||
|
|
||
| func (mv *MotionVector) MotionVector() (int64, int64) { |
There was a problem hiding this comment.
Since this is a MotionVector we should just call this Vector
libav defines this as int32.
| return int64(mv.CMotionVector.motion_x), int64(mv.CMotionVector.motion_y) | ||
| } | ||
|
|
||
| func (mv *MotionVector) MotionScale() int64 { |
There was a problem hiding this comment.
Since this is a MotionVector we should just call this Scale
libav defines this as uint16.
| CMotionVector *C.AVMotionVector | ||
| } | ||
|
|
||
| func (mv *MotionVector) Source() int64 { |
| func (mv *MotionVector) MotionScale() int64 { | ||
| return int64(mv.CMotionVector.motion_scale) | ||
| } | ||
|
|
There was a problem hiding this comment.
Please add support for Flags too:
https://www.ffmpeg.org/doxygen/3.0/structAVMotionVector.html#a75d00ba82df36ec5e697527ddb9addcc
func (mv *MotionVector) Flags() uint64 {
return mv.CMotionVector.flags
}|
@cvley Thank you for your PR. |
|
@imkira Thanks for your reviews. I will work on it 😄 |
|
@imkira I have fixed the code and add a simple test, please review them. By the way, I'd like to generate a random video in the test to perform motion vectors extraction, is it OK? Thanks. |
|
@cvley No problem about the random video. During tests I'm currently downloading to a directory called https://bintray.com/imkira/go-libav/download_file?file_path=sample_iPod.m4v And referencing them like this: go-libav/avformat/avformat_test.go Line 60 in 126f4da Do any of these work for your tests? If not, please send me the file to imkira@gmail.com and I will upload it for the tests. |
| FrameDataPanScan FrameSideDataType = C.AV_FRAME_DATA_PANSCAN | ||
| FrameDataA53CC FrameSideDataType = C.AV_FRAME_DATA_A53_CC | ||
| FrameDataStereo3D FrameSideDataType = C.AV_FRAME_DATA_STEREO3D | ||
| FrameDataMatrixEncoding FrameSideDataType = C.AV_FRAME_DATA_MATRIXENCODING |
There was a problem hiding this comment.
Maybe we should use _ too in MATRIX_ENCODING
There was a problem hiding this comment.
Do you mean we use FrameDataMATRIX_ENCODING instead of FrameDataMatrixEncoding?
Should I change all these types using _?
Thanks.
| FrameDataMatrixEncoding FrameSideDataType = C.AV_FRAME_DATA_MATRIXENCODING | ||
| FrameDataDownMixInfo FrameSideDataType = C.AV_FRAME_DATA_DOWNMIX_INFO | ||
| FrameDataReplayGain FrameSideDataType = C.AV_FRAME_DATA_REPLAYGAIN | ||
| FrameDataDisplayMatrix FrameSideDataType = C.AV_FRAME_DATA_DISPLAYMATRIX |
| return | ||
| } | ||
|
|
||
| C.av_buffer_unref(unsafe.Pointer(&sd.CFrameSideData.buf)) |
There was a problem hiding this comment.
Aren't these managed pointers. Do we to provide this?
There was a problem hiding this comment.
We don't use buf directly here, but we need to free it.
I will dig more about the buf and av_buffer_unref usage.
Thanks.
| return FrameSideDataType(sd.CFrameSideData._type) | ||
| } | ||
|
|
||
| func (sd *FrameSideData) MotionVector(n int) *MotionVector { |
There was a problem hiding this comment.
I see you didn't follow my advice for MotionVectors() []*MotionVector.
Also, you're not using go_motion_vector_size anymore.
How will you discover the number of motion vectors in go?
| } | ||
| } | ||
|
|
||
| func TestMotionVectorFromFrameSideData(t *testing.T) { |
There was a problem hiding this comment.
Can you make a separate function TestFrameSideData where you call all its funcs?
There was a problem hiding this comment.
No problems. I will try your test videos and random generated videos. 😄
| sideData := frame.SideData(FrameDataMotionVectors) | ||
| if sideData != nil { | ||
| t.Fatalf("[TestMotionVectorFromFrameSideData] sidedata=%v, NG expected=nil", sideData) | ||
| } |
There was a problem hiding this comment.
Can you call all MotionVector's funcs?
|
Any update on this @cvley ? |
Hi, I need motion vector extraction from video, so I implement related functions.
Pls. review them, thanks 😄