15

For the past couple weeks my co workers and me have been working on trying to get captions on our clients YouTube video's through the v3 API. After about week we were finally able to get the captions to upload just fine but, YouTube would give us this message in the UI "Track content is not processed" and doesn't display the caption's that we upload. However, we can download the original format that was upload; so we know the file was uploaded successfully.

We also were able to get the sync flag to work that tells YouTube to run through the transcript and set timings for the video but, it doesn't actually work. It returns telling us that it is syncing but when we go to the UI for the video it just shows the caption track name and give's us the message "Track content is not processed.". We've used up all the hours that we had and we're now working on our own time to solve this problem but still no luck.

Has anyone ran into this problem before? If so, what were you able to do to get this to work?

I will post a snippet of my code below that shows the upload portion of our script.

# Insert a video caption.
# Create a caption snippet with video id, language, name and draft status.
$captionSnippet = new Google_Service_YouTube_CaptionSnippet();
$captionSnippet->setVideoId($videoId);
$captionSnippet->setLanguage($captionLanguage);
$captionSnippet->setName($captionName);
$captionSnippet->setIsDraft( true );

# Create a caption with snippet.
$caption = new Google_Service_YouTube_Caption();
$caption->setSnippet($captionSnippet);

// Setting the defer flag to true tells the client to return a request which can be called
$client->setDefer(false);

// Get the file content's of the uploaded file
$file = file_get_contents( $captionFile['tmp_name'] );

// Create a request for the API's captions.insert method to create and upload a caption.
$insertRequest = $youtube->captions->insert("snippet", $caption, array( 
  'sync' => true, 
  'data' => $file, 
  'mimeType' => 'application/octet-stream', 
  'uploadType' => 'multipart' )  
); 

echo '<pre>'; print_r( $insertRequest ); echo '</pre>';

// // Read the caption file and upload it chunk by chunk.
$status = $insertRequest;
fclose($handle);

// If you want to make other calls after the file upload, set setDefer back to false
$client->setDefer(false);

Thank you,
Tyler Steinhaus

emccomas
  • 1
  • 1
Tyler Steinhaus
  • 206
  • 1
  • 6
  • 1
    Exact same problem here. It looks like a bug on YouTube's end. Hoping to see some kind of meaningful answer soon. – Parker Kemp Jul 20 '15 at 19:49
  • 2
    It would be nice if a Google Engineer could comment on this issue since they apparently are suppose to be monitoring these tags. I also tried again today with no luck. – Tyler Steinhaus Jul 22 '15 at 20:37
  • 3
    Related issue: https://code.google.com/p/gdata-issues/issues/detail?id=7468 – Alex0007 Aug 09 '15 at 11:40

2 Answers2

5

Have you tried to achieve what you want using the functions Google have posted themselves?

Below taken from https://developers.google.com/youtube/v3/code_samples/php

/**
 * Uploads a caption track in draft status that matches the API request parameters.
 * (captions.insert)
 *
 * @param Google_Service_YouTube $youtube YouTube service object.
 * @param Google_Client $client Google client.
 * @param $videoId the YouTube video ID of the video for which the API should
 *  return caption tracks.
 * @param $captionLanguage language of the caption track.
 * @param $captionName name of the caption track.
 * @param $captionFile caption track binary file.
 * @param $htmlBody html body.
 */
