codec

Open() and codecs.open() in Python 2.7 behave strangely different

吃可爱长大的小学妹 提交于 2019-11-28 04:03:34
问题 I have a text file with first line of unicode characters and all other lines in ASCII. I try to read the first line as one variable, and all other lines as another. However, when I use the following code: # -*- coding: utf-8 -*- import codecs import os filename = '1.txt' f = codecs.open(filename, 'r3', encoding='utf-8') print f names_f = f.readline().split(' ') data_f = f.readlines() print len(names_f) print len(data_f) f.close() print 'And now for something completely differerent:' g = open

Print to UTF-8 encoded file, with platform-dependent newlines?

巧了我就是萌 提交于 2019-11-28 02:56:40
问题 In Python, what is the best way to write to a UTF-8 encoded file with platform-dependent newlines? the solution would ideally work quite transparently in a program that does a lot of printing in Python 2. (Information about Python 3 is welcome too!) In fact, the standard way of writing to a UTF-8 file seems to be codecs.open('name.txt', 'w'). However, the documentation indicates that (…) no automatic conversion of '\n' is done on reading and writing. because the file is actually opened in

Can't open video using opencv

坚强是说给别人听的谎言 提交于 2019-11-27 20:42:12
The opencv works fine when doing other things. It can open images and show images. But it can't open a video. The code I'm using to open a video is as below import cv2 cap = cv2.VideoCapture("MOV_0006.mp4") while True: ret, frame = cap.read() cv2.imshow('video', frame) if cv2.waitKey(1) & 0xff == ord('q'): break cap.release() cv2.destroyAllWindows() But when executing, it outputs error messages like below [h264 @ 0x1053ba0] AVC: nal size 554779904 [h264 @ 0x1053ba0] AVC: nal size 554779904 [h264 @ 0x1053ba0] no frame! My vlc and mplayer can play this video, but the opencv can't. I have

Difference between open and codecs.open in Python

自古美人都是妖i 提交于 2019-11-27 17:29:08
There are two ways to open a text file in Python: f = open(filename) And import codecs f = codecs.open(filename, encoding="utf-8") When is codecs.open preferable to open ? Luciano Ramalho Since Python 2.6, a good practice is to use io.open() , which also takes an encoding argument, like the now obsolete codecs.open() . In Python 3, io.open is an alias for the open() built-in. So io.open() works in Python 2.6 and all later versions, including Python 3.4. See docs: http://docs.python.org/3.4/library/io.html Now, for the original question: when reading text (including "plain text", HTML, XML and

what is the codec for mp4 videos in python OpenCV

╄→гoц情女王★ 提交于 2019-11-27 14:49:14
问题 fourcc = cv2.cv.CV_FOURCC(*'XVID') The above line is used for avi video. In the same fashion, which codec do we use for mp4 videos in Ubuntu? 回答1: The codec is H.264. One of these should work for you: fourcc = cv2.cv.CV_FOURCC(*'H264') #or #fourcc = cv2.cv.CV_FOURCC(*'X264') However, I should warn you that you'll probably need to have ffmpeg and the x264 libraries installed so since you are in Ubuntu, try doing this command in the terminal : sudo apt-get install ffmpeg x264 libx264-dev Also,

How to decode AAC audio buffer to PCM buffer in iOS? [closed]

最后都变了- 提交于 2019-11-27 14:33:31
I am trying to decode AAC audio to PCM audio in iOS, what the best way to do this?Any sample code would be very helpful...Is there any simple APIs to do this..? I have sample code to do it. At start you should configure in/out ASBD (AudioStreamBasicDescription) and create converter: - (void)setupAudioConverter{ AudioStreamBasicDescription outFormat; memset(&outFormat, 0, sizeof(outFormat)); outFormat.mSampleRate = 44100; outFormat.mFormatID = kAudioFormatLinearPCM; outFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger; outFormat.mBytesPerPacket = 2; outFormat.mFramesPerPacket = 1;

Illegal State Exception when calling MediaCodec.configure()

柔情痞子 提交于 2019-11-27 13:33:16
问题 I get the IllegalStateException on MediaCodec.configure() line, I'm trying to record audio using MediaCodec. This only occur on some phones, on tabs everything is fine. This particular crash example is from Samsung Galaxy S4. Exception traces: 01-22 17:33:38.379: V/ACodec(16541): [OMX.google.aac.decoder] Now Loaded 01-22 17:33:38.379: V/ACodec(16541): onConfigureComponent 01-22 17:33:38.379: W/ACodec(16541): [OMX.google.aac.decoder] Failed to set standard component role 'audio_encoder.aac'.

Android encoder muxer: raw h264 to mp4 container

泪湿孤枕 提交于 2019-11-27 12:34:48
问题 I created a h264 raw video file, and I was able to mux it with Android MediaMuxer on Android 4.3 and up. Now I need to support Android versions 4.1 and 4.2. I found Jcodec. And there is an example for doing this: https://github.com/jcodec/jcodec/blob/master/samples/main/java/org/jcodec/samples/mux/AVCMP4Mux.java But I'm getting java.nio.ReadOnlyBufferException exception at line 70: H264Utils.encodeMOVPacket(data); I guess this code is not for Android? How do I fix this. Can someone familiar

What is video timescale, timebase, or timestamp in ffmpeg? [closed]

夙愿已清 提交于 2019-11-27 11:35:14
There does not seem to be any explanation online as to what these are. People talk about them a lot. I just want to know what they are and why they are significant. Using -video_track_timescale, how would I determine a number for it? Is it random? Should it be 0? Modern containers govern the time component of presentation of video (and audio) frames using timestamps, rather than framerate. So, instead of recording a video as 25 fps, and thus implying that each frame should be drawn 0.04 seconds apart, they store a timestamp for each frame e.g. Frame pts_time 0 0.00 1 0.04 2 0.08 3 0.12 ... For

ffmpeg convert mov file to mp4 for HTML5 video tag IE9

大兔子大兔子 提交于 2019-11-27 08:59:37
问题 I looked everywhere here and on google - there is no valid command that works for IE9. some how IE9 is missing something. All that I tried worked everywhere else: chrome,safari,mobile device etc... I want one command that will convert it and I can use it in every device suppose to support mp4 in HTML5 video tag. I use this commands: ffmpeg -i movie.mov -vcodec copy -acodec copy out.mp4 ffmpeg -i movie.mov -vcodec libx264 -vprofile high -preset slow -b:v 500k -maxrate 500k -bufsize 1000k -vf