Newest 'libx264' Questions - Stack Overflow
Les articles publiés sur le site
-
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 .
-
How to get FFMPEG to encode H264 using libx264 ?
12 décembre 2021, par Basit AnwerFFMPEG encode example fails to create a H264 video. MPEG1 works fine though.
Pasting the code here as well
* @file * video encoding with libavcodec API example * * @example encode_video.c */ #include #include #include #include
avcodec.h> #include opt.h> #include imgutils.h> static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt, FILE *outfile) { int ret; /* send the frame to the encoder */ if (frame) printf("Send frame %3"PRId64"\n", frame->pts); ret = avcodec_send_frame(enc_ctx, frame); if (ret < 0) { fprintf(stderr, "Error sending a frame for encoding\n"); exit(1); } while (ret >= 0) { ret = avcodec_receive_packet(enc_ctx, pkt); if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) return; else if (ret < 0) { fprintf(stderr, "Error during encoding\n"); exit(1); } printf("Write packet %3"PRId64" (size=%5d)\n", pkt->pts, pkt->size); fwrite(pkt->data, 1, pkt->size, outfile); av_packet_unref(pkt); } } int main(int argc, char **argv) { const char *filename, *codec_name; const AVCodec *codec; AVCodecContext *c= NULL; int i, ret, x, y; FILE *f; AVFrame *frame; AVPacket *pkt; uint8_t endcode[] = { 0, 0, 1, 0xb7 }; if (argc <= 2) { fprintf(stderr, "Usage: %s The code fails at encode call and every
avcodec_receive_packet
call returnsAVERROR(EAGAIN)
What am i missing here?