这是我的最终目标:我想AVVideoCompositionCoreAnimationTool用来创建Core Animation的视频.我不会在这个组合中使用现有的AVAsset.
我的问题是,如何AVMutableComposition在给定的时间内制作具有静态纯色的视频?在我想出来后,我可以添加动画.
这是我的代码:
- (void)exportVideo {
AVMutableComposition *mixComposition = [AVMutableComposition composition];
CMTimeRange timeRange = CMTimeRangeMake(kCMTimeZero, CMTimeMakeWithSeconds(10, 600));
[mixComposition insertEmptyTimeRange:timeRange];
AVMutableCompositionTrack *videoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
[videoTrack insertEmptyTimeRange:timeRange];
AVMutableVideoCompositionInstruction *mainInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
mainInstruction.timeRange = timeRange;
mainInstruction.backgroundColor = [UIColor blueColor].CGColor;
AVMutableVideoComposition *mainComposition = [AVMutableVideoComposition videoComposition];
mainComposition.renderSize = CGSizeMake(500, 500);
mainComposition.instructions = [NSArray arrayWithObject:mainInstruction];
mainComposition.frameDuration = CMTimeMake(1, 30);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *myPathDocs = [documentsDirectory stringByAppendingPathComponent:[NSString …Run Code Online (Sandbox Code Playgroud) 我正在使用FFmpeg访问我的macOS应用程序中的RTSP流。
达到的目标:我创建了一个音调发生器,它创建单通道音频并返回一个 CMSampleBuffer。当视频的 fps 和音频采样率发生变化时,音调发生器用于测试我的音频管道。
目标:目标是将多通道音频缓冲区合并为一个 CMSampleBuffer。
音频数据生命周期:
AVCodecContext* audioContext = self.rtspStreamProvider.audioCodecContext;
if (!audioContext) { return; }
// Getting audio settings from FFmpegs audio context (AVCodecContext).
int samplesPerChannel = audioContext->frame_size;
int frameNumber = audioContext->frame_number;
int sampleRate = audioContext->sample_rate;
int fps = [self.rtspStreamProvider fps];
int calculatedSampleRate = sampleRate / fps;
// NSLog(@"\nSamples per channel = %i, frames = %i.\nSample rate = %i, fps = %i.\ncalculatedSampleRate = %i.", samplesPerChannel, frameNumber, sampleRate, fps, calculatedSampleRate);
// …Run Code Online (Sandbox Code Playgroud) 我目前正在使用rusoto_s3lib 将文件上传到 S3。我发现的所有示例都做同样的事情:打开一个文件,将文件的全部内容读入内存(Vec<u8>),然后将 Vec 转换为 a ByteStream(实现From<Vec<u8>>)。这是一个代码示例:
fn upload_file(&self, file_path: &Path) -> FileResult<PutObjectOutput> {
let mut file = File::open(file_path)?;
let mut file_data: Vec<u8> = vec![];
file.read_to_end(&mut file_data)?;
let client = S3Client::new(Region::UsEast1);
let mut request = PutObjectRequest::default();
request.body = Some(file_data.into());
Ok(client.put_object(request).sync()?)
}
Run Code Online (Sandbox Code Playgroud)
这对于小文件来说可能是可以接受的,但是(我假设)一旦您尝试上传大小大于可用堆内存的文件,这种技术就会崩溃。
创建 a 的另一种方法ByteStream是使用这个初始化器,它接受一个实现Streamtrait的对象。我认为这File会实现这个特性,但事实并非如此。
是否有某种类型可以从一个Filewhich 实现Stream?制作我自己的元组结构的正确解决方案是包装File和实现Stream自身吗,这个实现是微不足道的吗?有没有我没有看到的另一个解决方案,或者我只是误解了上面代码中的内存分配方式?
这是我的代码:
func test(v map[string]string) {
v["foo"] = "bar"
}
func main() {
v := make(map[string]string)
test(v)
fmt.Printf("%v\n", v) // prints map[foo:bar]
}
Run Code Online (Sandbox Code Playgroud)
我对 Go 还很陌生,但据我所知,由于我将映射值传递给test()而不是指向映射的指针,因此该test()函数应该修改映射的不同变量,因此不会影响中变量的值main()。我本来希望它能打印出来map[]。我测试了不同的场景:
type myStruct struct {
foo int
}
func test2(v myStruct) {
v.foo = 5
}
func main() {
v := myStruct{1}
test2(v)
fmt.Printf("%v\n", v) // prints {1}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,代码的行为符合我的预期。v函数中的变量不受main()中变量的更改的影响test2()。那么为什么地图不同呢?
我希望我的类型MyError可以从所有其他类型转换。我尝试这样做:
impl<T> From<T> for MyError {
fn from(_: T) -> Self {
MyError::Unknown
}
}
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
error[E0119]: conflicting implementations of trait `std::convert::From<MyError>` for type `MyError`
--> src/main.rs:26:5
|
26 | impl<T> From<T> for MyError {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T> From<T> for T;
Run Code Online (Sandbox Code Playgroud)
这是有道理的,因为这样T是必然的MyError,并且此实现由impl<T> From<T> for T. 理想情况下,我将能够排除MyError来自T这样的:
error[E0119]: conflicting implementations of trait `std::convert::From<MyError>` for type `MyError`
--> src/main.rs:26:5
|
26 …Run Code Online (Sandbox Code Playgroud) objective-c ×2
rust ×2
audio ×1
avfoundation ×1
dictionary ×1
ffmpeg ×1
go ×1
ios ×1
macos ×1
struct ×1