-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add motion vector extraction from side data #33
base: master
Are you sure you want to change the base?
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.
|
avutil/avutil.go
Outdated
@@ -980,6 +989,64 @@ func (f *Frame) PacketDuration() int64 { | |||
return int64(C.av_frame_get_pkt_duration(f.CAVFrame)) | |||
} | |||
|
|||
func (f *Frame) GetSideData() *FrameSideData { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) *FrameSideData
Please 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
...
)
avutil/avutil.go
Outdated
@@ -41,6 +42,14 @@ package avutil | |||
// } | |||
// return 0; | |||
//} | |||
//static const AVMotionVector *go_motion_vector(const AVFrameSideData *sd, int num) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An extra line here between functions please.
avutil/avutil.go
Outdated
// const AVMotionVector *mvs = (const AVMotionVector *)sd->data; | ||
// return &mvs[num]; | ||
//} | ||
//static int go_motion_vector_size(const AVFrameSideData *sd) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
type FrameSideData struct { | ||
CFrameSideData *C.AVFrameSideData | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you do the same here for NewMotionVectorFromC
?
avutil/avutil.go
Outdated
return int64(mv.CMotionVector.source) | ||
} | ||
|
||
func (mv *MotionVector) Width() int64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
avutil/avutil.go
Outdated
return int64(mv.CMotionVector.dst_x), int64(mv.CMotionVector.dst_y) | ||
} | ||
|
||
func (mv *MotionVector) MotionVector() (int64, int64) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a MotionVector
we should just call this Vector
libav defines this as int32
.
avutil/avutil.go
Outdated
return int64(mv.CMotionVector.motion_x), int64(mv.CMotionVector.motion_y) | ||
} | ||
|
||
func (mv *MotionVector) MotionScale() int64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a MotionVector
we should just call this Scale
libav defines this as uint16
.
avutil/avutil.go
Outdated
CMotionVector *C.AVMotionVector | ||
} | ||
|
||
func (mv *MotionVector) Source() int64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int32
avutil/avutil.go
Outdated
func (mv *MotionVector) MotionScale() int64 { | ||
return int64(mv.CMotionVector.motion_scale) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 [email protected] 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should use _ too in MATRIX_ENCODING
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DISPLAY_MATRIX
return | ||
} | ||
|
||
C.av_buffer_unref(unsafe.Pointer(&sd.CFrameSideData.buf)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't these managed pointers. Do we to provide this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about this
@@ -845,3 +845,13 @@ func TestPixelFormatDescriptor_ComponentCount(t *testing.T) { | |||
t.Fatalf("[TestPixelFormatDescriptor_ComponentCount] count=%d, NG expected=%d", count, 3) | |||
} | |||
} | |||
|
|||
func TestMotionVectorFromFrameSideData(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make a separate function TestFrameSideData
where you call all its func
s?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you call all MotionVector
's func
s?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problems.
Any update on this @cvley ? |
Hi, I need motion vector extraction from video, so I implement related functions.
Pls. review them, thanks 😄