Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
How to run animation in python without downloading FFmpeg or changing settings
2 juin 2017, par ToniUsing Jupyter notebook with Python 3.5.2 Anaconda 4.1.1 32-bit on Windows 7, and trying to reproduce the animations here, I get this message:
In [36]: HTML(anim.to_html5_video())
RuntimeError Traceback (most recent call last) in
() 1 ----> 2 HTML(anim.to_html5_video()) C:\Anaconda3\lib\site-packages\matplotlib\animation.py in to_html5_video(self) 949 # We create a writer manually so that we can get the 950 # appropriate size for the tag --> 951 Writer = writers[rcParams['animation.writer']] 952 writer = Writer(codec='h264', 953 bitrate=rcParams['animation.bitrate'], C:\Anaconda3\lib\site-packages\matplotlib\animation.py in __getitem__(self, name) 86 def __getitem__(self, name): 87 if not self.avail: ---> 88 raise RuntimeError("No MovieWriters available!") 89 return self.avail[name] 90 RuntimeError: No MovieWriters available! Which is clear enough. However, this SE post seems to indicate that the solution is in downloading FFmpeg, and ultimately having to change environment variables settings, which I don't feel comfortable doing.
Is there a way to make this happen without going down this PATH?
-
Any suggestion for a reliable video format for industrial applications ?
2 juin 2017, par fstabI am currently using videos encoded in MPEG4 (h264). This makes the content of the frames rely on the content of other frames.
In my case this is undesirable as I often need to quickly split video files without re-compressing or altering the content and seek many times trough the video.
The video format that I need needs to be reliable and the frames need to be independent from each other.
Any idea on which video format might be best for these requirements?
Maybe there is a sub-type of MPEG4 encoding that allows to reach this result?
-
errors when compiling c code with ffmpeg library
2 juin 2017, par KindermannI've installed ffmpeg library in my new ubuntu 16.04 OS. When I tried to compile my c code, I got the following strange errors:
/home/widerstand/ffmpeg_build/lib/libavutil.a(hwcontext_vaapi.o): In function `vaapi_device_free': /home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:861: undefined reference to `XCloseDisplay' /home/widerstand/ffmpeg_build/lib/libavutil.a(hwcontext_vaapi.o): In function `vaapi_device_create': /home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:891: undefined reference to `XOpenDisplay' /home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:896: undefined reference to `vaGetDisplay' /home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:903: undefined reference to `XDisplayName' /home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:893: undefined reference to `XDisplayName' /home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:917: undefined reference to `vaGetDisplayDRM' /home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:891: undefined reference to `XOpenDisplay' /home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:893: undefined reference to `XDisplayName' /home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:898: undefined reference to `XDisplayName' /home/widerstand/ffmpeg_build/lib/libavutil.a(hwcontext_vdpau.o): In function `vdpau_device_create': /home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:431: undefined reference to `XOpenDisplay' /home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:437: undefined reference to `XDisplayString' /home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:439: undefined reference to `XDefaultScreen' /home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:439: undefined reference to `vdp_device_create_x11' /home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:433: undefined reference to `XDisplayName' /home/widerstand/ffmpeg_build/lib/libavutil.a(hwcontext_vdpau.o): In function `vdpau_device_free': /home/widerstand/ffmpeg_sources/ffmpeg/libavutil/hwcontext_vdpau.c:410: undefined reference to `XCloseDisplay' collect2: error: ld returned 1 exit status Makefile:30: recipe for target 'video_analysis' failed make: *** [video_analysis] Error 1
I've reinstalled ffmpeg library multiple times using the following configurations:
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \ --prefix="$HOME/ffmpeg_build" \ --pkg-config-flags="--static" \ --extra-cflags="-I$HOME/ffmpeg_build/include" \ --extra-ldflags="-L$HOME/ffmpeg_build/lib" \ --bindir="$HOME/bin" \ --enable-gpl \ --enable-libass \ --enable-libfdk-aac \ --enable-libfreetype \ --enable-libmp3lame \ --enable-libopus \ --enable-libtheora \ --enable-libvorbis \ --enable-libvpx \ --enable-libx264 \ --enable-nonfree PATH="$HOME/bin:$PATH" make
The installation process was successful each time. But when I tried to compile my own c code, I always encountered the same errors as mentioned above. I have no idea about that... Here is the makefile I used:
EDIT:
FFMPEG_LIBS= libavdevice \ libavformat \ libavfilter \ libavcodec \ libswresample \ libswscale \ libavutil \ TARGET = video_analysis LIBS = -lX11 -lm -lvdpau -lva CC = gcc CFLAGS += -O2 -g -O0 CFLAGS := $(shell pkg-config --cflags $(FFMPEG_LIBS)) $(CFLAGS) LDLIBS := $(shell pkg-config --libs $(FFMPEG_LIBS)) $(LDLIBS) .PHONY: default all clean default: $(TARGET) all: default OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c)) HEADERS = $(wildcard *.h) %.o: %.c $(HEADERS) $(CC) $(CFLAGS) -c $< -o $@ .PRECIOUS: $(TARGET) $(OBJECTS) $(TARGET): $(OBJECTS) $(CC) $(OBJECTS) $(LDLIBS) $(LIBS) -o $@ clean: -rm -f *.o -rm -f $(TARGET)
EDIT:
Afer swapping $(LIBS) and $(LDLIBS) to be $(LDLIBS) $(LIBS) at line 30, it looks much better, but the compiler still reports the following errors:
/root/ffmpeg_build/lib/libavutil.a(hwcontext_vaapi.o): In function `vaapi_device_create': /ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:896: undefined reference to `vaGetDisplay' /ffmpeg_sources/ffmpeg/libavutil/hwcontext_vaapi.c:917: undefined reference to `vaGetDisplayDRM'
I have no idea which library is still missing? It looks as if libva were still missing?... I got the answer by myself...Have a look at here: errors of 'vaGetDisplay' and `vaGetDisplayDRM'
-
PHP exec command running and waiting to finish on dev machine, but exiting without completing on production
2 juin 2017, par HirveshI'm trying to run a command within PHP to resize a video using ffmpeg. My command is as follows:
$videoFilename = storage_path()."/app/gifrecipes/sample.mp4"; $videoFilename2 = storage_path()."/app/gifrecipes/sample2.mp4"; exec("ffmpeg -y -i " . $videoFilename . " -s 640x640 -aspect 1:1 -r 24000/1001 -b 1550k -bt 1792k -vcodec libx264 -pass 1 -preset ultrafast -an " . $videoFilename2 . " && ffmpeg -y -i " . $videoFilename . " -s 640x640 -aspect 1:1 -r 24000/1001 -b 1550k -bt 1792k -vcodec libx264 -pass 2 -preset ultrafast -acodec libfaac -ac 2 -ab 128k " . $videoFilename2);
On my development server (with same PHP and FFMPEG version as production) the command converts the video and finishes, whereas, on production, it just creates and empty (0 bytes) video file and exits. When I run the command from command line on the production server, video converts fine, it's just when ran from php which causes the issue.
Anybody can guide me as to why this is happening?
Edit:
Similar threads:
ffmpeg video conversion creates empty file when using php's exec()
-
How to use libx264 to encode video in ffmpeg ?
2 juin 2017, par wzjingI want to compress a video to smaller size, and if the video not encode by h264, then I transcode to h264. I have compiled ffmpeg 3.3.2 with libx264, When I using
avcodec_send_frame()
, it always return an error code, I useav_err2str(ret)
, and it said "Generic error in an external library" . Is this becouse my code is wrong or my lib is wrong? any way to crrect it or get more details?
so here is my code of the transcode part, I do encode in the while loop, and the method to encode frame isencodeFrame()
, the error happend in the last 3 line in methodencodeFrame()
, that meansavcodec_send_frame(outCxt, outFrame)
return whith an error:int transcode(){ ...... /******** Section 1 arguments configure ********/ AVCodec outCodec = NULL; outCodec = avcodec_find_encoder_by_name("libx264"); //tried avcodec_find_encoder(AV_CODEC_ID_H264) got same error if (outCodec == NULL) { LOGE("Unable to find encoder libx264"); exit(1); } AVCodecContext *outCtx = NULL; outCtx = avcodec_alloc_context3(outCodec); outCtx->bit_rate = 40000; outCtx->width = inCtx->width; outCtx->height = inCtx->height; outCtx->time_base = (AVRational) {1, 25}; outCtx->framerate = (AVRational) {25, 1}; outCtx->gop_size = inCtx->gop_size; outCtx->max_b_frames = inCtx->max_b_frames; outCtx->pix_fmt = AV_PIX_FMT_YUV420P; outCtx->sample_fmt = inCtx->sample_fmt; outCtx->sample_rate = inCtx->sample_rate; outCtx->frame_size = inCtx->frame_size; outCtx->channel_layout = inCtx->channel_layout; outCtx->channels = inCtx->channels; av_opt_set(outCtx->priv_data, "preset", "slow", 0); ret = avcodec_open2(outCtx, outCodec, NULL); if (ret < 0) error(ret, "Error while inilizing outCtx instanceof AVCodecContext"); /******** Section 2 init AVPacket and AVFrame ********/ AVPacket *inPacket = NULL; inPacket = av_packet_alloc(); av_init_packet(inPacket); AVFrame *vFrame; vFrame = av_frame_alloc(); if (!vFrame) LOGE("Unable to allocate vFrame"); vFrame->width = outCtx->width; vFrame->height = outCtx->height; vFrame->format = outCtx->pix_fmt; ret = av_frame_get_buffer(vFrame, 32); if (ret < 0) error(ret, "Unable to execute av_frame_get_buffer"); /******** Section 3 start transcode ********/ int k = 0; while (av_read_frame(inFormatContext, inPacket) == 0) { LOGI("--------------------- index:%d -------------------", k); resend: ret = avcodec_send_packet(inCtx, inPacket); if (ret == AVERROR(EOF)) LOGW("> avcodec_send_packet: reache EOF"); else if (ret == AVERROR(EAGAIN)) { LOGW("> avcodec_send_packet: last frame not been read"); goto resend; } else if (ret == 0) { if (inPacket->stream_index == video_index) { LOGD(">> receiving video frame"); avcodec_receive_frame(inCtx, vFrame); encodeFrame(outFormatContext, outCtx, vFrame); } else { //Currently, I igonred audio stream for now LOGD(">> receiving audio frame"); avcodec_receive_frame(inCtx, aFrame); } av_packet_unref(inPacket); k++; } else { LOGE("> Error: avcodec_send_packet(%s)", av_err2str(ret)); exit(1); } } ...... } void encodeFrame(AVFormatContext *outFCxt, AVCodecContext *outCxt, AVFrame *outFrame) { LOGD(">> Encode Start"); int ret; AVPacket *packet; packet = av_packet_alloc(); ret = avcodec_send_frame(outCxt, outFrame); switch (ret) { case AVERROR(EAGAIN): LOGW(">>> avcodec_send_frame(last packet not received yet)"); av_packet_unref(packet); encodeFrame(outFCxt, outCxt, outFrame); break; case AVERROR(EOF): LOGW(">>> avocdec_send_frame(reach end)"); av_packet_unref(packet); break; case 0: av_frame_unref(outFrame); LOGD(">>> avcodec_send_frame(packet send success)"); while (1){ ret = avcodec_receive_packet(outCxt, packet); switch (ret) { case AVERROR(EAGAIN): LOGW(">>>> avcodec_receive_packet(no input)"); goto end; case AVERROR(EOF): LOGW(">>>> avcodec_receive_packet(reach end)"); goto end; case 0: LOGD(">>>> Writting frame"); ret = av_write_frame(outFCxt, packet); if (ret == 0){ LOGD(">>>>> Write finished"); av_packet_unref(packet); } else { LOGE(">>>>> Error:av_write_frame(%s)", av_err2str(ret)); exit(1); } goto end; default: LOGE(">>>> Error:avcode_receive_packet(%s)", av_err2str(ret)); exit(1); } end: break; } break; default: /** I got a "Generic error in an external library" here **/ LOGE(">>> Error: avcodec_send_frame(%s)", av_err2str(ret)); exit(1); }
}