2017年5月8日 星期一

讓youtbe可以分享播放聯結

http://stackoverflow.com/questions/11178041/android-youtube-share-a-youtube-video-to-my-app

This worked for me. Add this intent filter to your manifest file to make your application appear in the share list of the youtube application.
<intent-filter>
   <action android:name="android.intent.action.SEND" />
   <category android:name="android.intent.category.DEFAULT" />              
   <data android:host="www.youtube.com" android:mimeType="text/*" />
</intent-filter>

2017年4月15日 星期六

JAVA Google speech recognition

  private HttpURLConnection makeConnection(
      URL url,
      byte[] postBody,
      long position,
      long length,
      boolean allowGzip,
      boolean followRedirects) throws IOException
{

setRequestProperty



https://zh.wikipedia.org/wiki/FLAC





https://docs.python.org/2/library/subprocess.html




 temp = tempfile.NamedTemporaryFile(suffix='.wav', delete=False)
https://docs.python.org/2/library/tempfile.html


tempfile.NamedTemporaryFile([mode='w+b'[bufsize=-1[suffix=''[prefix='tmp'[dir=None[delete=True]]]]]])
This function operates exactly as TemporaryFile() does, except that the file is guaranteed to have a visible name in the file system (on Unix, the directory entry is not unlinked). That name can be retrieved from the name attribute of the returned file-like object. Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows NT or later). If delete is true (the default), the file is deleted as soon as it is closed.
The returned object is always a file-like object whose file attribute is the underlying true file object. This file-like object can be used in a with statement, just like a normal file.
New in version 2.3.
New in version 2.6: The delete parameter.





http://writingminds.github.io/ffmpeg-android-java/

2017年4月14日 星期五

autosub

https://github.com/agermanidis/autosub#autosub--


Install AutoSub Step to Step in Windows with Translate subtitle

https://github.com/agermanidis/autosub/issues/31


commands:
autosub_app.py -S zh-TW -D zh-TW sea.mp4

Google 语音识别 API (Part 2)
http://blog.laobubu.net/archivers/google-speech-api-pt2

2017年4月1日 星期六

canvas

http://www.jianshu.com/p/336f90f0026f


drawRect
https://developer.android.com/reference/android/graphics/Canvas.html#drawRect(float, float, float, float, android.graphics.Paint)



12down voteaccepted
From the Android documentation - protected void dispatchDraw (Canvas canvas):
Called by draw to draw the child views. This may be overridden by derived classes to gain control just before its children are drawn (but after its own view has been drawn).


SimpleDecoder, textRenderer, SimpleSubtitleDecoder & WebVtt

https://www.draw.io/ 

WebVTT cue timestamp consists of a U+003C LESS-THAN SIGN character (<), followed by a WebVTT timestamp representing the time that the given point in the cue becomes active, followed by a U+003E GREATER-THAN SIGN character (>). The time represented by the WebVTT timestamp must be greater than the times represented by any previous WebVTT cue timestamps in the cue, as well as greater than the cue’s start time offset, and less than the cue’s end time offset.


textLayout = new StaticLayout(cueText, textPaint, availableWidth, textAlignment, spacingMult,
        spacingAdd, true);








2017年3月30日 星期四

webvtt format

https://dev.opera.com/articles/zh-cn/an-introduction-to-webvtt-and-track/

https://developer.mozilla.org/zh-TW/docs/Web/API/Web_Video_Text_Tracks_Format


時間標籤
  • 時間標籤中的時間,必須比該節點的開始時間晚、比同節點先前之其他時間標籤晚,並且早於該節點的結束時間。 當前文字(active text) 代表此時間標籤到下個時間標籤(或文字內容的結尾)之間的文字,其他同節點中,比 當前文字 早的文字都稱為 先前文字(previous text) ,而晚於 當前文字 的便稱為 未來文字(future text) 。如此便可做出卡拉OK字幕效果
Example 12 - Karaoke style text
1
00:16.500 --> 00:18.500
When the moon <00:17.500>hits your eye

1
00:00:18.500 --> 00:00:20.500
Like a <00:19.000>big-a <00:19.500>pizza <00:20.000>pie

1
00:00:20.500 --> 00:00:21.500
That's <00:00:21.000>amore


