HD FLV video playing slow - ffmpeg

I have a few videos which I have captured from a Live Streaming Media Server and they are in FLV Format. Now, the problem is, though the videos are captured completely but when I play them in VLC Media Player, they play very slowly, almost frame by frame like a slideshow.
Here are the details of the Video codec, audio codec, bitrate and other details of the video which I got using ffmpeg:
[flv # 0051e9a0] Invalid keyframes object, skipping.
[flv # 0051e9a0] Keyframe index parsing failed
Input #0, flv, from 'tofix.flv':
Metadata:
audiodelay : 0
audiosize : 6607344
canSeekToEnd : false
datasize : 271773993
hasAudio : true
hasCuePoints : false
hasKeyframes : true
hasMetadata : true
hasVideo : true
lastkeyframetimestamp: 424
lasttimestamp : 425
metadatacreator : inlet media FLVTool2 v1.0.6 - http://www.inlet-media.de/fl
vtool2
videosize : 265143027
Duration: 00:07:04.62, start: 0.000000, bitrate: 1903 kb/s
Stream #0:0: Video: flv1, yuv420p, 960x540, 5112 kb/s, 29.97 tbr, 1k tbn, 1k
tbc
Stream #0:1: Audio: mp3, 44100 Hz, stereo, s16, 112 kb/s
At least one output file must be specified
The bit rate is 1903 kbps and the codec is flv1.
I also captured some other videos from the server which are in h.264 codec with a bit rate of 563 kbps and they play properly.
Is there a way I can play these high definition FLV files in my media player smoothly?
It would be great if this is possible.
I have tried converting the FLV video to AVI using ffmpeg, however, the issue still remains.

Your container says 1 fps [1 tbn] so it is playing at 1 fps. Remux them with 29.97 and also fix your capture mechanism.
Question is more fit for Stack overflow.

Related

FFmpeg - A/V sync problem when muxing concatenated MP4 files

First of all, I'd like to say that I've spent the whole day on researching the issue, tried everything I found on the web and none of the solutions worked, so I'm hopeless.
I'm testing live streaming using Azure Media Services. When the event is stopped, I'd like to get the recording as a single MP4 file, but Azure saves the video and audio tracks separately in a fragmented form. I figured out that I can concatenate these files (I used OSX cat command), so I do have perfectly working MP4 files for video and audio - both of them play without any interruptions and seem just fine.
Here's the FFmpeg info on these files:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video_1200k.mp4':
Metadata:
major_brand : isml
minor_version : 512
compatible_brands: ismlpiff
encoder : Lavf58.45.100
Duration: 01:05:49.57, start: 0.085000, bitrate: 1166 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 1163 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'audio_128k.mp4':
Metadata:
major_brand : isml
minor_version : 512
compatible_brands: ismlpiff
encoder : Lavf58.45.100
Duration: 01:06:09.57, start: 0.000000, bitrate: 132 kb/s
Stream #1:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : Audio
vendor_id : [0][0][0][0]
I noticed the duration difference, but I thought that when I mux these streams, I would get a file in which the last few seconds would have just the audio track. I started with testing the most basic FFmpeg command ffmpeg -i video_1200k.mp4 -i audio_128k.mp4 -c copy muxed.mp4, however the A/V turned out to be out of sync - the video is ahead of audio and the gap increases quite a lot over time.
I've tried pretty much every FFmpeg command arguments I found in similar post, including re-encoding, offsetting the audio, speeding up the audio (to match the video duration), adding audio filters (aresample=async with different values) and none of them helped - all I managed to achieve is getting a sync at the beginning of the video, but the audio keeps getting more and more delayed (at 50 mins the delay is like 15 seconds).
Any ideas what am I doing wrong? Any hints would be highly appreciated.
Thanks a lot in advance!

Failed to convert webm audio file to mp4 using FFMPEG

I have a webm audio file , I was trying to convert it into mp4 using ffmpeg. But it is failed to create the mp4. The info about the file is as follows.
fmpeg -i 54ebe077-96fc-4ace-9a38-f13c58807322.webm -hide_banner
Input #0, matroska,webm, from '54ebe077-96fc-4ace-9a38-f13c58807322.webm':
Metadata:
encoder : Lavf56.40.101
creation_time : 2019-10-22T11:19:12.000000Z
Duration: 00:00:24.16, start: 0.000000, bitrate: 41 kb/s
Stream #0:0: Video: vp8, yuv420p, 640x480, SAR 1:1 DAR 4:3, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
Stream #0:1: Audio: opus, 48000 Hz, mono, fltp (default)
At least one output file must be specifiedffmpeg -i 54ebe077-96fc-4ace-9a38-f13c58807322.webm -qscale 0 out.mp4
I was tried to convert it using the following command
ffmpeg -i 54ebe077-96fc-4ace-9a38-f13c58807322.webm -qscale 0 out.mp4
It throws errors
[opus # 0x56489c7f9840] LBRR frames is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[opus # 0x56489c7f9840] Error decoding a SILK frame.
[opus # 0x56489c7f9840] Error decoding an Opus frame.
Too many packets buffered for output stream 0:1.
[aac # 0x56489c82d640] Qavg: 59180.625
[aac # 0x56489c82d640] 2 frames left in the queue on closing
Conversion failed!
How to fix this issue? I have played the file in VLC and I can hear the sound from the source file. But failed to convert it
Your ffmpeg is too old
Update your ffmpeg:
Download an already compiled ffmpeg
Or see compile instructions at FFmpeg Wiki
This was ticket #4641: Error decoding SILK frame. The fix is newer than the most current release branch (FFmpeg 4.3 as of writing this), so you have to get a build from the git master branch (either of the links above will do), or wait for FFmpeg 4.4.
If you can't update
If you can't update your ffmpeg the old workaround is to use libopus to decode:
ffmpeg -c:a libopus -i input ...

lower fps when using ffmpeg to convert mp4 to gif

I am using ffmpeg to convert high quality videos to gif, most of the videos are 60fps and over 720p, but when I use the code below, to convert the video to gif, I get very low fps for the gif output,
#!/usr/bin/env
palette=/tmp/pallete.png
filter="fps=50,scale=480:-1:flags=lanczos"
ffmpeg -y -i test.mov -vf $filter,palettegen=stats_mode=diff $palette
ffmpeg -y -i test.mov -i $palette -lavfi "$filter [x]; [x][1:v] paletteuse" test.gif
another issue I have noted is - as the width increases e.g 720 instead of 480 I get even lower fps.
here is output log example, the output fps is lower than the assigned 50fps
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/tmp/201631203815.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.36.100
Duration: 00:00:05.48, start: 0.016000, bitrate: 1579 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1334x1334, 1576 kb/s, 60.18 fps, 60 tbr, 1000k tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Input #1, png_pipe, from '/tmp/pallete.png':
Duration: N/A, bitrate: N/A
Stream #1:0: Video: png, rgba(pc), 16x16 [SAR 1:1 DAR 1:1], 25 tbr, 25 tbn, 25 tbc
Output #0, gif, to '/tmp/201631203815.gif':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.40.101
Stream #0:0: Video: gif, pal8, 480x480, q=2-31, 200 kb/s, 50 fps, 100 tbn, 50 tbc (default)
Metadata:
encoder : Lavc56.60.100 gif
Stream mapping:
Stream #0:0 (h264) -> fps
Stream #1:0 (png) -> paletteuse:palette
paletteuse -> Stream #0:0 (gif)
Press [q] to stop, [?] for help
frame= 275 fps= 32 q=-0.0 Lsize= 2480kB time=00:00:05.50 bitrate=3693.5kbits/s
How do I ensure that the output fps is always whats set by the user?
Any resource on this is highly appreciated.
UPDATE
i have also noticed that the use of a higher fps eg filter="fps=90,scale=480:-1:flags=lanczos" has the effect of slowing down the gif,like a slow motion effect, the output fps is still lower around 15fps,
setting the fps value explicitly gave the same lower fps output
results frame= 346 fps= 24 q=-0.0 Lsize= 6506kB time=00:00:06.92
bitrate=7701.8kbits/s
This is not the output fps! It's the encoding speed. Most players don't properly play GIFs with a fps higher than 50. See the demo showing this behaviour.
I'm not experienced in making GIF files with FFmpeg, but as far as I know, the fps filter has an idividual "fps" parameter for the actual framerate value, so I think it may not work correctly if you omit that.
Just to make sure the filter gets the correct value, you should explicitly set the fps value:
filter="fps=fps=50,scale=480:-1:flags=lanczos"
If it doesn't working, I'd try the regular "rate" option too:
ffmpeg -y -i test.mov -i $palette -lavfi "$filter [x]; [x][1:v] paletteuse" -r 50 test.gif
Otherways, your console output looks good (it indicates the output will be 50fps), so the phenomena is a little bit mysterious.
Working Solution:
All you need to do is to break the process into three individual steps, and use the "-framerate" demux-option.
First, let's generate the palette file:
ffmpeg -i <input_file> -filter_complex "scale=w=480:h=-1:flags=lanczos, palettegen=stats_mode=diff" palette.png
Secondly, break the video frames into image files:
ffmpeg -i <input_file> -r 50 -f image2 image_%06d.png
And finally, join said images into one GIF sequence:
(the important part here is the image2 demuxer's framerate option!)
ffmpeg -framerate 50 -i image_%06d.png -i palette.png -filter_complex "[0]scale=w=400:h=-1[x];[x][1:v] paletteuse" -pix_fmt rgb24 output.gif
Edit: Finally find the answer!
You need to use image2 demuxer's -framerate option! (answer edited accordingly)
Alternative methods:
gifsickle - convert images to gif, can set frame delay
ImageMagic - can convert video to gif directly, excellent gif quality control options.

how to convert videos to flv using ffmpeg in php?

i am trying to convert some different video formats to flv using ffmpeg. But it seems that only some videos go through.
ffmpeg -i /var/www/tmp/91640.avi -ar 22050 -ab 32 -f flv /var/www/videos/91640.flv
here is some debug info:
Seems stream 0 codec frame rate differs from container frame rate: 23.98 (65535/2733) -> 23.98 (5000000/208541)
Input #0, avi, from '/var/www/tmp/91640.avi':
Duration: 00:01:12.82, start: 0.000000, bitrate: 5022 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 1280x528 [PAR 1:1 DAR 80:33], 23.98 tbr, 23.98 tbn, 23.98 tbc
Stream #0.1: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s
Output #0, flv, to '/var/www/videos/91640.flv':
Stream #0.0: Video: flv, yuv420p, 1280x528 [PAR 1:1 DAR 80:33], q=2-31, 200 kb/s, 90k tbn, 23.98 tbc
Stream #0.1: Audio: adpcm_swf, 22050 Hz, 5.1, s16, 0 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Error while opening codec for output stream #0.1 - maybe incorrect parameters such as bit_rate, rate, width or height
also, if i try to grab one frame ad convert it to jpeg i get an error as well
ffmpeg -i /var/www/tmp/91640.avi -an -ss 00:00:03 -t 00:00:01 -r 1 -y /var/www/videos/91640.jpg
debug info
...
[mpeg4 # 0x1d7d810]Invalid and inefficient vfw-avi packed B frames detected
av_interleaved_write_frame(): I/O error occurred
Usually that means that input file is truncated and/or corrupted.
im thinking that the image fails because the video conversion failed in the first place, not sure though
any ideas what goes wrong?
Bits, not kbits
From your console output:
WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s
Use 32k, not just 32.
Only stereo or mono is supported
The encoder adpcm_swf ony supports mono or stereo, so add -ac 2 as an output option. The console output would have suggested this if you were using a recent ffmpeg build.
Use -vframes 1 for single image outputs
Instead of -t 00:00:01 -r 1 use -vframes 1.
A better encoder
Instead of using the encoders flv and adpcm_swf, I recommend libx264 and libmp3lame:
ffmpeg -i input -vcodec libx264 -preset medium -crf 23 -acodec libmp3lame -ar 44100 -q:a 5 output.flv
-preset – Controls the encoding speed to compression ratio. Use the slowest preset you have patience for: ultrafast,superfast, veryfast, faster, fast, medium, slow, slower, veryslow.
-crf – Constant Rate Factor. A lower value is a higher quality. Range is 0-51 for this encoder. 0 is lossless, 18 is roughly "visually lossless", 23 is default, and 51 is worst quality. Use the highest value that still gives an acceptable quality.
-q:a – Audio quality for libmp3lame. Range is 0-9 for this encoder. A lower value is a higher quality.
Also see
FFmpeg and x264 Encoding Guide
Encoding VBR (Variable Bit Rate) mp3 audio

How do I debug why avconv is stalling?

I'm converting .mov files to .mpg files using avconv. The command being run by my php application is as follows:
avconv -y -i '$finalvideo' -target ntsc-dvd -aspect 4:3 '$mpgvideo' > $logs
I'm able to convert small .mov files to .mpg without any problems. However, I'm unable to convert videos that are over ten or fifteen minutes long. The log file is completely empty. When I run the command directly the frame stops somewhere around 34000 no matter which video I pick.
The cpu shows 97% usage on this process, however, nothing is happening.
OS Ubuntu 10~
How can I gather more information about this stalled process?
Here's the frozen output
avconv version 0.7, Copyright (c) 2000-2011 the Libav developers
built on Nov 3 2011 13:39:09 with gcc 4.3.3
Seems stream 0 codec frame rate differs from container frame rate: 180000.00 (180000/1) -> 23.98 (24000/1001)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/var/www/sites/default/files/compiled_videos/573-stream.mov':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
creation_time : 1970-01-01 00:00:00
encoder : Lavf53.0.3
Duration: 00:18:53.49, start: 0.000000, bitrate: 1430 kb/s
Stream #0.0(eng): Video: h264 (Main), yuv420p, 854x480, 1387 kb/s, 25.60 fps, 23.98 tbr, 90k tbn, 180k tbc
Metadata:
creation_time : 1970-01-01 00:00:00
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 126 kb/s
Metadata:
creation_time : 1970-01-01 00:00:00
[buffer # 0x9d88820] w:854 h:480 pixfmt:yuv420p
[scale # 0x9d88b60] w:854 h:480 fmt:yuv420p -> w:720 h:480 fmt:yuv420p flags:0x4
Incompatible sample format 's16' for codec 'ac3', auto-selecting format 'flt'
Output #0, dvd, to '/var/www/sites/default/files/compiled_videos/573.mpg':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
creation_time : 1970-01-01 00:00:00
encoder : Lavf53.10.0
Stream #0.0(eng): Video: mpeg2video, yuv420p, 720x480 [PAR 8:9 DAR 4:3], q=2-31, 6000 kb/s, 90k tbn, 29.97 tbc
Metadata:
creation_time : 1970-01-01 00:00:00
Stream #0.1(eng): Audio: ac3, 48000 Hz, stereo, flt, 448 kb/s
Metadata:
creation_time : 1970-01-01 00:00:00
Stream mapping:
Stream #0.0 -> #0.0 (h264 -> mpeg2video)
Stream #0.1 -> #0.1 (aac -> ac3)
Press ctrl-c to stop encoding
[mpeg2video # 0x9d8bf20] rc buffer underflow
Input stream #0.1 frame changed from rate:48000 fmt:s16 ch:2 to rate:48000 fmt:flt ch:2
frame=33910 fps= 91 q=2.0 size= 151922kB time=336.58 bitrate=3697.7kbits/s dup=5475 drop=530
Oh interesting. I used -loglevel debug -debug. I was seeing this information
stream #0:
keyframe=0
duration=0.000
dts=1133.449 pts=1133.533
size=103
*** 1 dup!
stream #0:
keyframe=0
duration=0.000
dts=1133.449 pts=1133.449
size=104
Until I finally received this message
*** drop!
I have posted my bug with libav
http://bugzilla.libav.org/show_bug.cgi?id=67
thanks for your help.
Try running avconv with a higher log level: -loglevel debug.
That should give you more data. Also, try -dump and -debug.
Are you sure it's not because you're hitting a storage cap?
I ran into this recently with ffmpeg while converting some oddly sized video clips to a "standard" 16:9 x264 & AAC streams inside a mp4 container. When that "Incompatible sample format 's16' for codec 'ac3', auto-selecting format 'flt'" message would show up, my ffmpeg process would frequently just hang indefinitely at 100% CPU use.
I finally found that the issue, at least in my case, was that because of the conversions I was doing (transcoding to an intermediary format then to the final, desired output), it was actually the number of audio stream channels that caused the encode process to hang. By telling ffmpeg to convert the audio stream to 2-channel, I was able to fix this issue permanently.
The same solution will probably apply to avconv. In the ffmpeg world (and because I'm stuck with an outdated version), I merely needed to add -ac 2 to my ffmpeg command and everything worked perfectly!
Hope that helps :)

Resources