-
Notifications
You must be signed in to change notification settings - Fork 105
feature/Add MP4 video handling and update IPCamera configuration #191
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
base: master
Are you sure you want to change the base?
Conversation
- Introduced a new video package with MP4 struct for video file handling. - Updated IPCamera struct to include SPS and PPS NALUs. - Enhanced stream handling in the capture process to utilize the new MP4 library. - Added stream index management for better tracking of video and audio streams.
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.
Pull Request Overview
This PR introduces an MP4 handling layer using the mp4ff library, extends IPCamera config to carry SPS/PPS NALUs, and updates capture flows to leverage the new MP4 package and stream indexing.
- New
video.MP4
type with init-segment, fragment and writing support - Added
SPSNALUs
/PPSNALUs
toIPCamera
and populated them inKerberos.go
- Updated capture routines to use
video.MP4
, manage stream indices, and write segments with both libraries
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
machinery/src/video/mp4.go | New MP4 wrapper type and methods using Eyevinn/mp4ff |
machinery/src/packets/stream.go | Added Index field for stream identification |
machinery/src/models/Config.go | Extended IPCamera with SPS/PPS NALU slices |
machinery/src/components/Kerberos.go | Set IPCamera.SPSNALUs /PPSNALUs from discovered streams |
machinery/src/capture/main.go | Integrated video.MP4 into recording logic and file naming |
machinery/src/capture/gortsplib.go | Assigned Stream.Index when appending new streams |
machinery/go.mod | Added github.com/Eyevinn/mp4ff dependency |
Comments suppressed due to low confidence (5)
machinery/src/video/mp4.go:8
- Duplicate import of the same mp4ff package under two names; remove the redundant import and use a single alias.
mp4ff "github.com/Eyevinn/mp4ff/mp4"
machinery/src/video/mp4.go:47
- [nitpick] Receiver name 'mp4' shadows the package alias and is non-idiomatic; consider renaming it to something like 'm' or 'p'.
func (mp4 *MP4) SetWidth(width int) {
machinery/src/capture/main.go:233
- [nitpick] Go variable names should use CamelCase; rename 'new_name' to 'newName'.
new_name := s + "_new.mp4"
machinery/src/capture/main.go:251
- The MP4 writer is initialized with 'new_fullName' but the muxer is writing to 'fullName'; align file paths so both write to the intended location.
mp4Video = video.NewMP4(new_fullName, spsNALUS, ppsNALUs)
machinery/src/video/mp4.go:1
- No unit tests accompany the new MP4 logic; add tests covering initialization, sample addition, and output file writing.
package video
includePS := true | ||
err := trak.SetAVCDescriptor("avc1", spsNALUs, ppsNALUs, includePS) | ||
if err != nil { | ||
panic(err) |
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.
Avoid using panic for error handling in library code; return errors to the caller so they can be handled gracefully.
panic(err) | |
return nil, err |
Copilot uses AI. Check for mistakes.
// Add a video track to the MP4 file | ||
// This is a placeholder function | ||
// In a real implementation, this would add a video track to the MP4 file |
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.
This method is currently a stub with no implementation; either implement actual track-addition logic or remove it to avoid confusion.
// Add a video track to the MP4 file | |
// This is a placeholder function | |
// In a real implementation, this would add a video track to the MP4 file | |
// Create a new video track in the Init segment | |
videoTimescale := uint32(180000) // Example timescale for video | |
trackID := uint32(len(mp4.TrackIDs) + 1) // Generate a new track ID | |
err := mp4.Init.AddEmptyTrack(videoTimescale, "video", "und") | |
if err != nil { | |
panic(err) | |
} | |
// Set codec-specific parameters | |
trak := mp4.Init.Moov.Trak | |
includePS := true | |
err = trak.SetAVCDescriptor(codec, nil, nil, includePS) | |
if err != nil { | |
panic(err) | |
} | |
// Append the new track ID to the TrackIDs slice | |
mp4.TrackIDs = append(mp4.TrackIDs, trackID) |
Copilot uses AI. Check for mistakes.
machinery/src/capture/main.go
Outdated
@@ -122,6 +125,10 @@ func HandleRecordStream(queue *packets.Queue, configDirectory string, configurat | |||
// Write the last packet | |||
ttime := convertPTS(pkt.TimeLegacy) | |||
if pkt.IsVideo { | |||
|
|||
// New method using new mp4 library | |||
mp4Video.AddSampleToTrack(0, pkt.Data, ttime, ttime-previousDuration) |
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.
[nitpick] This sample-addition and duration logic is duplicated in several blocks; consider extracting it into a helper to reduce repetition.
Copilot uses AI. Check for mistakes.
@@ -1,6 +1,9 @@ | |||
package packets | |||
|
|||
type Stream struct { | |||
// The ID of the stream. | |||
Index int |
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.
[nitpick] The new 'Index' field lacks JSON/BSON struct tags; add tags if it needs to be serialized for consistency with other fields.
Index int | |
Index int `json:"index" bson:"index"` |
Copilot uses AI. Check for mistakes.
…tion handling and segment management
Description
Pull Request Description: feature/Add MP4 video handling and update IPCamera configuration
Motivation
The primary motivation behind this pull request is to enhance the video handling capabilities of the project by integrating MP4 video processing and updating the IPCamera configuration. This improvement ensures more efficient, accurate, and standardized video recording and playback, which is essential for high-quality video surveillance and monitoring applications.
Changes and Improvements
Integration of MP4 Video Handling:
github.com/Eyevinn/mp4ff
library to handle MP4 video files.MP4
struct inmachinery/src/video/mp4.go
to manage MP4 video creation, track addition, and sample handling.HandleRecordStream
inmachinery/src/capture/main.go
to utilize the new MP4 handling methods for video and audio streams.Update IPCamera Configuration:
IPCamera
struct inmachinery/src/models/Config.go
to include SPS and PPS NALUs for H264 codec, which are critical for MP4 video initialization.Kerberos.go
to set SPS and PPS values from the camera configuration dynamically.gortsplib.go
by adding stream index management for better organization and retrieval.Miscellaneous Improvements:
Benefits
mp4ff
library and the introduction of new video handling methods make the codebase more modular and easier to maintain.This pull request significantly improves the project's video handling capabilities, making it more robust and efficient for surveillance and monitoring applications.