Video media/upload - "unknown error" on FINALIZE step

android
video
media-upload

#1

Hi, I trying to upload video via the api and I got “unknown error” on FINALIZE step.
There is my code (Android/Java):

 TwitterSession session = Twitter.getSessionManager().getActiveSession();
 TwitterAuthToken authToken = session.getAuthToken();
 final TwitterVideoApiClient twitterVideoApiClient = new TwitterVideoApiClient(session);
 final MediaService twitterMediaService = twitterVideoApiClient.getMediaService();
 File video = new File(path);
 final TypedFile typedFile = new TypedFile("application/octet-stream", video);
 twitterVideoApiClient.videoUploadInitService().initialize("INIT", "video/mp4", String.valueOf(video.length()), new Callback<Media>()
 { 
    @Override
    public void success(Result<Media> result) {
      Log.d(GlobalShell.TAG_API, " 1st success. MediaIdString: " + result.data.mediaIdString);
      firstStepResult = result;
      twitterVideoApiClient.videoUploadAppendService().append("APPEND", firstStepResult.data.mediaIdString, 0, typedFile, new Callback<Twitter>() 
    {
        @Override
        public void success(Result<Twitter> result) {
           Log.d(GlobalShell.TAG_API, " 2nd success: " + result.response.getHeaders());
           twitterVideoApiClient.videoUploadFinalizeService().finalize("FINALIZE", firstStepResult.data.mediaIdString, true, new Callback<Twitter>() {
          
             @Override
             public void success(Result<Twitter> result) {
                Log.d(GlobalShell.TAG_API, " 3rd success: ");
             }

             @Override
             public void failure(TwitterException e) {
                Log.d(GlobalShell.TAG_API, " 3rd failure: " + e);
             }
        }
   
        @Override
        public void failure(TwitterException e) {
           Log.d(GlobalShell.TAG_API, " 2nd failure: " + e);
        }
    }
  
  @Override
  public void failure(TwitterException e) {
    Log.d(GlobalShell.TAG_API, " 1st failure: " + e);
 }
   });

And result:

   1st success. MediaIdString: 715026605408657409
   2nd success: [: HTTP/1.1 204 No Content ... ]
   3rd failure: com.twitter.sdk.android.core.TwitterApiException: unknown error

The TwitterVideoApiClient class:

public class TwitterVideoApiClient extends TwitterApiClient {

    private static final String TWITTER_UPLOAD_URL = "https://upload.twitter.com";
    private RestAdapter twitterVideoApiClientAdapter;

    public TwitterVideoApiClient(TwitterSession session) {

        super(session);

        final Gson gson = new GsonBuilder()
                .registerTypeAdapterFactory(new SafeListAdapter())
                .registerTypeAdapterFactory(new SafeMapAdapter())
                .create();

        SSLSocketFactory sslSocketFactory = TwitterCore.getInstance().getSSLSocketFactory();
        TwitterAuthConfig authConfig = TwitterCore.getInstance().getAuthConfig();
        ExecutorService executorService = TwitterCore.getInstance().getFabric()
                .getExecutorService();

        twitterVideoApiClientAdapter = new RestAdapter.Builder()
                .setClient(new AuthenticatedClient(authConfig, session, sslSocketFactory))
                .setEndpoint(TWITTER_UPLOAD_URL)
                .setConverter(new GsonConverter(gson))
                .setExecutors(executorService, new MainThreadExecutor())
                .build();
    }

    public TwitterUploadVideoInitService videoUploadInitService() {
        return twitterVideoApiClientAdapter.create(TwitterUploadVideoInitService.class);
    }

    public TwitterUploadVideoAppendService videoUploadAppendService() {
        return twitterVideoApiClientAdapter.create(TwitterUploadVideoAppendService.class);
    }

    public TwitterUploadVideoFinalizeService videoUploadFinalizeService() {
        return twitterVideoApiClientAdapter.create(TwitterUploadVideoFinalizeService.class);
    }

    public interface TwitterUploadVideoInitService {
        @FormUrlEncoded()
        @POST("/1.1/media/upload.json")
        void initialize(@Field("command") String command,
                        @Field("media_type") String mediaType,
                        @Field("total_bytes") String totalBytes,
                        Callback<Media> callback)   ;
    }

    public interface TwitterUploadVideoAppendService {
        @Multipart
        @POST("/1.1/media/upload.json")
        void append(@Part("command") String command,
                    @Part("media_id") String mediaId,
                    @Part("segment_index") int segmentIndex,
                    @Part("media") TypedFile media,
                    Callback<Twitter> callback);
    }

    public interface TwitterUploadVideoFinalizeService {
        @FormUrlEncoded()
        @POST("/1.1/media/upload.json")
        void finalize(@Field("command") String command,
                      @Field("media_id") String mediaId,
                      @Field("allow_async") Boolean allow_async,
                      Callback<Twitter> callback);
    }

}

Upload video properties:

 result_0.mp4
   General
      Complete name : result_0.mp4
      Format : MPEG-4
      Format profile : Base Media
      Codec ID : isom
      File size : 624 KiB
      Duration : 5s 805ms
      Overall bit rate : 880 Kbps
      Writing application : Lavf56.4.101
   Video #1
      ID : 1
      Format : AVC
      Format/Info : Advanced Video Codec
      Format profile : High@L2.1
      Format settings, CABAC : Yes
      Format settings, ReFrames : 4 frames
      Codec ID : avc1
      Codec ID/Info : Advanced Video Coding
      Duration : 5s 805ms
      Bit rate : 878 Kbps
      Nominal bit rate : 800 Kbps
      Width : 514 pixels
      Height : 362 pixels
      Display aspect ratio : 1.000
      Frame rate mode : Constant
      Frame rate : 0.861 fps
      Color space : YUV
      Chroma subsampling : 4:2:0
      Bit depth : 8 bits
      Scan type : Progressive
      Bits/(Pixel*Frame) : 5.484
      Stream size : 623 KiB (100%)
      Writing library : x264 core 142
      Encoding settings : cabac=1 / ref=3 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=6 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=1 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=abr / mbtree=1 / bitrate=800 / ratetol=1.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
      Color range : Full

Can you help me and tell where did I go wrong?
Thanks for your help!


#2

@inkyzify could you post the video file?


#3

@tushargj Thanks for reply. I don’t know how to post here my video file (because only jpg, jpeg, png, gif are supported). You can download the video via this link (video). If it can help you, when I’ve tried to upload the video via twitter web site it was successfully.


#4

@inkyzify Thanks for source file. There is nothing wrong with video file. Are you able to reproduce this consistently? If yes then please could you provide example of failed mediaId(s)?


#5

@tushargj There are some mediaId(s) which were failed on “finalize” step - 718353332016934912, 718354562072059904, 718354628954439681.


#6

Hi I am also facing the same issue…I am getting the error “HTTP status 400” on FINALIZE step for Image uploading …Is it solved?

Thanks
Fab


#7

@fab52909126 Please could you provide a link to the source image? Media api may return 400 if image is not valid or supported.


#8

Image properties:
type/format :jpeg
size :87kb
resolution: 517*322
name: baby.jpg

Can you help me and tell where did I go wrong?
Thanks for your help!


#9

Can you actually provide a link to the original image for us to download and examine? thank you.


#10

Hi ,
Uploded the image file here.
What parameter should be passed as “media” in APPEND command…byte array or RequestBody or TypedFile ?
Thanks in advance…


#11

Hi
Still I could not upload the image using INIT,APPEND and FINALIZE command.
Bit I can upload the same image using simple image upload command.
Please tell me what wrong i am doing?

Thanks in advance