When this specification says that a user agent is to collect a WebVTT timestamp, the user agent must run the following steps:
  1. Let input and position be the same variables as those of the same name in the algorithm that invoked these steps.
  2. Let most significant units be minutes.
  3. If position is past the end of input, return an error and abort these steps.
  4. If the character indicated by position is not an ASCII digit, then return an error and abort these steps.
  5. Collect a sequence of characters that are ASCII digits, and let string be the collected substring.
  6. Interpret string as a base-ten integer. Let value1 be that integer.
  7. If string is not exactly two characters in length, or if value1 is greater than 59, let most significant units be hours.
  8. If position is beyond the end of input or if the character at position is not a U+003A COLON character (:), then return an error and abort these steps. Otherwise, move position forwards one character.
  9. Collect a sequence of characters that are ASCII digits, and let string be the collected substring.
  10. If string is not exactly two characters in length, return an error and abort these steps.
  11. Interpret string as a base-ten integer. Let value2 be that integer.
  12. If most significant units is hours, or if position is not beyond the end of input and the character at position is a U+003A COLON character (:), run these substeps:
    1. If position is beyond the end of input or if the character at position is not a U+003A COLON character (:), then return an error and abort these steps. Otherwise, move position forwards one character.
    2. Collect a sequence of characters that are ASCII digits, and let string be the collected substring.
    3. If string is not exactly two characters in length, return an error and abort these steps.
    4. Interpret string as a base-ten integer. Let value3 be that integer.
    Otherwise (if most significant units is not hours, and either position is beyond the end of input, or the character at position is not a U+003A COLON character (:)), let value3 have the value of value2, then value2have the value of value1, then let value1 equal zero.
  13. If position is beyond the end of input or if the character at position is not a U+002E FULL STOP character (.), then return an error and abort these steps. Otherwise, move position forwards one character.
  14. Collect a sequence of characters that are ASCII digits, and let string be the collected substring.
  15. If string is not exactly three characters in length, return an error and abort these steps.
  16. Interpret string as a base-ten integer. Let value4 be that integer.
  17. If value2 is greater than 59 or if value3 is greater than 59, return an error and abort these steps.
  18. Let result be value1×60×60 + value2×60 + value3 + value4∕1000.
  19. Return result.






https://www.w3.org/community/texttracks/2013/09/11/carriage-of-webvtt-and-ttml-in-mp4-files/


By default, the line is set to auto.




A line
The line defines positioning of the cue box.
The line offsets the cue box from the top, the right or left of the video viewport as defined by the writing direction, the snap-to-lines flag, or the lines occupied by any other showing tracks.
The line is set either as a number of lines, a percentage of the video viewport height or width, or as the special value auto, which means the offset is to depend on the other showing tracks.
By default, the line is set to auto.
If the writing direction is horizontal, then the line percentages are relative to the height of the video, otherwise to the width of the video.
WebVTT cue has a computed line whose value is that returned by the following algorithm, which is defined in terms of the other aspects of the cue:
  1. If the line is numeric, the WebVTT cue snap-to-lines flag of the WebVTT cue is false, and the line is negative or greater than 100, then return 100 and abort these steps.
    Although the WebVTT parser will not set the line to a number outside the range 0..100 and also set the WebVTT cue snap-to-lines flag to false, this can happen when using the DOM API’s snapToLines and line attributes.
  2. If the line is numeric, return the value of the WebVTT cue line and abort these steps. (Either the WebVTT cue snap-to-lines flag is true, so any value, not just those in the range 0..100, is valid, or the value is in the range 0..100 and is thus valid regardless of the value of that flag.)
  3. If the WebVTT cue snap-to-lines flag of the WebVTT cue is false, return the value 100 and abort these steps. (The line is the special value auto.)
  4. Let cue be the WebVTT cue.
  5. If cue is not in a list of cues of a text track, or if that text track is not in the list of text tracks of a media element, return −1 and abort these steps.
  6. Let track be the text track whose list of cues the cue is in.
  7. Let n be the number of text tracks whose text track mode is showing and that are in the media element’s list of text tracks before track.
  8. Increment n by one.
  9. Negate n.
  10. Return n.






