Q:

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.

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:

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:

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

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

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

A:

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

ffmpeg documentation

A:

exiftool will help you a lot. See https://owl.phy.queensu.ca/~phil/exiftool/examples.html
On most Debian based distro's you can install this with sudo apt-get install exiftool.
After this you could use shell_exec in PHP with the example command in the link above.
 $output = shell_exec('exiftool yourfile.mp4');

Reading and Writing is possible with exiftool see the examples.
Small example copied from the site i linked:

4) Write multiple tags
exiftool -artist="Phil Harvey" -copyright="2011 Phil Harvey" a.jpg

So this means:
$command = 'exiftool -artist="Phil Harvey" -copyright="2011 Phil Harvey" a.jpg';
$output = shell_exec($command);

Of course this example is applicable to video files too. 

