Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
ffmpeg fast extraction of small segments
17 juin 2016, par alrAccording to this this manual for fast extraction of small segments from video file you need to specify -ss parameter before -i.
How efficiently split 70+ GB raw video file to, let say, 4 second segments? Using the option specified above it works fine at the beginning, but then it becomes slower and slower. According to htop, the cache becomes full in Ubuntu 14.04 using ffmpeg 2.8.6, unless you have RAM bigger than the processed file.
Is there a way to split raw video file which is bigger than the amount of RAM without slowing down? It would be nice to use ffmpeg, because it allows to apply other filters on the fly. -
Stream OpenGL framebuffer over HTTP (via FFmpeg)
17 juin 2016, par mOflI have an OpenGL application of which rendered images need to be streamed over internet to mobile clients. Previously, it sufficed to simply record the rendering into a video file, which is already working, and now this should be extended to subsequent streaming.
What is working right now:
- Render a scene to an OpenGL framebuffer object
- Capture the FBO content using NvIFR
- Encode it to H.264 using NvENC (no CPU round trip required)
- Download the encoded frame to host memory as a byte array
- Append this frame to a video file
None of this steps involves FFmpeg or any other library so far. I now want to replace the last step with "Stream the current frame's byte array over internet" and I assume that using FFmpeg and FFserver would be a reasonable choice for this. Am I correct? If not, what would be the proper way?
If so, how do I approach this within my C++ code? As pointed out, the frame is already encoded. Also, there is no sound or other stuff, simply a H.264 encoded frame as byte array that is updated irregularly and should be converted into a steady video stream. I assume that this would be FFmpeg's job and that the subsequent streaming via FFserver would be simple from there. What I don't know is how to feed my data to FFmpeg in the first place, as all FFmpeg tutorials I found (in a non-exhaustive search) work on a file or webcam/capture device as data source, not volatile data in main memory.
The file mentioned above that I am already able to create is a C++ file stream to which I append each single frame, meaning that different framerates of video and rendering are not treated correctly. This also needs to be taken care of at some point.
Can somebody point me in the right direction? Can I forward data from my application to FFmpeg to build a proper video feed without writing to the hard disk? Tutorials are greatly appreciated. By the way FFmpeg/FFserver is not mandatory. If you have a better idea for streaming of OpenGL framebuffer contents, I'm eager to know.
-
ffmpeg conversion using libx264 looks terrible - interlaced
17 juin 2016, par justinI'm in the process of converting some files from my set-top box (.ASF) format to something more portable that will work with plex and roku more readily. In doing so I'm using
ffmpeg
, but having unsatisfying results. Whereas the original doesn't have ANY notable interlacing defects, the converted file does. I think it has something to do with the libx264 converter because of the following experiment:Running this command:
ffmpeg -i file.asf -vcodec copy -acodec copy -bsf:a aac_adtstoasc -ss 150 -t 15 short.mp4
ffmpeg version 3.0.2 Copyright (c) 2000-2016 the FFmpeg developers built with Apple LLVM version 7.3.0 (clang-703.0.29) configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --enable-vda libavutil 55. 17.103 / 55. 17.103 libavcodec 57. 24.102 / 57. 24.102 libavformat 57. 25.100 / 57. 25.100 libavdevice 57. 0.101 / 57. 0.101 libavfilter 6. 31.100 / 6. 31.100 libavresample 3. 0. 0 / 3. 0. 0 libswscale 4. 0.100 / 4. 0.100 libswresample 2. 0.101 / 2. 0.101 libpostproc 54. 0.100 / 54. 0.100 [asf @ 0x7f9f84000000] Could not find codec parameters for stream 2 (Unknown: none): unknown codec Consider increasing the value for the 'analyzeduration' and 'probesize' options Input #0, asf, from 'file.asf': Metadata: title : Slingbox artist : Sling Media comment : test Duration: N/A, start: 0.000000, bitrate: N/A Stream #0:0: Video: h264 (High) (h264 / 0x34363268), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 30.30 fps, 30 tbr, 1k tbn, 59.94 tbc Stream #0:1: Audio: aac (LC) ([255][0][0][0] / 0x00FF), 32000 Hz, stereo, fltp, 96 kb/s Stream #0:2: Unknown: none File 'short.mp4' already exists. Overwrite ? [y/N] y Output #0, mp4, to 'short.mp4': Metadata: title : Slingbox artist : Sling Media comment : test encoder : Lavf57.25.100 Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 30.30 fps, 30 tbr, 16k tbn, 1k tbc Stream #0:1: Audio: aac (LC) ([64][0][0][0] / 0x0040), 32000 Hz, stereo, 96 kb/s Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] for help [mp4 @ 0x7f9f8388c200] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly [mp4 @ 0x7f9f8388c200] pts has no value Last message repeated 449 times frame= 450 fps=0.0 q=-1.0 Lsize= 9002kB time=00:00:15.02 bitrate=4907.9kbits/s speed=92.1x video:8817kB audio:173kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.125406%
Which produces a file which has no interlacing artifact and appears to be same exact file size as the original (if run without the -ss and -t commands).
But running this command (without any options):
ffmpeg -i test.asf -ss 150 -t 15 short2.mp4
ffmpeg version 3.0.2 Copyright (c) 2000-2016 the FFmpeg developers built with Apple LLVM version 7.3.0 (clang-703.0.29) configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --enable-vda libavutil 55. 17.103 / 55. 17.103 libavcodec 57. 24.102 / 57. 24.102 libavformat 57. 25.100 / 57. 25.100 libavdevice 57. 0.101 / 57. 0.101 libavfilter 6. 31.100 / 6. 31.100 libavresample 3. 0. 0 / 3. 0. 0 libswscale 4. 0.100 / 4. 0.100 libswresample 2. 0.101 / 2. 0.101 libpostproc 54. 0.100 / 54. 0.100 [asf @ 0x7fec32801400] Could not find codec parameters for stream 2 (Unknown: none): unknown codec Consider increasing the value for the 'analyzeduration' and 'probesize' options Input #0, asf, from 'test.asf': Metadata: title : Slingbox artist : Sling Media comment : test Duration: N/A, start: 0.000000, bitrate: N/A Stream #0:0: Video: h264 (High) (h264 / 0x34363268), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 30.30 fps, 30 tbr, 1k tbn, 59.94 tbc Stream #0:1: Audio: aac (LC) ([255][0][0][0] / 0x00FF), 32000 Hz, stereo, fltp, 96 kb/s Stream #0:2: Unknown: none [libx264 @ 0x7fec32102800] using SAR=1/1 [libx264 @ 0x7fec32102800] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2 [libx264 @ 0x7fec32102800] profile High, level 4.0 [libx264 @ 0x7fec32102800] 264 - core 148 r2668 fd2c324 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00 Output #0, mp4, to 'short2.mp4': Metadata: title : Slingbox artist : Sling Media comment : test encoder : Lavf57.25.100 Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 30 fps, 15360 tbn, 30 tbc Metadata: encoder : Lavc57.24.102 libx264 Side data: unknown side data type 10 (24 bytes) Stream #0:1: Audio: aac (LC) ([64][0][0][0] / 0x0040), 32000 Hz, stereo, fltp, 128 kb/s Metadata: encoder : Lavc57.24.102 aac Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264)) Stream #0:1 -> #0:1 (aac (native) -> aac (native)) Press [q] to stop, [?] for help frame= 450 fps= 20 q=-1.0 Lsize= 6732kB time=00:00:15.00 bitrate=3674.9kbits/s speed=0.657x video:6481kB audio:240kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.168370% [libx264 @ 0x7fec32102800] frame I:12 Avg QP:18.85 size: 39804 [libx264 @ 0x7fec32102800] frame P:291 Avg QP:21.40 size: 17543 [libx264 @ 0x7fec32102800] frame B:147 Avg QP:22.61 size: 7167 [libx264 @ 0x7fec32102800] consecutive B-frames: 42.9% 36.9% 11.3% 8.9% [libx264 @ 0x7fec32102800] mb I I16..4: 43.2% 52.0% 4.8% [libx264 @ 0x7fec32102800] mb P I16..4: 11.9% 16.0% 1.0% P16..4: 30.2% 3.0% 1.7% 0.0% 0.0% skip:36.2% [libx264 @ 0x7fec32102800] mb B I16..4: 0.6% 0.9% 0.1% B16..8: 25.7% 1.4% 0.2% direct: 4.6% skip:66.6% L0:49.0% L1:49.4% BI: 1.6% [libx264 @ 0x7fec32102800] 8x8 transform intra:55.1% inter:92.0% [libx264 @ 0x7fec32102800] coded y,uvDC,uvAC intra: 22.5% 38.6% 6.6% inter: 6.5% 17.3% 0.5% [libx264 @ 0x7fec32102800] i16 v,h,dc,p: 28% 47% 8% 17% [libx264 @ 0x7fec32102800] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 34% 15% 42% 1% 1% 2% 1% 2% 1% [libx264 @ 0x7fec32102800] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 10% 78% 6% 1% 1% 1% 1% 1% 1% [libx264 @ 0x7fec32102800] i8c dc,h,v,p: 59% 19% 19% 3% [libx264 @ 0x7fec32102800] Weighted P-Frames: Y:14.4% UV:3.8% [libx264 @ 0x7fec32102800] ref P L0: 65.5% 6.6% 19.0% 8.4% 0.4% [libx264 @ 0x7fec32102800] ref B L0: 89.6% 8.9% 1.5% [libx264 @ 0x7fec32102800] ref B L1: 98.6% 1.4% [libx264 @ 0x7fec32102800] kb/s:3539.34 [aac @ 0x7fec32103a00] Qavg: 573.580
Produces a file which has quite a bit of interlacing defect when playing on my HD projector thru Roku via Plex (direct play enabled, apparently no transcoding).
Lest I be overly picky, I engaged my wife in this test, showing her the two files and she agreed that the one that used
libx264
was significantly worse and unwatchable. Can't figure out how to shrink this file down without causing these interlacing defects -- it happens even when I don't try to shrink it! Any thoughts?Video files:
https://dl.dropboxusercontent.com/u/23091/m1/short.mp4 https://dl.dropboxusercontent.com/u/23091/m1/short2.mp4
Update: Additionally, I tried a few settings to generate a MPEG4 (.AVI) file and had similar lack of success. Similar interlacing defects.
-
Audio decoding stopped working ffmpeg
17 juin 2016, par StevaI wrote little program for extracting raw audio date a little while ago. I was busy and in meanwhile I changed OS from Kubuntu 15.04 to 16.04. Libraries are dynamically linked in cmakelists.txt
target_link_libraries( ffmpeg #[[ Linking ffmpeg libraries - START ------------------]] "${CMAKE_SOURCE_DIR}/extern_libs/libffmpeg/lib/libavcodec.so" "${CMAKE_SOURCE_DIR}/extern_libs/libffmpeg/lib/libavdevice.so" "${CMAKE_SOURCE_DIR}/extern_libs/libffmpeg/lib/libavutil.so" "${CMAKE_SOURCE_DIR}/extern_libs/libffmpeg/lib/libavfilter.so" "${CMAKE_SOURCE_DIR}/extern_libs/libffmpeg/lib/libavformat.so" "${CMAKE_SOURCE_DIR}/extern_libs/libffmpeg/lib/libswresample.so" "${CMAKE_SOURCE_DIR}/extern_libs/libffmpeg/lib/libswscale.so" #[[ Linking ffmpeg libraries - END --------------------]] )
I started working again on my code but code doesn't work anymore.
if(av_read_frame(m_ctx, &avpkt) >= 0){ got_frame = 0; avcodec_decode_audio4(c, decoded_frame, &got_frame, &avpkt); detectSampleFormat((AVSampleFormat)decoded_frame->format); m_data->allocateMemory(m_duration, decoded_frame->channels); m_resampler->initResampler(m_fmt, decoded_frame->channel_layout, decoded_frame->sample_rate, decoded_frame->nb_samples); m_resampler->resampleAudioFrame(decoded_frame, m_data); } while(av_read_frame(m_ctx, &avpkt) >= 0){ got_frame = 0; avcodec_decode_audio4(c, decoded_frame, &got_frame, &avpkt); m_resampler->resampleAudioFrame(decoded_frame, m_data); }
Decoded frame should contain information as channel_layout, number of channels and so on... But during execution of program those are 0 or nulls.
Can anyone help me with this? I am unclear why this was working some while ago (I last worked on this code in March) and same code doesn't work anymore.
EDIT: I found problem. First frame which is read from file is damaged or something, so I just waited for first correct frame to initialize my components.
This question can be closed.
-
how do i create a stereo mp3 file with latest version of ffmpeg ?
17 juin 2016, par SeanI'm updating my code from the older version of ffmpeg (53) to the newer (54/55). Code that did work has now been deprecated or removed so i'm having problems updating it.
Previously I could create a stereo MP3 file using a sample format called:
SAMPLE_FMT_S16
That matched up perfectly with my source stream. This has now been replace with
AV_SAMPLE_FMT_S16
Which works fine for mono recordings but when I try to create a stereo MP3 file it bugs out at avcodec_open2 with:
"Specified sample_fmt is not supported."
Through trial and error I've found that using
AV_SAMPLE_FMT_S16P
...is accepted by avcodec_open2 but when I get through and create the MP3 file the sound is very distorted - it sounds about 2 octaves lower than usual with a massive hum in the background - here's an example recording:
http://hosting.ispyconnect.com/example.mp3
I've been told by the ffmpeg guys that this is because I now need to manually deinterleave my byte stream before calling:
avcodec_fill_audio_frame
How do I do that? I've tried using the swrescale library without success and i've tried manually feeding in L/R data into avcodec_fill_audio_frame but the results i'm getting are sounding exactly the same as without interleaving.
Here is my code for encoding:
void add_audio_sample( AudioWriterPrivateData^ data, BYTE* soundBuffer, int soundBufferSize) { libffmpeg::AVCodecContext* c = data->AudioStream->codec; memcpy(data->AudioBuffer + data->AudioBufferSizeCurrent, soundBuffer, soundBufferSize); data->AudioBufferSizeCurrent += soundBufferSize; uint8_t* pSoundBuffer = (uint8_t *)data->AudioBuffer; DWORD nCurrentSize = data->AudioBufferSizeCurrent; libffmpeg::AVFrame *frame; int got_packet; int ret; int size = libffmpeg::av_samples_get_buffer_size(NULL, c->channels, data->AudioInputSampleSize, c->sample_fmt, 1); while( nCurrentSize >= size) { frame=libffmpeg::avcodec_alloc_frame(); libffmpeg::avcodec_get_frame_defaults(frame); frame->nb_samples = data->AudioInputSampleSize; ret = libffmpeg::avcodec_fill_audio_frame(frame, c->channels, c->sample_fmt, pSoundBuffer, size, 1); if (ret<0) { throw gcnew System::IO::IOException("error filling audio"); } //audio_pts = (double)audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den; libffmpeg::AVPacket pkt = { 0 }; libffmpeg::av_init_packet(&pkt); ret = libffmpeg::avcodec_encode_audio2(c, &pkt, frame, &got_packet); if (ret<0) throw gcnew System::IO::IOException("error encoding audio"); if (got_packet) { pkt.stream_index = data->AudioStream->index; if (pkt.pts != AV_NOPTS_VALUE) pkt.pts = libffmpeg::av_rescale_q(pkt.pts, c->time_base, c->time_base); if (pkt.duration > 0) pkt.duration = av_rescale_q(pkt.duration, c->time_base, c->time_base); pkt.flags |= AV_PKT_FLAG_KEY; if (libffmpeg::av_interleaved_write_frame(data->FormatContext, &pkt) != 0) throw gcnew System::IO::IOException("unable to write audio frame."); } nCurrentSize -= size; pSoundBuffer += size; } memcpy(data->AudioBuffer, data->AudioBuffer + data->AudioBufferSizeCurrent - nCurrentSize, nCurrentSize); data->AudioBufferSizeCurrent = nCurrentSize; }
Would love to hear any ideas - I've been trying to get this working for 3 days now :(