phpfilevideometadata

Write properties/metadata (comments, title, etc.) to a video (PHP/cURL)


I was wondering how I can write metadata/properties (comments specifically and other information) to a video file (mainly .mp4), using PHP.

Properties/metadata of a video file - Windows

Here is my function that I use to download a remote file ($sourceURL) to a local destination ($destinationURL). I am able to rename the file with the $destinationURL (just end it with /video.mp4). I am currently using cURL, but if it can only be done by something like fopen()/fwrite(), then I am open to suggestions :)

function downloadFile( $sourceURL, $destinationURL ) {
    $options = array(
        CURLOPT_FILE => is_resource( $destinationURL ) ? $destinationURL : fopen( $destinationURL, 'w' ),
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_URL => $sourceURL,
        CURLOPT_FAILONERROR => true,
    );

    $ch = curl_init();
    curl_setopt_array( $ch, $options );
    $return = curl_exec( $ch );

    if ( $return === false ) {
        return curl_error( $ch );
    } else {
        return true;
    }
}

What I have tried:

  1. getID3(): http://getid3.sourceforge.net/ Perhaps I am missing something, but when I try to write to an mp4 file, it gives me this error:

Error message from getID3 - 1

Changing the tag format to "id3v1" doesn't work either.

Error message from getID3 - 2

If I'm not mistaken, the tag format's "id3v2.3" and "id3v1" only work with .mp3 files.

  1. Answers from: writing exif data in php - These only seem to work for image files

Thank you so much for your time and I look forward to any comments/answers I may receive.

Kind Regards

Joshua Lochner


Solution

  • You can use ffmpeg to extract/add metadata from/to videos, i.e.:

    To Extract:

    ffmpeg -i video.mp4 -f video_metadata.txt 
    

    To Add:

    ffmpeg -i video.mp4 -metadata title="my title" video_metadata.mp4