I am trying to encode using
-(NSString *)urlEncodeUsingEncoding:(NSStringEncoding)encoding {
return ( NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,
(CFStringRef)self,
NULL,
(CFStringRef)#"!*'\"();:#&=+$,/?%#[]%£",
CFStringConvertNSStringEncodingToEncoding(encoding));
}
I am successfully encoding these characters. i would like to encode euro, pound, symbols also. Please guide me, thanks in advance.
Related
I have been playing around with the libAV* family of libraries, that comes along with FFMPEG and I am learning how to implement things like encoding, decoding, muxing etc.
I came across this code : https://libav.org/documentation/doxygen/master/encode_video_8c-example.html , that encodes, YUV frames, to a file, using an encoder. In my implementation, I will change the encoder to H264 using avcodec_find_encoder(AV_CODEC_ID_H264) But I do not know, how to put this encoded data, into a proper container (.mp4) using libav libraries, so that the output file, can be played by any media player like VLC, QuickTime, etc...
Can anyone please help me on that? Every help will be greatly appreciated!
You should be able to write the frames to a file you initialize something like this:
// Have the library guess the format
AVOutputFormat *fmt = av_guess_format(NULL, "my_video.mp4", NULL);
// Set the AVOutputFormat in your output context (init not shown)
pOutFormatContext->oformat = fmt;
// Open the output, error handling not shown
avio_open2(&pOutFormatContext->pb, "my_video.mp4", AVIO_FLAG_WRITE, NULL, NULL);
// Create output stream
AVStream * outStream;
outStream = avformat_new_stream(pOutFormatContext, NULL);
// Set any output stream options you would want, example of setting the aspect ratio from the input coded 'inCodecContext' (init not shown for this)
outStream->sample_aspect_ratio.num = inCodecContext->sample_aspect_ratio.num;
outStream->sample_aspect_ratio.den = inCodecContext->sample_aspect_ratio.den;
// There may be other things you want to set like the time base, but will depend on what you're doing
// Write the header to the context, error handling not shown
avformat_write_header(pOutFormatContext, NULL);
// Dump out the format and check
av_dump_format(pOutFormatContext, 0, pOutFormatContext->filename, 1);
You then have to read the packets and encode them which it sounds like you're already doing, and then when you write to the output context it should be writing to the file in the container you specified.
I can't print the swedish letters åäö.
#include <stdio.h>
#include <stdlib.h>
int main(void){
printf("å Å | ä Ä | ö Ö");
return 0;
}
The output I get is:
├Ñ ├à | ├ñ ├ä | ├ ├û
I don't understand what is wrong. I've searched google and stackoverflow, but nothing to be found. Maybe there is something wrong with UTF-8?
Other information that might be usefull:
I'm using Windows 10 and atom.
SOLUTION
Go to:
System language settings -> Administrative language settings -> Change system
locale...
Now check the following box:
[Beta: Use Unicode UTF-8 for worldwide language support]
This fixed my problem and I am now able to use UTF-8 characters.
The Windows command window (terminal, console, whatever you call it) does support UTF-8 since several years, at least with Windows 7 based on my experiences. You need to set the code page:
mode con cp select=65001
Additionally you can set the output code page programmatically:
SetConsoleOutputCP(CP_UTF8);
I was following this tutorial.
https://developers.google.com/apps-script/articles/appengine
When I tried to follow Section 1-6
"Test this URL in your browser: http:// localhost:8080/rpc?action=Echo¶ms={"example":"blah"}&key=mySecretKey."
(I added a space between "http://" and "localhost" to avoid auto error check of stackover
flow.)
I could not follow because of this error.
<type 'exceptions.SyntaxError'>: 'ascii' codec can't decode byte 0xc2 in position 141: ordinal not in range(128) please see http://www.python.org/peps/pep-0263.html for details (backend.py)
args = ("'ascii' codec can't decode byte 0xc2 in position...n.org/peps/pep-0263.html for details (backend.py)",)
filename = None
lineno = None
message = "'ascii' codec can't decode byte 0xc2 in position...n.org/peps/pep-0263.html for details (backend.py)"
msg = "'ascii' codec can't decode byte 0xc2 in position...n.org/peps/pep-0263.html for details (backend.py)"
offset = None
print_file_and_line = None
text = None
Before this tutorial, I've read a "Hello World" tutorial for Google App Engine. And it worked fine.
What should I do to remove the error?
P.S.
In the tutorial I found a typo "Section 1: Using the Script Editor" should be "Section 1: Creating and deploying an App Engine service". I think.
The pilcrow sign ¶ (in "... action=Echo¶ms= ...") has a representation in ascii as B6, but in UTF-8 it is represented as C2 B6.
Your browser or editor is probably (and quite reasonably) using UTF-8 as the encoding for the script. A workaround may be to change your encoding to Western or ascii, then paste the script again.
Unicode problems are very common in GAE python applications. This article from Nick Johnson will help you with your Python code:
http://blog.notdot.net/2010/07/Getting-unicode-right-in-Python
I am getting the very familiar:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 24: ordinal not in range(128)
I have checked out multiple posts on SO and they recommend - variable.encode('ascii', 'ignore')
however, this is not working. Even after this I am getting the same error ...
The stack trace:
'ascii' codec can't encode character u'\x92' in position 18: ordinal not in range(128)
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 513, in __call__
handler.post(*groups)
File "/base/data/home/apps/autominer1/1.343038273644030157/siteinfo.py", line 2160, in post
imageAltTags.append(str(image["alt"]))
UnicodeEncodeError: 'ascii' codec can't encode character u'\x92' in position 18: ordinal not in range(128)
The code responsible for the same:
siteUrl = urlfetch.fetch("http://www."+domainName, headers = { 'User-Agent' : 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9b5) Gecko/2008032620 Firefox/3.0b5' } )
webPage = siteUrl.content.decode('utf-8', 'replace').encode('ascii', 'replace')
htmlDom = BeautifulSoup(webPage)
imageTags = htmlDom.findAll('img', { 'alt' : True } )
for image in imageTags :
if len(image["alt"]) > 3 :
imageAltTags.append(str(image["alt"]))
Any help would be greatly appreciated. thanks.
There are two different things that Python treats as strings - 'raw' strings and 'unicode' strings. Only the latter actually represent text. If you have a raw string, and you want to treat it as text, you first need to convert it to a unicode string. To do this, you need to know the encoding for the string - they way unicode codepoints are represented as bytes in the raw string - and call .decode(encoding) on the raw string.
When you call str() on a unicode string, the opposite transformation takes place - Python encodes the unicode string as bytes. If you don't specify a character set, it defaults to ascii, which is only capable of representing the first 128 codepoints.
Instead, you should do one of two things:
Represent 'imageAltTags' as a list of unicode strings, and thus dump the str() call - this is probably the best approach
Instead of str(x), call x.encode(encoding). The encoding to use will depend on what you're doing, but the most likely choice is utf-8 - eg, x.encode('utf-8').
i'm developing a video server in C on GNU/Linux, and i'm using ffmpeg to manage data of each video file. So, i open the file, get all the information about its container, then do the same with its codec and start reading frames one by one.
Unfortunately, ffmpeg and more precisely avcodec is not very well documented. I need to know when a frame is an I-Frame or a B-Frame to maintain a record, so how could i do it?
Thanks in advance.
The picture type is given by the pict_type field of struct AVFrame. You have 4 types defined in FFMPEG. pict_type is set to FF_I_TYPE for I Frames.
For example, part of my debug code which give me a letter to set in a debug message :
/* _avframe is struct AVFrame* */
switch(_avframe->pict_type)
{
case FF_I_TYPE:
return "I";
break;
case FF_P_TYPE:
return "P";
break;
case FF_S_TYPE:
return "S";
break;
case FF_B_TYPE:
return "B";
break;
}
Manuel,
Have you tried FF-probe yet? It is a multimedia streams analyzer that allows you to see the type of each frame. You can download it from SourceForget.net. To compile it you will need Gnu autoconf, a C compiler and a working installation of the FFmpeg. Let me know if that helps.