Newest 'ffmpeg' Questions - Stack Overflow
Articles published on the website
-
avcodec_decode_video2 fails to decode after frame resolution change
7 October 2016, by Krzysztof KansyI'm using ffmpeg in Android project via JNI to decode real-time H264 video stream. On the Java side I'm only sending the the byte arrays into native module. Native code is running a loop and checking data buffers for new data to decode. Each data chunk is processed with:
int bytesLeft = data->GetSize(); int paserLength = 0; int decodeDataLength = 0; int gotPicture = 0; const uint8_t* buffer = data->GetData(); while (bytesLeft > 0) { AVPacket packet; av_init_packet(&packet); paserLength = av_parser_parse2(_codecPaser, _codecCtx, &packet.data, &packet.size, buffer, bytesLeft, AV_NOPTS_VALUE, AV_NOPTS_VALUE, AV_NOPTS_VALUE); bytesLeft -= paserLength; buffer += paserLength; if (packet.size > 0) { decodeDataLength = avcodec_decode_video2(_codecCtx, _frame, &gotPicture, &packet); } else { break; } av_free_packet(&packet); } if (gotPicture) { // pass the frame to rendering }
The system works pretty well until incoming video's resolution changes. I need to handle transition between 4:3 and 16:9 aspect ratios. While having AVCodecContext configured as follows:
_codecCtx->flags2|=CODEC_FLAG2_FAST; _codecCtx->thread_count = 2; _codecCtx->thread_type = FF_THREAD_FRAME; if(_codec->capabilities&CODEC_FLAG_LOW_DELAY){ _codecCtx->flags|=CODEC_FLAG_LOW_DELAY; }
I wasn't able to continue decoding new frames after video resolution change. The
got_picture_ptr
flag thatavcodec_decode_video2
enables when whole frame is available was never true after that.
This ticket made me wonder if the issue isn't connected with multithreading. Only useful thing I've noticed is that when I changethread_type
toFF_THREAD_SLICE
the decoder is not always blocked after resolution change, about half of my attempts were successfull. Switching to single-threaded processing is not possible, I need more computing power. Setting up the context to one thread does not solve the problem and makes the decoder not keeping up with processing incoming data.
Everything work well after app restart.I can only think of one workoround (it doesn't really solve the problem): unloading and loading the whole library after stream resolution change (e.g as mentioned in here). I don't think it's good tho, it will propably introduce other bugs and take a lot of time (from user's viewpoint).
Is it possible to fix this issue?
EDIT:
I've dumped the stream data that is passed to decoding pipeline. I've changed the resolution few times while stream was being captured. Playing it with ffplay showed that in moment when resolution changed and preview in application froze, ffplay managed to continue, but preview is glitchy for a second or so. You can see full ffplay log here. In this case video preview stopped when I changed resolution to 960x720 for the second time. (Reinit context to 960x720, pix_fmt: yuv420p
in log). -
360 VR video to static?
7 October 2016, by SuperProwerSo, I have simple 360 (or 180, I'm not really sure since I can't play it) degrees side-by-side VR video, but my phone is so old, so it's can play that kind of video, not matter what player I use (I was able to see few frames from such a video, but they were static or applications was crashing).
Is there any way to convert such video into static one? I understand that I will lost ability to rotate my head, but I don't really care since my phone don't have a gyroscope.
I want to create simple side-by-side video which I could play with any player - I understand that I can lost quality and effect, but as I said, I don't really care, since this is just something fun which I want to try.
-
Failing to convert audio file from M4A to MP3 format using FFmpegWrapper
7 October 2016, by Radu MateiI'm trying to convert a M4A audio file to MP3 format using
ffmpeg
in an iOS Project, language: Objective C. To make things easier I try to accomplish this usingFFmpegWrapper
I'm using ffmpeg ver 2.8.3 and FFmpegWrapper 1.0 installed via CocoaPods. On
pod outdated
it shows that I'm using latest versions.This is my code:
- (void) convertMP4ToMP3 { NSString *inputFormat = @"m4a"; NSString *outputFormat = @"mp3"; NSString *inputFileName = @"audio"; NSString *outputFileName = @"outputAudio"; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *inputFilePath = [[NSBundle mainBundle] pathForResource:inputFileName ofType:inputFormat]; NSString *outputFilePath = [documentsDirectory stringByAppendingPathComponent:[outputFileName stringByAppendingPathExtension:outputFormat]]; if ([[NSFileManager defaultManager] fileExistsAtPath:outputFilePath]) { [[NSFileManager defaultManager] removeItemAtPath:outputFilePath error:nil]; } FFmpegWrapper *wrapper = [[FFmpegWrapper alloc] init]; NSDictionary *options = @{kFFmpegInputFormatKey : inputFormat, kFFmpegOutputFormatKey : outputFormat}; [wrapper convertInputPath:inputFilePath outputPath:outputFilePath options:options progressBlock:^(NSUInteger bytesRead, uint64_t totalBytesRead, uint64_t totalBytesExpectedToRead) { } completionBlock:^(BOOL success, NSError *error) { success ? NSLog(@"Success!") : NSLog(@"Error : %@",error.localizedDescription); }]; }
And as result conversion fails with the following logs:
[mp3 @ 0x16a5ca00] Using AVStream.codec.time_base as a timebase hint to the muxer is deprecated. Set AVStream.time_base instead. [mp3 @ 0x16a5ca00] Invalid audio stream. Exactly one MP3 audio stream is required. Error : Invalid argument
Any help would be appreciated.
-
Video conversion with php ffmpeg not playable on browser
7 October 2016, by Guille TerrasaI'm using the PHP FFMPEG Library https://github.com/PHP-FFMpeg/PHP-FFMpeg on a web application to convert some videos uploaded by the users in different formats to MP4 H264 video format, playable on most browsers.
I have a problem with some MP4 videos with an specific codec, this videos are being converted succesfully with PHP FFMPEG but are not playable on the browser.
- Type: Vídeo
- Codec: H264 - MPEG-4 AVC (part 10) (H264)
- Resolution: 320x258
- Screen Resolution: 320x240
- Framerate: 30.000300
- Decoded Format: Planar 4:2:2 YUV full scale
On other similar videos with a different version of the codec, the uploading and conversion process is working and the result is playable on the browser:
- Type: Vídeo
- Codec: H264 - MPEG-4 AVC (part 10) (avc1)
- Resolution: 320x258
- Screen Resolution: 320x240
- Framerate: 30
- Decoded Format: Planar 4:2:2 YUV
The code used to convert the video server side with PHP FFMPEG is this:
$video = $ffmpeg->open($path . '/' . $filename); $video->filters() ->resize(new \FFMpeg\Coordinate\Dimension($destWidth, $destHeight)) ->synchronize(); $video->save(new \FFMpeg\Format\Video\X264('libmp3lame'), $dest);
And on the browser is loaded with a video tag:
Thanks
-
How to play rtsp stream in android using ffmpeg
7 October 2016, by msjI want to play rtsp stream using ffmpeg library. I was buid ffmpeg for android and also I try to save rtsp stream to file it's work fine. my command
ffmpeg -i rtsp://@URL -acodec copy -vcodec copy abc.mp4
now I want to view my ip camera live stream video using ffmpeg. Have any ideas.
Thanks for ur time.