seek

How does Python's seek function work?

元气小坏坏 提交于 2019-12-22 05:18:04
问题 If I have some file-like object and do the following: F = open('abc', 'r') ... loc = F.tell() F.seek(loc-10) What does seek do? Does is start at the beginning of the file and read loc-10 bytes? Or is it smart enough just to back up 10 bytes? 回答1: It is OS- and libc-specific. the file.seek() operation is delegated to the fseek(3) C call for actual OS-level files. 回答2: According to Python 2.7's docs: file.seek(offset[, whence]) Set the file’s current position, like stdio‘s fseek(). The whence

Android Precise seeking of video

 ̄綄美尐妖づ 提交于 2019-12-21 02:14:10
问题 I'm struggling with precise seeking using MediaExtractor's seekTo() . While I can seek to sync frames without problems, I would like to seek to specific time. This question led me to some ideas how to do this, but I'm not sure if they are valid. Basicly, I would have to seek to closest previous sync frame and then advance() the extractor until target time is reached. Every frame in the process would be fed to the decoder, i.e the first I-frame and the rest P-frames. This is related code

f.seek() and f.tell() to read each line of text file

a 夏天 提交于 2019-12-19 07:29:22
问题 I want to open a file and read each line using f.seek() and f.tell() : test.txt: abc def ghi jkl My code is: f = open('test.txt', 'r') last_pos = f.tell() # get to know the current position in the file last_pos = last_pos + 1 f.seek(last_pos) # to change the current position in a file text= f.readlines(last_pos) print text It reads the whole file. 回答1: ok, you may use this: f = open( ... ) f.seek(last_pos) line = f.readline() # no 's' at the end of `readline()` last_pos = f.tell() f.close()

Python file.tell gives wrong value location

蹲街弑〆低调 提交于 2019-12-18 17:11:36
问题 I am trying to extract a number of locations from an existing file using Python. This is my current code for extracting the locations: self.fh = open( fileName , "r+") p = re.compile('regGen regPorSnip begin') for line in self.fh : if ( p.search(line) ): self.porSnipStartFPtr = self.fh.tell() sys.stdout.write("found regPorSnip") This snippet is repeated a number of times (less the file open) with different search values, and seems to work: I get the correct messages, and the variables have

How can I seek to frame No. X with ffmpeg?

廉价感情. 提交于 2019-12-18 11:29:53
问题 I'm writing a video editor , and I need to seek to exact frame, knowing the frame number . Other posts on stackoverflow told me that ffmpeg may give me a few broken frames after seeking, which is not a problem for playback but a big problem for video editors. And I need to seek by frame number , not by time, which will become inaccurate when converted to frame number. I've read dranger's tuts (which is outdated now), and end up with: av_seek_frame(fmt_ctx, video_stream_id, frame, AVSEEK_FLAG

Android SeekBar to control MediaPlayer progress

╄→гoц情女王★ 提交于 2019-12-18 10:52:58
问题 I have a SeekBar , it displays correctly MediaPlayer progress. However, I have troubles with seeking - if I seek scroll box somewhere it just returns on the position where audio file is playing. public class EntityPageActivity extends Activity implements Runnable, OnClickListener, OnSeekBarChangeListener{ private SeekBar seekBar; private Button startMedia; private Button pauseMedia; private MediaPlayer mp; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate

Python: rewinding one line in file when iterating with f.next()

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 07:39:26
问题 Python's f.tell doesn't work as I expected when you iterate over a file with f.next(): >>> f=open(".bash_profile", "r") >>> f.tell() 0 >>> f.next() "alias rm='rm -i'\n" >>> f.tell() 397 >>> f.next() "alias cp='cp -i'\n" >>> f.tell() 397 >>> f.next() "alias mv='mv -i'\n" >>> f.tell() 397 Looks like it gives you the position of the buffer rather than the position of what you just got with next(). I've previously used the seek/tell trick to rewind one line when iterating over a file with

How to write at a particular position in text file without erasing original contents?

守給你的承諾、 提交于 2019-12-18 07:04:27
问题 I've written a code in Python that goes through the file, extracts all numbers, adds them up. I have to now write the 'total' (an integer) at a particular spot in the file that says something something something...Total: __00__ something something . I have to write the total that I have calculated exactly after the Total: __ part which would mean the resulting line would change to, for example: something something something...Total: __35__ something something . So far I have this for the

Python seek on remote file using HTTP

血红的双手。 提交于 2019-12-17 15:51:50
问题 How do I seek to a particular position on a remote (HTTP) file so I can download only that part? Lets say the bytes on a remote file were: 1234567890 I wanna seek to 4 and download 3 bytes from there so I would have: 456 and also, how do I check if a remote file exists? I tried, os.path.isfile() but it returns False when I'm passing a remote file url. 回答1: If you are downloading the remote file through HTTP, you need to set the Range header. Check in this example how it can be done. Looks

Python seek on remote file using HTTP

三世轮回 提交于 2019-12-17 15:51:33
问题 How do I seek to a particular position on a remote (HTTP) file so I can download only that part? Lets say the bytes on a remote file were: 1234567890 I wanna seek to 4 and download 3 bytes from there so I would have: 456 and also, how do I check if a remote file exists? I tried, os.path.isfile() but it returns False when I'm passing a remote file url. 回答1: If you are downloading the remote file through HTTP, you need to set the Range header. Check in this example how it can be done. Looks