我正在开发一个应用程序,我解码视频并替换某些帧并使用MediaMuxer和重新编码MediaCodec.如果我不替换任何帧(除了1080p视频,我将在下面解释),该应用程序可以工作,但是当我这样做时,替换后的帧会像素化,视频会不稳定.
此外,当我尝试使用1920x1080视频的应用程序时,我得到一个奇怪的输出,其中视频没有显示任何内容,直到我滚动到视频的开头,然后视频开始显示(但具有之前提到的相同问题)编辑后的像素化.
以下是我配置编码器的方法:
Video_format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, interval);
Video_format.setInteger(MediaFormat.KEY_BIT_RATE, bitRate);
Video_format.setInteger(MediaFormat.KEY_FRAME_RATE, frameRate);
Video_format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 0);
int color_format=MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar;
Video_format.setInteger(MediaFormat.KEY_COLOR_FORMAT, color_format);
encoder.configure(Video_format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
Run Code Online (Sandbox Code Playgroud)
总而言之,我有两个问题:
1-修改帧后的像素化帧和不连贯的视频.
2-损坏的1920x1080视频,除非我滚动到开头.
编辑
这是一个未经编辑的1080p视频示例,当我在VLC上播放并在手机上播放不正确时会显示绿屏,除非我滚动开始,现在奇怪地在YouTube上正常工作,除了开始时的绿框
这是一个720p视频样本,在开始时也使用绿色框架进行编辑,并在编辑后清除像素化和滞后
这是我用来解码重新编码的代码:
do{
Bitmap b1;
if(edited_frames.containsKey(extractor.getSampleTime()))
b1=BitmapFactory.decodeFile(edited_frames.get(extractor.getSampleTime()));
else
b1=decode(extractor.getSampleTime(),Preview_width,Preview_Height);
if(b1==null) continue;
Bitmap b_scal=Bitmap.createScaledBitmap(b1, Preview_width, Preview_Height, false);
if(b_scal==null) continue;
encode(b_scal, encoder, muxer, videoTrackIndex);
lastTime=extractor.getSampleTime();
}while(extractor.advance());
Run Code Online (Sandbox Code Playgroud)
解码方法:
private Bitmap decode(final long time,final int width,final int height){
MediaFormat newFormat = codec.getOutputFormat();
Bitmap b = null;
final int TIMEOUT_USEC = 10000;
ByteBuffer[] …Run Code Online (Sandbox Code Playgroud) 我正在尝试让我的应用程序向用户的日历添加提醒.代码在添加之前搜索title并start date检查日历中是否已存在该事件(以便不重复).我的问题是:如果我手动从日历中删除事件(使用日历),事件将从日历中消失(我正在查看我的所有日历,并且无法在日历应用程序中看到它),但不会从数据库中消失.我不明白的另一件事是我尝试以编程方式删除事件,但仍然没有删除它们.
这是我的代码片段:
Cursor cur = null;
ContentResolver cr = getContentResolver();
String calUriString = "content://com.android.calendar/events";
Uri cal=Uri.parse(calUriString);
String[] EVENT_PROJECTION=new String[]{"calendar_id","title","dtstart","_id"};
String selection = "((" + "calendar_id" + " = 1) AND ("
+ "title" + " LIKE '"+name+"') AND ("
+ "dtstart" + " = "+String.valueOf(c.getTimeInMillis())+"))";
cur = cr.query(cal, EVENT_PROJECTION, selection, null, null);
boolean found=false;
if(cur!=null)
if(cur.moveToFirst()){
DatabaseUtils.dumpCursor(cur);/*Just to view my results (which always include the deleted events)*/
do{
if(cur.getString(1).equals(name)){
/*I use this part to try …Run Code Online (Sandbox Code Playgroud) 我正在尝试将MediaCodec一系列图像(保存为文件中的字节数组)保存到视频文件中.我已经测试了这些图像SurfaceView(在系列中播放),我可以看到它们很好.我看了很多使用的例子MediaCodec,这是我理解的(如果我错了请纠正我):
从MediaCodec对象获取InputBuffers - >用你的帧的图像数据填充它 - >将输入缓冲区排队 - >获取编码输出缓冲区 - >将其写入文件 - >增加显示时间并重复
但是,我已经对此进行了很多测试,最终我遇到了两种情况之一:
queueInputBuffer在第二次调用时导致Media服务器死机.codec.flush()在最后调用(在将输出缓冲区保存到文件之后,虽然我看到的所有示例都没有这样做)并且媒体服务器没有死,但是,我无法使用任何媒体播放器打开输出视频文件,所以出了点问题.这是我的代码:
MediaCodec codec = MediaCodec.createEncoderByType(MIMETYPE);
MediaFormat mediaFormat = null;
if(CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)){
mediaFormat = MediaFormat.createVideoFormat(MIMETYPE, 1280 , 720);
} else {
mediaFormat = MediaFormat.createVideoFormat(MIMETYPE, 720, 480);
}
mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, 700000);
mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, 10);
mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar);
mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 5);
codec.configure(mediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
codec.start();
ByteBuffer[] inputBuffers = codec.getInputBuffers();
ByteBuffer[] outputBuffers = codec.getOutputBuffers();
boolean sawInputEOS = false;
int inputBufferIndex=-1,outputBufferIndex=-1;
BufferInfo info=null;
//loop …Run Code Online (Sandbox Code Playgroud) 我正在使用phonegap Android插件:EmailComposerwithAttachments https://github.com/phonegap/phonegap-plugins/tree/master/Android/EmailComposerWithAttachments,执行startActivitywithResult函数时会出现以下错误.我正在使用Android 4.2和Cordova 2.5.0
java.lang.ClassCastException:android.text.SpannableStringBuilder无法强制转换为java.util.ArrayList
// setting attachments
try {
JSONArray attachments = parameters.getJSONArray("attachments");
if (attachments != null && attachments.length() > 0) {
ArrayList<Uri> uris = new ArrayList<Uri>();
//convert from paths to Android friendly Parcelable Uri's
for (int i=0; i<attachments.length(); i++) {
try {
File file = new File(attachments.getString(i));
if (file.exists()) {
Uri uri = Uri.fromFile(file);
uris.add(uri);
}
} catch (Exception e) {
LOG.e("EmailComposer", "Error adding an attachment: " + e.toString());
}
}
if (uris.size() > 0) { …Run Code Online (Sandbox Code Playgroud) 我在LinearLayout中有这个ListView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
.../>
<EditText />
...
</EditText>
<ListView
android:id="@+id/words_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
List由SimpleCursorAdapter以编程方式填充:
adapter = new SimpleCursorAdapter(this, R.layout.list_row_search, mCursor, from, to);
Run Code Online (Sandbox Code Playgroud)
list_row_search有一个带有两个TableRows的TableLayout:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TableLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<View
android:layout_height="1dip"
android:background="#FF33B5E5" />
<TableRow
android:id="@+id/tableRow1"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/list_lesson"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="1dip"
android:textSize="12sp" />
<TextView
android:id="@+id/list_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5.25"
android:padding="1dip"
android:paddingRight="10dp"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/list_flex"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="12.5"
android:padding="1dip"
android:paddingRight="10dp" />
<TextView
android:id="@+id/list_rom"
android:layout_width="0dp" …Run Code Online (Sandbox Code Playgroud) 我有一个Order - FoodItem多对多的关系,如下所示:
association_table = db.Table('association', db.Model.metadata,
db.Column('left_id', db.Integer, db.ForeignKey('orders.order_id')),
db.Column('right_id', db.Integer, db.ForeignKey('fooditems.fooditem_id'))
)
class OrderModel(ReviewableModel):
__tablename__ = 'orders'
order_id = db.Column(db.Integer, db.ForeignKey('reviewables.id'), primary_key=True)
food_items = db.relationship("FoodItemModel", secondary = association_table)
__mapper_args__ = {'polymorphic_identity':'orders'}
class FoodItemModel(ReviewableModel):
__tablename__ = 'fooditems'
fooditem_id = db.Column(db.Integer, db.ForeignKey('reviewables.id'), primary_key=True)
__mapper_args__ = {'polymorphic_identity':'fooditems'}
Run Code Online (Sandbox Code Playgroud)
用户可以请求具有重复foodItem的订单.这是正确创建的,但是当我将更改保存到数据库时,将删除重复项.例如,我订购3个比萨饼:
def save_to_db(self):
print('before: '+str(self.food_items))
db.session.add(self)
db.session.commit()
print('after: '+str(self.food_items))
Run Code Online (Sandbox Code Playgroud)
输出是这样的:
before: [<FoodItemModel u'Pizza'>, <FoodItemModel u'Pizza'>, <FoodItemModel u'Pizza'>]
after: [<FoodItemModel u'Pizza'>]
Run Code Online (Sandbox Code Playgroud)
关联表已正确更新:
"left_id" "right_id"
"6" "3"
"6" "3"
"6" "3"
Run Code Online (Sandbox Code Playgroud)
但是,OrderModel中的food_items只包含1个项目
我有excel在第一行有列名.我需要阅读它没有None:
a = [Sheet.UsedRange.Rows(1).Value]
[((u'Step', u'Test Case ID', u'Traceability Ref', u'Test Description', u'Display', u'Test conditions', None, None, None, None, None, u'Test Criteria', u'Delay Time(ms)', u'Capture Time(ms)', u'Automation Type(A/S)', u'Expected Output', None, None, None, u'Actual Output', u'Comments'),)]
Run Code Online (Sandbox Code Playgroud)
我累了使用过滤器:
a = filter(None, a)
Run Code Online (Sandbox Code Playgroud)
我需要删除None(这是我的Excel中的空列).
android ×5
mediacodec ×2
python ×2
video ×2
calendar ×1
cordova ×1
excel ×1
height ×1
listview ×1
mediamuxer ×1
sqlalchemy ×1
tablelayout ×1