Newest 'libx264' Questions - Stack Overflow
Les articles publiés sur le site
-
VLC huge buffering times over rtp for local H264 stream
15 mars 2022, par mikeI'm outputting an H264 stream, encoded by my application using ffmpeg. I can display it using
ffplay
, but when trying to view the stream in VLC, I only get the first frame, or it looks like that's the case.The messages output shows that it is "buffering", taking around a minute to get to 100% when the frame updates. When using
ffplay
, the latency is about 50-100ms at worst.I am sending to
rtp://127.0.0.1:6666?pkt_size=1316
with the formatrtp_mpegts
. I am new to this and it's highly likely I haven't set the frame up completely correctly. The process is (minus declarations and error checking)codec_name = "libx264"; codec = avcodec_find_encoder_by_name(codec_name.c_str()); context = avcodec_alloc_context3(codec); pkt = av_packet_alloc(); context->bit_rate = 5 * Mega; context->width = info.DisplayWidth; context->height = info.DisplayHeight; context->time_base = { 1, FPS }; context->framerate = { FPS, 1 }; context->gop_size = 100; context->max_b_frames = 1; context->pix_fmt = AV_PIX_FMT_YUV420P; if (codec->id == AV_CODEC_ID_H264) { check_ret("set option: preset", av_opt_set(context->priv_data, "preset", "fast", 0)); check_ret("set option: tune", av_opt_set(context->priv_data, "tune", "zerolatency", 0)); check_ret("set option: profile", av_opt_set(context->priv_data, "profile", "baseline", 0)); } check_ret("open codec", avcodec_open2(context, codec, NULL)); // setup the stream fmt = (AVOutputFormat*)av_guess_format("rtp_mpegts", NULL, NULL); avformat_alloc_output_context2(&avfctx, fmt, fmt->name, "rtp://127.0.0.1:6666?pkt_size=1316"); avio_open(&avfctx->pb, avfctx->url, AVIO_FLAG_WRITE); AVStream* stream = avformat_new_stream(avfctx, codec); avcodec_parameters_from_context(stream->codecpar, context); stream->time_base.num = 1; stream->time_base.den = FPS; avformat_write_header(avfctx, NULL); // then the encoding (in an output loop)
yuvFrame->pts = i++; // i is incremented every frame avcodec_send_frame(enc_ctx, yuvFrame); while (ret >= 0) { ret = avcodec_receive_packet(enc_ctx, pkt); //ret = av_interleaved_write_frame(avfctx, pkt); was using this, don't seem to need it ret = av_write_frame(avfctx, pkt); av_packet_unref(pkt); } The VLC output looks like this:
main debug: using hw decoder module "d3d11va" avcodec info: Using D3D11VA (NVIDIA GeForce RTX 2080 Super with Max-Q Design, vendor 10de(NVIDIA), device 1e93, revision a1) for hardware decoding qt debug: Logical video size: 1280x720 main debug: resized to 1280x720 main debug: VoutDisplayEvent 'resize' 1280x720 main debug: Received first picture main debug: Buffering 1% main debug: Buffering 2% main debug: Buffering 3% main debug: auto hiding mouse cursor main debug: Buffering 4% main debug: Buffering 5% main debug: Buffering 6% main debug: Buffering 7% main debug: Buffering 8% main debug: Buffering 9% main debug: Buffering 10% main debug: auto hiding mouse cursor main debug: Buffering 11% rtp warning: 1 packet(s) lost rtp warning: 1 packet(s) lost rtp warning: 1 packet(s) lost ts warning: discontinuity received 0x3 instead of 0xd (pid=256) ts warning: discontinuity received 0x5 instead of 0xf (pid=256) ts warning: discontinuity received 0x1 instead of 0xb (pid=256) main debug: Buffering 12% main debug: Buffering 13% main debug: Buffering 14% main debug: Buffering 15% main debug: Buffering 16% main debug: Buffering 17% main debug: Buffering 18% main debug: auto hiding mouse cursor main debug: Buffering 19% main debug: Buffering 20%
-
Access to motion vector's (x, y) coordinate while using libx264 encoder
8 mars 2022, par RocklandI want to know if it is possible to get motion vectors values (x, y) somehwhere in the enconding process while using libx264 encoder.
I have a project where I need to modify motion vectors values during encoding process. What I want to do concretly is for exemple :
motion_x = motion_x + 1
and/ormotion_y = motion_y -1
I want to know if it is possible to get motion vectors values (x, y) somehwhere in the enconding process while using libx264 encoder.
I have a project where I need to modify motion vectors values during encoding process. What I want to do concretly is for exemple :
motion_x = motion_x + 1
and/ormotion_y = motion_y -1
I know that it is possible to do that while using the standards ffmpeg encoders. Precisily in the function
static int encode_picture(MpegEncContext *s, int picture_number)
in the filempegvideo_enc.c
located in the ffmpeg's libavcodec directory, we can get and modify motion vector's values in the structMpegEncContext
(->current_picture.motion_val)
. When I use libx264 encoder, this function is not called so I don't know where and how to do that.Your help will be verry appreciated.
-
FFMPEG : Convert WebM VP8/VP9 multi-resolution video to MP4 (H.264)
28 janvier 2022, par thedeadaliveI have been trying to convert a multi-resolution WebM video ( VP9/VP8/H.264 ) (1280 x 1080 till the half, thereafter 1080 x 1280) to MP4 container with H.264 encoding for video.
When transcoded with FFMPEG is locking into the frame size it's encountering at the start of the video (1280 x 1080 in this case) when transcoded with libvpx (for VP8 and VP9) and libx264 (for H264).
The only instance i could get it right was when the Input WebM was having H.264 video and opus Audio, and ffmpeg was instructed to just copy the video stream and trans-code the Audio to aac only.
Is there way in make ffmpeg support multi-resolution video transcoding?
How to generate a sample video: On a Chrome or Firefox (on a device that supports auto rotation and has different resolution on portrait and landscape) that supports mediaRecorder API goto this link: https://webrtc.github.io/samples/src/content/getusermedia/record/ , start recording a video , while recording the video, change orientation, stop recording and download the video. file)
Discussion Reference: https://groups.google.com/a/webmproject.org/forum/#!topic/webm-discuss/IgumDyMAHY0
-
Getting Error message Unknown encoder 'libx264' , any help appreciated
16 janvier 2022, par Alex.FosterI am trying to compress videos files to a target size within python using ffmpeg-python for an A level project as part of my coursework, I keep getting this error saying it doesn't know the encoder. Not sure what I'm meant to do as this is literally an entirely new space to me. Am I meant to have installed the codec or something, or is there an alternative I can use?
import os, ffmpeg ##import section:this part is where I import all of the modules I will use import tkinter import shutil from tkinter import filedialog import os def fileSelect(): #start of fileSelect function global startingLocation #declares startingLocation as global variable global originalName #declares originalName as global variable global fileType #declares fileType as global variable startingLocation = filedialog.askopenfilename(initialdir="/", title="Select file", #tkinter function that opens file explorer, lets user select file saves the file path as a variable filetypes=(("video files", "*.mp4"),("images", "*.jpg*"))) originalName = os.path.basename(startingLocation) #os function that gets the actaul file name from the path string print (originalName) #print statement to check if originalName has been found fileType = startingLocation.split('.') #splits original name where any full stop in found and saves array as variable fileType = fileType[-1] #changes variable to have the str value of the final item in the array; the file type fileType = '.' + fileType #adds fullstop to the start of the file type so i dont have to repeatedly do it print (fileType) #print statement to check file type is found correctly def outputSelect(): #start of outputSelect function global outputLocation #declares outputLocation as global variable outputLocation = filedialog.askdirectory(initialdir="/", title="Select folder") #tkinter function that opens file explorer, lets the user select of folder as saves the folder path as a variable def fileNewName(): #start of fileNewName function global customName #declares customName as global variable customName = input("Enter the end name of your file") #simple code assigning user input to the custom name vairable customName = customName + fileType #add the fileType onto the end of the custom name def compress(): #start of compress function fileSelect() #calls the fileSelect function outputSelect() #calls the outputSelect function fileNewName() global src global dst #calls the fileNewName function src = startingLocation #assigns startingLocation str as src, so the shutil module is able to use it in a cleaner way dst = outputLocation #assigns outputLocation dst as src, so the shutil module is able to use it in a cleaner way shutil.copy(src, dst) #shutil command that copies the file from src to dst src = outputLocation + '/' + originalName #reassigns src as the location of the file copy dst = outputLocation + '/' + customName #reassigns dst as the location of the file copy but with a new name shutil.move(src,dst) def compress_video(video_full_path, output_file_name, target_size): # Reference: https://en.wikipedia.org/wiki/Bit_rate#Encoding_bit_rate min_audio_bitrate = 32000 max_audio_bitrate = 256000 probe = ffmpeg.probe(video_full_path) # Video duration, in s. duration = float(probe['format']['duration']) # Audio bitrate, in bps. audio_bitrate = float(next((s for s in probe['streams'] if s['codec_type'] == 'audio'), None)['bit_rate']) # Target total bitrate, in bps. target_total_bitrate = (target_size * 1024 * 8) / (1.073741824 * duration) # Target audio bitrate, in bps if 10 * audio_bitrate > target_total_bitrate: audio_bitrate = target_total_bitrate / 10 if audio_bitrate < min_audio_bitrate < target_total_bitrate: audio_bitrate = min_audio_bitrate elif audio_bitrate > max_audio_bitrate: audio_bitrate = max_audio_bitrate # Target video bitrate, in bps. video_bitrate = target_total_bitrate - audio_bitrate i = ffmpeg.input(video_full_path) ffmpeg.output(i, os.devnull, **{'c:v': 'libx264', 'b:v': video_bitrate, 'pass': 1, 'f': 'mp4'} ).overwrite_output().run() ffmpeg.output(i, output_file_name, **{'c:v': 'libx264', 'b:v': video_bitrate, 'pass': 2, 'c:a': 'aac', 'b:a': audio_bitrate} ).overwrite_output().run() compress() compress_video(dst, outputLocation, 3 * 1000)
-
How to resolve "ERROR : libx264 not found" ?
13 janvier 2022, par davidvargheseI needed to install ffmpeg with libx264 support for enabling H.264 encoding . I installed libx264 successfully using the below script with toolchains available in android-ndk-r9d .
#!/bin/bash NDK=~/android-ndk-r9d SYSROOT=$NDK/platforms/android-8/arch-arm/ TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64 function build_one { ./configure \ --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \ --sysroot="$SYSROOT" \ --host=arm-linux \ --enable-pic \ --enable-shared \ --disable-cli make clean make make install } build_one
Now I wanted to build ffmpeg with libx264 support . I used the below script with --enable-libx264 , --enable-nonfree , --enable-gpl options as in the below script .
#!/bin/bash NDK=~/android-ndk-r9d SYSROOT=$NDK/platforms/android-8/arch-arm/ TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64 function build_one { ./configure \ --prefix=$PREFIX \ --enable-shared \ --enable-nonfree \ --enable-gpl \ --enable-libx264 \ --disable-doc \ --disable-ffmpeg \ --disable-ffplay \ --disable-ffprobe \ --disable-ffserver \ --disable-avdevice \ --disable-doc \ --disable-symver \ --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \ --target-os=linux \ --arch=arm \ --enable-cross-compile \ --sysroot=$SYSROOT \ --extra-cflags="-Os -fpic $ADDI_CFLAGS" \ --extra-ldflags="$ADDI_LDFLAGS" \ $ADDITIONAL_CONFIGURE_FLAG make clean make make install } CPU=arm PREFIX=$(pwd)/android/$CPU ADDI_CFLAGS="-marm" build_one
But when I run the script I'm getting error "ERROR: libx264 not found" .
I suppose ffmpeg is not able to figure out the installed location of libx264 . After libx264 installation I have libx264.so file in /usr/local/lib executable at /usr/local/bin and header files at /usr/local/include directories .
What all changes do I need to make to the ffmpeg build script in-order to make it detect libx264?
Note : I am using Ubuntu 12.04(64 bit) for cross compiling .