how to save h264 stream into .264 file - ffmpeg

I'm using nginx-rtmp-module build hls server, when I play it on safari, it does not shows image,then i use this command ffmpeg -i rtmp://192.168.4.213/hls/testH264 -c copy -map 0 -f segment -segment_list playlist.m3u8 -segment_time 5 output%03d.ts, it shows missing picture in access unit with size 28184,so i think maybe the raw h264 stream has some problem,then i directly save the h264 stream into .264 file,but when i play the .264 file with vlc,the screen is fuzzy,help

should use binary type to save file

Related

Ffmpeg -c copy not carrying over audio track from mkv to hls stream

I am using ffmpeg to create an hls stream. The source is an mkv with multiple audio tracks. I have tried using -map to specify the audio stream as well. I also found that when I point ffmpeg to any other audio stream in the file it works. It's just the first audio stream that does not. At one point I replaced -c copy with -acodec aac -ac 6 on the first stream and I got sound which is great but I am only looking to copy the stream and not re-encode it. The next thing I tried was using other mkv videos I have. All are reflecting the same issue. The mkv's by itself play both audio and video fine in VLC. When playing the output.m3u8 in VLC the option to choose different audio tracks is greyed out. Here is the command I'm using:
ffmpeg -i "./video.mkv" -ss 00:00:00 -t 00:00:30 -c copy -f hls "output.m3u8"
I want the audio of my hls stream to reflect that of the mkv source:
Although what I get returned from the command above gives me no sound and shows me this in mediaInfo:
I've aslo noticed that hls does not support pcm. Is it possible dash could work with this stream because it is pcm?
HLS segments can be either MPEG-TS or fragmented MP4. Neither officially support PCM audio, so you'll have to convert it.
DASH uses fragmented MP4 as segment format.

How to optimize file size of recorded camera stream?

I am recording stream from camera using different approaches. I tried to record camera stream using ffmpeg. I looked at this question: https://stackoverflow.com/a/26464175/5128696 and used the following command:
ffmpeg -i http://user:password#192.168.0.101/video.cgi?resolution=vga -c copy -map 0 -f segment -segment_time 300 -segment_format mp4 "outfile%03d.mp4"
It worked, but file size peaked at 45Mb for 2 minutes video.
Then I used VLC to record stream. Result file for fragment of same length was about 2Mb
How do I optimize the recorded file size? My camera gives 640x480 video stream without audio, and 45Mb is too much.
-c copy enables stream copy mode. Remove this option to re-encode:
ffmpeg -i http://user:password#192.168.0.101/video.cgi?resolution=vga -map 0 -f segment -segment_time 300 "outfile%03d.mp4"
This will use the default settings for the encoder named libx264. See FFmpeg Wiki: H.264 for more options.

why am i getting this error using ffmpeg while decoding m3u8?

I'm trying to decode a .m3u8 to mp4 using ffmpeg, but keep getting this error message:
Error applying bitstream filters to an output packet for stream #0:0
https://....../audio.m3u8: Invalid data found when processing input.
This is the command I'm using:
ffmpeg -y -f hls -i https://www.video-cdn.com/video/encrypt/7b35e1550e7dac1fa9d6f34eb0b55148/R915dD-90d3ac3f-48d9-4da1-84d4-d354a7ed03de/90d3ac3f-48d9-4da1-84d4-d354a7ed03de/audio.m3u8 -bsf:v h264_mp4toannexb,dump_extra -bsf:a aac_adtstoasc -map 0 -c copy -flags +global_header -max_interleave_delta 0 -f mp4 test.mp4
cmdExample
Any ideas?
The HLS stream is encrypted. You can see this because of the following line in the m3u8 playlist file:
#EXT-X-KEY:METHOD=AES-128,URI="blob:https://www.video-cdn.com/90d3ac3f-48d9-4da1-84d4-d354a7ed03de",IV=0xa2dccda29716795b6a22bec559144723
Since the URI is with the Blob-Prefix, FFmpeg can not decrypt the stream, because this blob is only valid where you have received this URL (e.g. your browser).
To solve this, you need to manually download the m3u8 playlist file to your local drive, download also the AES-128 key manually, modify the playlist and pass this into FFmpeg. You can find a short tutorial here.

Create mp4 file from raw h264 using a pipe instead of files

I have a raw h264 file that I can display with VLC, on a mac:
open -a VLC file.h264
I can convert this to mp4 with the command line
ffmpeg -f h264 -i file.h264 -c:v copy file.mp4
But what I really want to do is something like:
cat file.h264 | ffmpeg > file.mp4
Reason being that the input is coming over a socket and I want to convert it and send it to a video tag in an html file on the fly.
An alternative solution would be a way to display the raw h264 in a web page without converting it to mp4 first.
The input is coming in frame by frame, the first four bytes are 0,0,0,1. My understanding is that this h264 Annex B format.
I know nothing about video formats, I would grateful to be pointed in a direction to look.
Should I look into writing code using libavcodec like this quuesion or is there an off-the-shelf solution?
H.264 muxed to MP4 using libavformat not playing back
Thanks!
The command line below will create a fragmented MP4 (Windows cmd)
type test.h264 | ffmpeg -i - -vcodec copy -f mp4 -movflags frag_keyframe+empty_moov pipe:1 > test_frag.mp4
You should be able to find lot's of JavaScript code to play fragmented MP4s.
For example: https://github.com/chriswiggins/videojs-fmp4

Invalid key_frame(I) and P- frame sequence in h264 Binary stream

I am getting video from USB webcam and encoding into h.264 raw stream as follows...
ffmpeg.exe -f dshow -rtbufsize 200M -i video="Logitech HD Webcam C270" -vcodec libx264 -preset ultrafast -tune zerolatency -g 30 -s 480x640 -buf
size:v 50M output.h264
I am expecting 1-Key frame and 29-P Frame(with SPS/PPS) in output.h264 stream.But I am not getting the expected result.However video is playing fine.
I tried to get Metadata of same file using ffprob ..
ffprobe -show_frames videofilename.h264 > outputlogfile.txt
Here I can see proper sequence 1-Key frame and 29-P frames.But if we open h264 file in binary reader(I am using HDX) I can see Key/P frames not in proper sequence.
You can download h264 sample and ffprob logs from below links.
https://www.dropbox.com/s/3ghpkqdc36wdgxr/TimerSample.h264?dl=0
https://www.dropbox.com/s/gdn64004o0udrfk/TimerSample.txt?dl=0
You can find binary sequence of same file from here (filtered by start code)
Please let me know whether i am missing some filter. Thank you.
The highlighted elements in the screenshot show that the bitstream begins with a SPS unit, then a PPS unit, then a SEI unit, followed by slices of an IDR picture, then non-reference picture slices. This is all normal and expected.
Use
ffmpeg -i videofilename.h264 -c copy -bsf:v trace_headers -f null -
to see a text dump of the parsing of the bitstream.

Resources