Hi All,
I encode frame into h264 file with pipeline like that:
appsrc name=appsrc ! video/x-raw,format=YUY2,width=1920,height=1080,framerate=30/1 ! nvvideoconvert ! video/x-raw(memory:NVMM), format=NV12, width=1920, height=1080,framerate=30/1 ! nvv4l2h264enc control-rate=constant_bitrate bitrate=240000000 ! video/x-h264, stream-format=(string)byte-stream ! filesink location=./camera_dev_0_2021_8_19_15_51_31.h264
But this h264 file's framerate is bigger than 30.How can i fix this problem?
I had tried the pipeline like that:
appsrc name=appsrc ! video/x-raw,format=YUY2,width=1920,height=1080,framerate=30/1 ! nvvideoconvert ! video/x-raw(memory:NVMM), format=NV12, width=1920, height=1080,framerate=30/1 ! nvv4l2h264enc control-rate=constant_bitrate bitrate=240000000 ! video/x-h264, stream-format=(string)byte-stream,framerate=30/1 ! h264parse ! mp4mux ! filesink location=./camera_dev_0_2021_8_19_15_51_31.h264
When the second frame data buffer push into appsrc,it had not not return.
status = gst_app_src_push_buffer(GST_APP_SRC(source_), buffer);
Thanks.
Hi,
Probably you don’t assign pts correctly. Please refer to this sample:
What is maximum video encoding resolution in pixels? - #11 by DaneLLL
We have deprecated omx plugins. Please use nvv4l2h264enc instead of omxh264enc.
Hi,
this is my writeframe function.
bool GStreamerRecoder::WriteFrame(const unsigned char *image_buffer,
const size_t &image_buffer_size,
const uint64_t ×tamp_ns) {
if (nullptr == image_buffer) {
std::cerr << "Nullptr!\n";
return false;
}
GstClockTime duration, timestamp;
GstFlowReturn status;
duration = static_cast<GstClockTime>((1.0 / fps_) * GST_SECOND);
timestamp = num_frames_ * duration;
GstBuffer *buffer =
gst_buffer_new_allocate(nullptr, image_buffer_size, nullptr);
GstMapInfo info;
gst_buffer_map(buffer, &info, (GstMapFlags)GST_MAP_READ);
memcpy(info.data, (guint8 *)image_buffer, image_buffer_size);
gst_buffer_unmap(buffer, &info);
GST_BUFFER_DURATION(buffer) = duration;
GST_BUFFER_PTS(buffer) = timestamp;
GST_BUFFER_DTS(buffer) = timestamp;
// set the current number in the frame
GST_BUFFER_OFFSET(buffer) = num_frames_;
status = gst_app_src_push_buffer(GST_APP_SRC(source_), buffer);
if (status != GST_FLOW_OK) {
std::cerr << "Error pushing buffer to GStreamer pipeline!\n";
gst_safe_release(&buffer);
return false;
}
uint64_t cur_timestamp_ns =
(timestamp_ns > 0) ? timestamp_ns : GetSysTimestamp_ns();
fprintf(timestamp_writer_, "%lu, %lu\n", num_frames_, cur_timestamp_ns);
num_frames_++;
return true;
}
And I had used nvv4l2h264enc
Hi,
For using qtmux or mp4mux, you would need to send end-of-stream signal in termination. Please check if you have this. Or may try matroskamux.
Since encoder does not touch/modify timestamps, it is very likely the timestamps are not set correctly.
1 Like
I have solved the problem based on your reply.Thank u.