A line alignment
An alignment for the cue box’s line, one of:
Start alignment
The cue box’s top side (for horizontal cues), left side (for vertical growing right), or right side (for vertical growing left) is aligned at the line.
Center alignment
The cue box is centered at the line.
End alignment
The cue box’s bottom side (for horizontal cues), right side (for vertical growing right), or left side (for vertical growing left) is aligned at the line.
By default, the line alignment is set to start.
The line alignment is separate from the text alignment — right-to-left vs. left-to-right cue text does not affect the line alignment.

2017年1月25日 星期三

2017年1月10日 星期二

Potential race condition issue of GStreamer


It is the issue report & proposed patch description for GStreamer; as the link below.

https://bugzilla.gnome.org/show_bug.cgi?id=777206




fig 1: download loop thread













fig 2: update loop thread



fig 3: base source thread

[Test URL & settings]:

[Issue]: 

Wrong codec settings leads to mosaic (ex, use the codec setting of high bit-rate representation to decode data of low bit-rate representation ).


[Root cause]: 

1. Race condition between threads.
2. Slow start of gst_mpd_client_setup_streaming() when updating manifest.


[Background]

Generally we have three kinds of threads within adaptive demuxer for a live (type = dynamical) streaming; they are listed below.
1. download thread: 
The flow controller to update fragment info, wait until the target fragment is available, create base source thread to download, wait for completeness, check EOS. 
2. update loop thread:
Update manifest according "minimumUpdatePeriod".
3. base source thread:
Actually download bit-stream of each fragment (segment).


[Detailed description]: 

Please refer to fig 4, an issued case is illustrated to understand where the problem arises.

Originally the representation is of 250000 bits/sec. Then the update loop thread locks the manifest_lock and by default launches from slow start (the lowest bit-stream) upon the updated manifest. It makes cur_representation to be of 125000 bits/sec.

After update done, manifest_lock is unlocked.
Since the download loop thread is still waiting for the signal from src thread to inform the completeness of download, the next thread which will get manifest_lock is src thread. 

At _src_event when src thread has completed download, gst_adaptive_demux_eos_handling() is executed with manifest_lock locked.

At B.4 gst_adaptive_demux_stream_advance_fragment_unlocked() is executed & the next download bit-rate is set to 125000 bits/sec. At B.7 gst_adaptive_demux_stream_select_bitrate() (in fact, gst_dash_demux_stream_select_bitrate ()) the check of "if (new_index != active_stream->representation_idx)" is false. It is because that the slow start of update manifest has changed active_stream->representation_idx to the lowest one. As the result, the new caps as well as the Boolean variable need_header will NOT be set. It makes the switch of bit-rate without re-passing necessary codec data.

Finally, it leads to mosaic by applying wrong codec data (of 250000 bits/sec) to decode 125000 bits/sec. As at C1 where the next URL is composed of the lowest bit-rate = 125000 but we do NOT pass codec data & header down for this bit-rate switch .







fig 4: an issued case


[Proposed solution]:

As fig 1 & fig 5, to download next fragment, at first download loop thread will update fragment info (by gst_adaptive_demux_stream_update_fragment_info()). It results in the update to 
stream->fragment of the type GstAdaptiveDemuxStreamFragment which includes the URI info.

Once GstAdaptiveDemuxStreamFragment has been updated, it will NOT be changed. To take use of this fact, we keep the bit-rate we have downloaded previously and compare it to current target. If they are different, we pass the info of header & caps down.

To avoid passing redundant header & caps, we only do the check if 
1. It is a live (type = dynamic) streaming.
2. If the "stream->need_header == FALSE" is TRUE.

Finally as figure 6, within gst_dash_demux_stream_update_fragment_info(), the bit-rate of current chosen representation could be known from: dashstream->active_stream->cur_representation->bandwidth.



 

Fig 5: Relationship of GstAdaptiveDemuxStream, GstActiveStream & GstRepresentationNode.

















Fig 6: How could we get bit-rate of current target fragment within gst_dash_demux_stream_update_fragment_info()



[1st Review]:

as reviewer's kindly suggestion:
This should be done not only when the bitrate changed but whenever the stream (representation) was changed

Also, according to ISO 23009-1:
specifies an identifier for this Representation. The identifier shall be unique within a Period unless the Representation is functionally identically to another Representation in the same Period.
s