All Projects → abema → Go Mp4

abema / Go Mp4

Licence: mit
Go library for reading and writing MP4 file

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Labels

Projects that are alternatives of or similar to Go Mp4

Musicdownloader
Material design YouTube mp3/mp4 downloader
Stars: ✭ 70 (-49.64%)
Mutual labels:  mp4
Av Converter
[av-converter.com] Audio and Video Converter, and YouTube downloader. Convert to MP3, MP4, AAC, FLAC, AC3, WAV, etc.
Stars: ✭ 97 (-30.22%)
Mutual labels:  mp4
Youtubedownloader
Downloads videos and playlists from YouTube
Stars: ✭ 2,202 (+1484.17%)
Mutual labels:  mp4
Faad2
Freeware Advanced Audio (AAC) Decoder faad2 mirror
Stars: ✭ 82 (-41.01%)
Mutual labels:  mp4
Mediaelement Files
Sample media files (MP4, WebM, Ogv, MP3, etc.) for the MediaElement.js library
Stars: ✭ 92 (-33.81%)
Mutual labels:  mp4
Media Server
RTSP/RTP/RTMP/FLV/HLS/MPEG-TS/MPEG-PS/MPEG-DASH/MP4/fMP4/MKV/WebM
Stars: ✭ 1,363 (+880.58%)
Mutual labels:  mp4
Spotivy
🎼 Download music videos from Spotify playlists
Stars: ✭ 64 (-53.96%)
Mutual labels:  mp4
React Native Yz Vlcplayer
VLC Player for react-native
Stars: ✭ 136 (-2.16%)
Mutual labels:  mp4
Gpac
Modular Multimedia framework for packaging, streaming and playing your favorite content.
Stars: ✭ 1,321 (+850.36%)
Mutual labels:  mp4
Audiovideocodec
一款视频录像机,支持AudioRecord录音、MediaCodec输出AAC、MediaMuxer合成音频视频并输出mp4,支持自动对焦、屏幕亮度调节、录制视频时长监听、手势缩放调整焦距等
Stars: ✭ 113 (-18.71%)
Mutual labels:  mp4
Live Dl
Download live streams from YouTube
Stars: ✭ 82 (-41.01%)
Mutual labels:  mp4
Sjmediacacheserver
A HTTP Media Caching Framework. It can cache FILE or HLS media. 音视频边播边缓存框架, 支持 HLS(m3u8) 和 FILE(mp4, mp3等).
Stars: ✭ 87 (-37.41%)
Mutual labels:  mp4
Nginx Vod Module
NGINX-based MP4 Repackager
Stars: ✭ 1,378 (+891.37%)
Mutual labels:  mp4
Testing Video
Generator of test video files for testing your media playback devices and calibrate TV sets
Stars: ✭ 70 (-49.64%)
Mutual labels:  mp4
Youtube2audio
Desktop application to download YouTube videos as annotated MP3 or MP4 files
Stars: ✭ 128 (-7.91%)
Mutual labels:  mp4
Sickbeard mp4 automator
Automatically convert video files to a standardized format with metadata tagging to create a beautiful and uniform media library
Stars: ✭ 1,142 (+721.58%)
Mutual labels:  mp4
Gifserver
A server for transcoding gif to video on the fly
Stars: ✭ 100 (-28.06%)
Mutual labels:  mp4
Mediafile
A unified reader of metadata from audio & video files.
Stars: ✭ 138 (-0.72%)
Mutual labels:  mp4
Gortmp
rtmp server for windows, mac, linux, android. (mpegts hls)
Stars: ✭ 131 (-5.76%)
Mutual labels:  mp4
Faac
Freeware Advanced Audio Coder faac mirror
Stars: ✭ 102 (-26.62%)
Mutual labels:  mp4

go-mp4

Go Reference CircleCI codecov Go Report Card

go-mp4 is Go library for reading and writing MP4.

Integration with your Go application

Reading

You can parse MP4 file as follows:

// expand all boxes
_, err := mp4.ReadBoxStructure(file, func(h *mp4.ReadHandle) (interface{}, error) {
	fmt.Println("depth", len(h.Path))

	// Box Type (e.g. "mdhd", "tfdt", "mdat")
	fmt.Println("type", h.BoxInfo.Type.String())

	// Box Size
	fmt.Println("size", h.BoxInfo.Size)

	if h.BoxInfo.IsSupportedType() {
		// Payload
		box, _, err := h.ReadPayload()
		if err != nil {
			return nil, err
		}
		str, err := mp4.Stringify(box, h.BoxInfo.Context)
		if err != nil {
			return nil, err
		}
		fmt.Println("payload", str)

		// Expands children
		return h.Expand()
	}
	return nil, nil
})
// extract specific boxes
boxes, err := mp4.ExtractBox(file, nil, mp4.BoxPath{mp4.BoxTypeMoov(), mp4.BoxTypeTrak(), mp4.BoxTypeTkhd()})
// get basic informations
info, _ := mp4.Probe(bufseekio.NewReadSeeker(file, 1024, 4))                                           
fmt.Println("track num:", len(info.Tracks))

Writing

Writer helps you to write box tree. The following sample code edits emsg box and writes to another file.

r := bufseekio.NewReadSeeker(inputFile, 128*1024, 4)
w := mp4.NewWriter(outputFile)
_, err = mp4.ReadBoxStructure(r, func(h *mp4.ReadHandle) (interface{}, error) {
	switch h.BoxInfo.Type {
	case mp4.BoxTypeEmsg():
		// write box size and box type
		_, err := w.StartBox(&h.BoxInfo)
		if err != nil {
			return nil, err
		}
		// read payload
		box, _, err := h.ReadPayload()
		if err != nil {
			return nil, err
		}
		// update MessageData
		emsg := box.(*mp4.Emsg)
		emsg.MessageData = []byte("hello world")
		// write box playload
		if _, err := mp4.Marshal(w, emsg, h.BoxInfo.Context); err != nil {
			return nil, err
		}
		// rewrite box size
		_, err = w.EndBox()
		return nil, err
	default:
		// copy all
		return nil, w.CopyBox(r, &h.BoxInfo)
	}
})

User-defined Boxes

You can create additional box definition as follows:

func BoxTypeXxxx() BoxType { return mp4.StrToBoxType("xxxx") }

func init() {
	mp4.AddBoxDef(&Xxxx{}, 0)
}

type Xxxx struct {
	FullBox  `mp4:"0,extend"`
	UI32      uint32 `mp4:"1,size=32"`
	ByteArray []byte `mp4:"2,size=8,len=dynamic"`
}

func (*Xxxx) GetType() BoxType {
	return BoxTypeXxxx()
}

Buffering

go-mp4 has no buffering feature for I/O. If you should reduce Read function calls, you can wrap the io.ReadSeeker by bufseekio.

Command Line Tool

Install mp4tool as follows:

go get github.com/abema/go-mp4/mp4tool

mp4tool -help

For example, mp4tool dump MP4_FILE_NAME command prints MP4 box tree as follows:

[moof] Size=504
  [mfhd] Size=16 Version=0 Flags=0x000000 SequenceNumber=1
  [traf] Size=480
    [tfhd] Size=28 Version=0 Flags=0x020038 TrackID=1 DefaultSampleDuration=9000 DefaultSampleSize=33550 DefaultSampleFlags=0x1010000
    [tfdt] Size=20 Version=1 Flags=0x000000 BaseMediaDecodeTimeV1=0
    [trun] Size=424 ... (use -a option to show all)
[mdat] Size=44569 Data=[...] (use -mdat option to expand)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].