TS recording h264 annex-B compliance

Discussion in 'ZIDOO X9' started by danman, Dec 6, 2015.

  1. danman

    danman Member

    Hello zidoo team,

    I tried to write an app that will stream the tail of recorded TS file to network.
    When I tried to play the stream, sound was playing OK but no video was shown. I found out that the player don't have the metadata (SPS, PPS, because they are probably only in the begginning of the file) so it doesn't know how to decode the h264 bitstream.

    Could you fix the firmware of zidoo to record annex-B compliant recordings? Or is there any way how to force compliant format (e.g. by native_set_output_format method)?

    Thanks.
     
  2. warren_wh

    warren_wh Active Member Staff Member Zidoo TECH Supporter

  3. danman

    danman Member

    Yes. I'm referring to the source code.

    So my first question is what output formats can be set by native_set_output_format?
    2 - mp4
    8 - ts
    What are the other options from 0 to 8?
    Thanks.
     
  4. danman

    danman Member

    I managed to compile and sign my own application based on the published source code. I want to make live streaming from zidoo possible.

    Can you please provide the info about formats?

    Or can't publish header or source file concerning output format definition?

    Thanks.
     
  5. danman

    danman Member

  6. On the source code (PipService.java) you can see:

    case 0:// 640x480pw = 640;
    h = 480;
    break;
    case 1:// 720x480icase 3:// 720x480pw = 720;
    h = 480;
    break;
    case 2:// 720x576i
    case 4:// 720x576pw = 720;
    h = 576;
    break;
    case 5:// 1280x720p_50Hz
    case 6:// 1280x720p_60Hzw = 1280;
    h = 720;
    break;
    case 7:// 1920x1080i_50Hz
    case 8:// 1920x1080i_60Hz
    case 9:// 1920x1080p_24Hz
    case 10:// 1920x1080p_25Hz
    case 11:// 1920x1080p_30Hz
    case 12:// 1920x1080p_50Hz
    case 13:// 1920x1080p_60Hzw = 1920;
    h = 1080;
    break;
    case 15:// 1280x1470p_50Hz
    case 16:// 1280x1470p_60Hz
    case 17:// 1280x1470p_24Hz
    case 18:// 1280x1470p_30Hzw = 1280;
    h = 1470;
    break;
    case 19:// 1920x2205p_24Hz
    case 20:// 1920x2205p_30Hzw = 1920;
    h = 2205;
    break;
    case 14:// 4K2Kp_30Hz
    case 21:// 4K2Kp_25Hz
    case 22:// 4K2Kp_24Hz
    case 23:// 4K2Kp_50Hz
    case 24:// 4K2Kp_60Hzw = 4096;
    h = 2160;
    break;
    case 25:// MAXw = 1920;
    h = 1080;
    break;
     
  7. danman

    danman Member

    No, I think this is not related... Because 2 has to mean mp4 and 8 has to mean TS
     
  8. Yeh! You were right!

    From the mstar pkg, MMediaPlayer.java:

    private static final int DATASOURCE_ES_VIDEO_CODEC_UNKNOW = -1;
    private static final int DATASOURCE_ES_VIDEO_CODEC_MPEG1VIDEO = 0;
    private static final int DATASOURCE_ES_VIDEO_CODEC_MPEG2VIDEO = 1;
    private static final int DATASOURCE_ES_VIDEO_CODEC_MPEG4 = 2;
    private static final int DATASOURCE_ES_VIDEO_CODEC_H263 = 3;
    private static final int DATASOURCE_ES_VIDEO_CODEC_DIVX3 = 4;
    private static final int DATASOURCE_ES_VIDEO_CODEC_DIVX4 = 5;
    private static final int DATASOURCE_ES_VIDEO_CODEC_DIVX = 6;
    private static final int DATASOURCE_ES_VIDEO_CODEC_H264 = 7;
    private static final int DATASOURCE_ES_VIDEO_CODEC_AVS = 8;
    private static final int DATASOURCE_ES_VIDEO_CODEC_RV30 = 9;
    private static final int DATASOURCE_ES_VIDEO_CODEC_RV40 = 10;
    private static final int DATASOURCE_ES_VIDEO_CODEC_MJPEG = 11;
    private static final int DATASOURCE_ES_VIDEO_CODEC_VC1 = 12;
    private static final int DATASOURCE_ES_VIDEO_CODEC_WMV3 = 13;
    private static final int DATASOURCE_ES_VIDEO_CODEC_FLV = 14;
    private static final int DATASOURCE_ES_VIDEO_CODEC_FOURCCEX = 15;
    private static final int DATASOURCE_ES_VIDEO_CODEC_TS = 16;
     
  9. danman

    danman Member

    Wow! Where did you get these? Do you have full mstar sources?
     
  10. danman

    danman Member

    Oh, I see now... But I'm not completely sure this is it...
     
  11. You just need to check if the codec used for the TS files are, indeed, CODEC_AVS

    About the code, I do not have the mstar codes. I just reversed engineered the lib.

    Regards!
     
  12. danman

    danman Member

    my findings in attachment
     

    Attached Files:

  13. Well, based on your findings, looks like the error is trow by the Android´s MediaRecorder class:

    https://android.googlesource.com/pl...r/media/java/android/media/MediaRecorder.java

    publicstaticfinalint DEFAULT =0;

    /** 3GPP media file format*/
    publicstaticfinalint THREE_GPP =1;
    /** MPEG4 media file format*/
    publicstaticfinalint MPEG_4 =2;

    /** The following formats are audio only .aac or .amr formats */
    /**
    * AMR NB file format
    * @deprecated Deprecated in favor of MediaRecorder.OutputFormat.AMR_NB
    */
    publicstaticfinalint RAW_AMR =3;
    /** AMR NB file format */
    publicstaticfinalint AMR_NB =3;
    /** AMR WB file format */
    publicstaticfinalint AMR_WB =4;
    /** @hide AAC ADIF file format */
    publicstaticfinalint AAC_ADIF =5;
    /** AAC ADTS file format */
    publicstaticfinalint AAC_ADTS =6;
    /** @hide Stream over a socket, limited to a single stream */
    publicstaticfinalint OUTPUT_FORMAT_RTP_AVP =7;
    /** @hide H.264/AAC data encapsulated in MPEG2/TS */
    publicstaticfinalint OUTPUT_FORMAT_MPEG2TS =8;
    /** VP8/VORBIS data in a WEBM container */
    publicstaticfinalint WEBM =9;
     
  14. I believe this is what you were looking for:

    /** @hide Stream over a socket, limited to a single stream */
    publicstaticfinalint OUTPUT_FORMAT_RTP_AVP =7;
     
  15. danman

    danman Member

    yes, that might be possible, but I don't see any option how to disable sound in stream and moreover I doubt that the output stream would contain SPS and PPS packets required to join the stream anytime. Now the TS stream contains these only in the begginning according to analysis in attachment.

    The only option to create compliant TS stream is to decode the input and insert TS packets with SPS and PPS according to annnexB which will take some time.
     

    Attached Files:

  16. And you can´t do it with the mp4 itself?
     
  17. danman

    danman Member

    no, because mp4 stream description (moov atom) is written only after recording is finished.
     
  18. danman

    danman Member

    Ok, it probably won't be as painful as i thought. Some of my first experiments were to read recorded file with ffmpeg in console on zidoo and stream it as mpegts like this:
    ./ffmpeg -i HdmiRecorder/video* -vcodec copy -acodec copy -f mpegts udp://239.255.0.1:1234
    but it didn't work because the output stream didn't contain SPS,PPS either.

    Today I tried the same on my linux box and the output stream has SPS and PPS before each I (key) frame!!! I used some old ffmpeg binary I found on the net back then so I guess that if I compile latest ffmpeg for zidoo (armv7 or so) it will work. I'll compile it now and test during weekend because I don't have zidoo on hand. Or you can try it...
     

Share This Page