function uploadCaption(Google_Service_YouTube $youtube, Google_Client $client, $videoId,
    $captionFile, $captionName, $captionLanguage, &$htmlBody) {
    # Insert a video caption.
    # Create a caption snippet with video id, language, name and draft status.
    $captionSnippet = new Google_Service_YouTube_CaptionSnippet();
    $captionSnippet->setVideoId($videoId);
    $captionSnippet->setLanguage($captionLanguage);
    $captionSnippet->setName($captionName);

    # Create a caption with snippet.
    $caption = new Google_Service_YouTube_Caption();
    $caption->setSnippet($captionSnippet);

    // Specify the size of each chunk of data, in bytes. Set a higher value for
    // reliable connection as fewer chunks lead to faster uploads. Set a lower
    // value for better recovery on less reliable connections.
    $chunkSizeBytes = 1 * 1024 * 1024;

    // Setting the defer flag to true tells the client to return a request which can be called
    // with ->execute(); instead of making the API call immediately.
    $client->setDefer(true);

    // Create a request for the API's captions.insert method to create and upload a caption.
    $insertRequest = $youtube->captions->insert("snippet", $caption);

    // Create a MediaFileUpload object for resumable uploads.
    $media = new Google_Http_MediaFileUpload(
        $client,
        $insertRequest,
        '*/*',
        null,
        true,
        $chunkSizeBytes
    );
    $media->setFileSize(filesize($captionFile));


    // Read the caption file and upload it chunk by chunk.
    $status = false;
    $handle = fopen($captionFile, "rb");
    while (!$status && !feof($handle)) {
      $chunk = fread($handle, $chunkSizeBytes);
      $status = $media->nextChunk($chunk);
    }

    fclose($handle);

    // If you want to make other calls after the file upload, set setDefer back to false
    $client->setDefer(false);

    $htmlBody .= "<h2>Inserted video caption track for</h2><ul>";
    $captionSnippet = $status['snippet'];
    $htmlBody .= sprintf('<li>%s(%s) in %s language, %s status.</li>',
        $captionSnippet['name'], $status['id'], $captionSnippet['language'],
        $captionSnippet['status']);
    $htmlBody .= '</ul>';
}
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46
  • 1
    I have and it doesn't work. The problem with the sample code is that the file's don't upload and even if the upload functionality worked it still wouldn't do what I need, which is to automatically sync my caption files with my videos. – Tyler Steinhaus Jul 27 '15 at 12:57
3

I was able to reproduce this problem, and found a possible fix. The key was the content of the uploaded caption file. The hint was where it says in the documentation:

The sync parameter indicates whether YouTube should automatically synchronize the caption file with the audio track of the video. If you set the value to true, YouTube will disregard any time codes that are in the uploaded caption file and generate new time codes for the captions.

You should set the sync parameter to true if you are uploading a transcript, which has no time codes, or if you suspect the time codes in your file are incorrect and want YouTube to try to fix them.

The tweak that made it work for me was to add in some dummy time codes that I knew were incorrect, and set 'sync' => 'true', so that the YouTube service would correct them. For example, here is the .sbv file that did NOT work:

This is a sample video to test the YouTube API captioning system.

When I used this file I got the same error you did, i.e. Track content is not processed, but when I changed it to this it worked:

00:00:00,00:00:00
This is a sample video to test the YouTube API captioning system.

When I downloaded the processed .sbv file from YouTube it looked like this:

0:00:00.000,0:00:04.266
This is a sample video to test the YouTube
API captioning system.

Granted, I only tried this for a VERY trivial video, and I don't think they did a very good job with the timings, but hopefully it will scale up to work with your system.

Community
  • 1
  • 1
morphatic
  • 7,677
  • 4
  • 47
  • 61
  • 1
    This is interesting. I can get it to work with your video, using your method. But using the same method on any of my videos still fails. – Parker Kemp Aug 06 '15 at 14:07
  • 2
    sigh. I guess it would be asking too much for the API to actually do what it says it will do... At least you were able to get it to "process" your captions. Perhaps there's a way to fake it by estimating the approximate number of seconds per character/word, or using punctuation, to insert the dummy time codes. Of course that won't work if there are any places in the video where the narration pauses. – morphatic Aug 06 '15 at 16:10
  • 1
    Thank you for responding! I have tried this too and I can't even get it to tell me it's even processing. I really wish their API would just work like they advertise it in their documentation. – Tyler Steinhaus Aug 06 '15 at 18:08