abema / go-mp4

Go library for reading and writing MP4 file
https://dev.to/sunfishshogi/go-mp4-golang-library-and-cli-tool-for-mp4-52o1
MIT License
464 stars 30 forks source link

Issue in adding album cover to a mp4 file #166

Closed Abhi5033 closed 7 months ago

Abhi5033 commented 8 months ago

Trying to add album cover to a song but the embedded cover is not recognizing I tried below approach

resp, err := http.Get(coverURL)
defer resp.Body.Close()
coverData, err := io.ReadAll(resp.Body)
err = addMeta(mp4.BoxType{'c', 'o', 'v', 'r'}, coverData)

Maybe I should give JPEG format also as a parameter? please help

sunfish-shogi commented 8 months ago

@Abhi5033 addMeta is your original private function, isn't it? go-mp4 has no such named function.

Abhi5033 commented 8 months ago

@Abhi5033 addMeta is your original private function, isn't it? go-mp4 has no such named function.

Yes sir

addMeta := func(tag mp4.BoxType, val interface{}) error {
            _, err = w.StartBox(&mp4.BoxInfo{Type: tag})
            if err != nil {
                    return err
            }

            err = marshalData(val)
            if err != nil {
                    return err
            }

            _, err = w.EndBox()
            return err
            }

Is it possible to add album cover to a song in go-mp4 by any other means?

sunfish-shogi commented 8 months ago

@Abhi5033 Your code includes a private function call, again. (marshalData) And I can not understand why your code uses io.ReadAll and passes its result as interface{}.

At first, please read https://dev.to/sunfishshogi/go-mp4-golang-library-and-cli-tool-for-mp4-52o1 to understand ISO Base Media File Format. go-mp4 supports only low level operations, so you should understand binary level data structure of MP4. Next, please see #165. I think your use-case is almost the same with the issue.

sunfish-shogi commented 7 months ago

I'll close this issue, because it seems it does not represent go-mp4's problem. Please comment when you have any additional informations.