Note that there are some explanatory texts on larger screens.

plurals
  1. POyoutube - video upload failure - unable to convert file - encoding the video wrong?
    text
    copied!<p>I am using .NET to create a video uploading application. Although it's communicating with YouTube and uploading the file, the processing of that file fails. YouTube gives me the error message, "Upload failed (unable to convert video file)." This supposedly means that "your video is in a format that our converters don't recognize..."</p> <p>I have made attempts with two different videos, both of which upload and process fine when I do it <em>manually</em>. So I suspect that my code is a.) not encoding the video properly and/or b.) not sending my API request properly.</p> <p>Below is how I am constructing my API PUT request and encoding the video:</p> <p>Any suggestions on what the error could be would be appreciated.</p> <p>Thanks</p> <p>P.S. I'm not using the client library because my application will use the resumable upload feature. Thus, I am manually constructing my API requests.</p> <p>Documentation: <a href="http://code.google.com/intl/ja/apis/youtube/2.0/developers_guide_protocol_resumable_uploads.html#Uploading_the_Video_File" rel="nofollow noreferrer">http://code.google.com/intl/ja/apis/youtube/2.0/developers_guide_protocol_resumable_uploads.html#Uploading_the_Video_File</a></p> <p>Code:</p> <pre><code> // new PUT request for sending video WebRequest putRequest = WebRequest.Create(uploadURL); // set properties putRequest.Method = "PUT"; putRequest.ContentType = getMIME(file); //the MIME type of the uploaded video file //encode video byte[] videoInBytes = encodeVideo(file); public static byte[] encodeVideo(string video) { try { byte[] fileInBytes = File.ReadAllBytes(video); Console.WriteLine("\nSize of byte array containing " + video + ": " + fileInBytes.Length); return fileInBytes; } catch (Exception e) { Console.WriteLine("\nException: " + e.Message + "\nReturning an empty byte array"); byte [] empty = new byte[0]; return empty; } }//encodeVideo //encode custom headers in a byte array byte[] PUTbytes = encode(putRequest.Headers.ToString()); public static byte[] encode(string headers) { ASCIIEncoding encoding = new ASCIIEncoding(); byte[] bytes = encoding.GetBytes(headers); return bytes; }//encode //entire request contains headers + binary video data putRequest.ContentLength = PUTbytes.Length + videoInBytes.Length; //send request - correct? sendRequest(putRequest, PUTbytes); sendRequest(putRequest, videoInBytes); public static void sendRequest(WebRequest request, byte[] encoding) { Stream stream = request.GetRequestStream(); // The GetRequestStream method returns a stream to use to send data for the HttpWebRequest. try { stream.Write(encoding, 0, encoding.Length); } catch (Exception e) { Console.WriteLine("\nException writing stream: " + e.Message); } }//sendRequest </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload