I am using the following ffmpeg command to trim and select certain portions of the video.
ffmpeg -v verbose -i test.mp4 -filter_complex
"[0:v]trim=start=5:end=40,setpts=PTS-STARTPTS[v_trimmed];
[v_trimmed]select='between(t,10,20)',setpts=N/FRAME_RATE/TB[v];
[0:a]atrim=start=5:end=40,asetpts=PTS-STARTPTS[a_trimmed];
[a_trimmed]aselect='between(t,10,20)',asetpts=N/SR/TB[a]"
-map "[v]" -map "[a]" -y -r 30 output_video.mp4
The above command errors out with the following trace
[h264 @ 0x12570a0e0] Reinit context to 1280x720, pix_fmt: yuv420p
[graph 0 input from stream 0:0 @ 0x600001ff8000] w:1280 h:720 pixfmt:yuv420p tb:1/30000 fr:30000/1001 sar:1/1 csp:bt709 range:tv
[graph_0_in_0:1 @ 0x600001ff80b0] tb:1/44100 samplefmt:fltp samplerate:44100 chlayout:stereo
[Parsed_trim_0 @ 0x600001ffc420] TB:0.000033 FRAME_RATE:29.970030 SAMPLE_RATE:nan
[Parsed_select_2 @ 0x600001ffc580] TB:0.000033 FRAME_RATE:nan SAMPLE_RATE:nan
[Parsed_atrim_4 @ 0x600001ffc630] TB:0.000023 FRAME_RATE:nan SAMPLE_RATE:44100.000000
[Parsed_aselect_6 @ 0x600001ffc790] TB:0.000023 FRAME_RATE:nan SAMPLE_RATE:44100.000000
[graph 0 input from stream 0:0 @ 0x600001ff8000] video frame properties congruent with link at pts_time: 0
[vost#0:0/libx264 @ 0x125707800] *** dropping frame 0 at ts -9223372036854775808
Last message repeated 298 times
[fc#0 @ 0x600001ae81b0] Input 1 no longer accepts new data
[aist#0:1/aac @ 0x1257100b0] [dec:aac @ 0x12570ea40] Decoder returned EOF, finishing
[aist#0:1/aac @ 0x1257100b0] [dec:aac @ 0x12570ea40] Terminating thread with return code 0 (success)
[aist#0:1/aac @ 0x1257100b0] All consumers of this stream are done
[fc#0 @ 0x600001ae81b0] Filtergraph returned EOF, finishing
[fc#0 @ 0x600001ae81b0] All consumers returned EOF
[vost#0:0/libx264 @ 0x125707800] *** dropping frame 0 at ts -9223372036854775808
[vost#0:0/libx264 @ 0x125707800] Encoder thread received EOF
[vost#0:0/libx264 @ 0x125707800] Could not open encoder before EOF
[vost#0:0/libx264 @ 0x125707800] Task finished with error code: -22 (Invalid argument)
[vost#0:0/libx264 @ 0x125707800] Terminating thread with return code -22 (Invalid argument)
[aost#0:1/aac @ 0x1257084b0] Encoder thread received EOF
[fc#0 @ 0x600001ae81b0] Terminating thread with return code 0 (success)
[vist#0:0/h264 @ 0x12570ecf0] [dec:h264 @ 0x1257094e0] Decoder returned EOF, finishing
[vist#0:0/h264 @ 0x12570ecf0] [dec:h264 @ 0x1257094e0] Terminating thread with return code 0 (success)
[vist#0:0/h264 @ 0x12570ecf0] All consumers of this stream are done
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x6000014ec100] All consumers are done
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x6000014ec100] Terminating thread with return code 0 (success)
[aost#0:1/aac @ 0x1257084b0] Terminating thread with return code 0 (success)
[out#0/mp4 @ 0x600001de8000] Nothing was written into output file, because at least one of its streams received no packets.
frame= 0 fps=0.0 q=0.0 Lsize= 0KiB time=N/A bitrate=N/A dup=0 drop=301 speed=N/A
[aac @ 0x1257087b0] Qavg: 645.507
[AVIOContext @ 0x125708d60] Statistics: 0 bytes written, 0 seeks, 0 writeouts
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x6000014ec100] Input file #0 (test.mp4):
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x6000014ec100] Input stream #0:0 (video): 1219 packets read (1479521 bytes); 1201 frames decoded; 0 decode errors;
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x6000014ec100] Input stream #0:1 (audio): 1741 packets read (646974 bytes); 1732 frames decoded; 0 decode errors (1773568 samples);
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x6000014ec100] Total: 2960 packets (2126495 bytes) demuxed
[AVIOContext @ 0x125705640] Statistics: 2699615 bytes read, 0 seeks
Conversion failed!
If I remove the setpts step after the trim, the above command will work as expected. What is the problem with using trim and setpts, and then, passing the output to the select filter?
Note: Using trim is important as per my current flow.
New contributor
lakhan dhingra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.